2024-04-10 Fred Gleason <fredg@paravelsystems.com>

* Stubbed out a 'pypad_sftpfilewrite.py'. PyPAD script.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2024-04-10 17:12:21 -04:00
parent d8096ee2db
commit b09ec69103
5 changed files with 184 additions and 2 deletions

View File

@@ -24702,3 +24702,5 @@
2024-04-06 Fred Gleason <fredg@paravelsystems.com>
* Incremented the package version to 4.2.0
* Incremented the Python API version to 4.2.0.
2024-04-10 Fred Gleason <fredg@paravelsystems.com>
* Stubbed out a 'pypad_sftpfilewrite.py'. PyPAD script.

View File

@@ -275,7 +275,7 @@ DISTRO-SPECIFIC NOTES
---------------------
1) RedHat Enterprise Linux 7
Required build packages: git gcc-c++ automake autoconf libtool qt5-qtbase-devel qt5-qtbase-mysql qt5-linguist qt5-qtwebkit-devel libcurl-devel cdparanoia-devel hpklinux-devel alsa-lib-devel jack-audio-connection-kit-devel libsamplerate-devel libsndfile-devel id3lib-devel libvorbis-devel flac-devel pam-devel soundtouch-devel twolame-devel libmad-devel lame-devel rpm-build createrepo fop docbook5-style-xsl libxslt kernel-devel rpm-sign man-pages openssl-devel taglib-devel libmusicbrainz5-devel libdiscid-devel libcoverart libcoverart-devel ImageMagick-c++-devel
Required build packages: git gcc-c++ automake autoconf libtool qt5-qtbase-devel qt5-qtbase-mysql qt5-linguist qt5-qtwebkit-devel libcurl-devel cdparanoia-devel hpklinux-devel alsa-lib-devel jack-audio-connection-kit-devel libsamplerate-devel libsndfile-devel id3lib-devel libvorbis-devel flac-devel pam-devel soundtouch-devel twolame-devel libmad-devel lame-devel rpm-build createrepo fop docbook5-style-xsl libxslt kernel-devel rpm-sign man-pages openssl-devel taglib-devel libmusicbrainz5-devel libdiscid-devel libcoverart libcoverart-devel ImageMagick-c++-devel python36-paramiko
Configure script invocation: ./configure --prefix=/usr --libdir=/usr/lib64 --libexecdir=/var/www/rd-bin --sysconfdir=/etc/httpd/conf.d

View File

@@ -2,7 +2,7 @@
##
## Makefile.am for Rivendell pypad/examples
##
## (C) Copyright 2018-2023 Fred Gleason <fredg@paravelsystems.com>
## (C) Copyright 2018-2024 Fred Gleason <fredg@paravelsystems.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as
@@ -42,6 +42,8 @@ install-exec-am:
cp pypad_nautel.exemplar $(DESTDIR)/usr/lib/rivendell/pypad/pypad_nautel.exemplar
../../../helpers/install_python.sh pypad_serial.py $(DESTDIR)/usr/lib/rivendell/pypad/pypad_serial.py
cp pypad_serial.exemplar $(DESTDIR)/usr/lib/rivendell/pypad/pypad_serial.exemplar
../../../helpers/install_python.sh pypad_sftpwrite.py $(DESTDIR)/usr/lib/rivendell/pypad/pypad_sftpwrite.py
cp pypad_sftpwrite.exemplar $(DESTDIR)/usr/lib/rivendell/pypad/pypad_sftpwrite.exemplar
../../../helpers/install_python.sh pypad_shoutcast1.py $(DESTDIR)/usr/lib/rivendell/pypad/pypad_shoutcast1.py
cp pypad_shoutcast1.exemplar $(DESTDIR)/usr/lib/rivendell/pypad/pypad_shoutcast1.exemplar
../../../helpers/install_python.sh pypad_spinitron.py $(DESTDIR)/usr/lib/rivendell/pypad/pypad_spinitron.py
@@ -84,6 +86,8 @@ uninstall-local:
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_nautel.py
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_serial.exemplar
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_serial.py
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_sftpwrite.exemplar
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_sftpwrite.py
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_shoutcast1.exemplar
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_shoutcast1.py
rm -f $(DESTDIR)/usr/lib/rivendell/pypad/pypad_spinitron.exemplar
@@ -125,6 +129,8 @@ EXTRA_DIST = pypad_ando.exemplar\
pypad_nautel.py\
pypad_serial.exemplar\
pypad_serial.py\
pypad_sftpwrite.exemplar\
pypad_sftpwrite.py\
pypad_shoutcast1.exemplar\
pypad_shoutcast1.py\
pypad_spinitron.exemplar\

View File

@@ -0,0 +1,97 @@
; This is the configuration for the 'pypad_sftpwrite' script for
; Rivendell, which can be used to a remote system via the SFTP protocol
; using Now & Next data.
; Section Header
;
; One section per file to be written should be configured, starting with
; 'Url1' and working up consecutively
[Url1]
; Url
;
; The URL to which to send the file, which may contain filepath
; wildcards as defined in Appendix C of the Rivendell Operations and
; Administration Guide.
;
Url=sftp://server.example.com/myfile.txt
; Username
;
; The username to be used when authenticating to the remote server.
;
Username=someuser
; Password
;
; The password to be used when authenticating to the remote server.
Password=hackme
; Format String. The string to be sent each time RDAirPlay changes
; play state, including any wildcards as placeholders for metadata values.
;
; The list of available wildcards can be found in the 'Metadata Wildcards'
; appendix of the Rivendell Operations Guide.
;
FormatString=NOW: %d(ddd MMM d hh:mm:ss yyyy): %t - %a\nNEXT: %D(ddd MMM d hh:mm:ss yyyy): %T - %A\n
; Encoding. Defines the set of escapes to be applied to the PAD fields.
; The following options are available:
;
; 0 - Perform no character escaping.
; 1 - "XML" escaping: Escape reserved characters as per XML-v1.0
; 2 - "URL" escaping: Escape reserved characters as per RFC 2396 Section 2.4
; 3 - "JSON" escaping: Escape reserved characters as per ECMA-404
Encoding=0
; Log Selection
;
; Set the status for each log to 'Yes', 'No' or 'Onair' to indicate whether
; state changes on that log should be output. If set to 'Onair', then
; output will be generated only if RDAirPlays OnAir flag is active.
MasterLog=Yes
Aux1Log=Yes
Aux2Log=Yes
VLog101=No
VLog102=No
VLog103=No
VLog104=No
VLog105=No
VLog106=No
VLog107=No
VLog108=No
VLog109=No
VLog110=No
VLog111=No
VLog112=No
VLog113=No
VLog114=No
VLog115=No
VLog116=No
VLog117=No
VLog118=No
VLog119=No
VLog120=No
[NowGroups]
; Group Selection
;
; Filter updates according to the Group membership of the 'now' playing
; event. If no groups are listed here and in the [NextGroups] section,
; then ALL updates will be forwarded
; without regard to Group.
; Group1=MUSIC
; Group2=LEGAL
; [...] ; Additional groups can be added...
[NextGroups]
; Group Selection
;
; Filter updates according to the Group membership of the 'next' playing
; event. If no groups are listed here, If no groups are listed here and in
; the [NowGroups] section,then ALL updates will be forwarded
; without regard to Group.
; Group1=MUSIC
; Group2=LEGAL
; [...] ; Additional groups can be added...

View File

@@ -0,0 +1,77 @@
#!%PYTHON_BANGPATH%
# pypad_sftpwrite.py
#
# Write PAD updates to arbitrary URLs
#
# (C) Copyright 2018-2022 Fred Gleason <fredg@paravelsystems.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import sys
import syslog
import configparser
import paramiko
import socket
import urllib
try:
from rivendellaudio import pypad
except ModuleNotFoundError:
import pypad # Rivendell v3.x style
from io import BytesIO
def eprint(*args,**kwargs):
print(*args,file=sys.stderr,**kwargs)
def ProcessPad(update):
n=1
section='Url'+str(n)
while(update.config().has_section(section)):
if update.shouldBeProcessed(section):
fmtstr=update.config().get(section,'FormatString')
url=urllib.parse.urlparse(update.resolveFilepath(update.config().get(section,'Url'),update.dateTime()))
username=update.config().get(section,'Username')
password=update.config().get(section,'Password')
ssh=paramiko.SSHClient()
#ssh.load_host_keys('/usr/lib/rivendell/ssh/known_hosts')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(url.netloc,username=username,password=password)
sftp=ssh.open_sftp()
path=url.path
if path[0]=='/': # Single leading '/' means relative path
path=path[1::]
fh=sftp.file(filename=path,mode='w')
fh.write(update.resolvePadFields(fmtstr,int(update.config().get(section,'Encoding'))).encode('utf-8'))
fh.close()
sftp.close()
except paramiko.ssh_exception.NoValidConnectionsError as errors:
update.syslog(syslog.LOG_WARNING,'connection failed: '+str(errors))
n=n+1
section='Url'+str(n)
#
# 'Main' function
#
rcvr=pypad.Receiver()
try:
paramiko.util.log_to_file('/home/fredg/temp/paramiko.txt')
rcvr.setConfigFile(sys.argv[3])
except IndexError:
eprint('pypad_sftpwrite.py: USAGE: cmd <hostname> <port> <config>')
sys.exit(1)
rcvr.setPadCallback(ProcessPad)
rcvr.start(sys.argv[1],int(sys.argv[2]))