mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-14 14:41:13 +02:00
2019-06-24 Fred Gleason <fredg@paravelsystems.com>
* Added a 'pypad.rivendellConfig()' method. * Added a 'pypad.syslog()' method.
This commit is contained in:
@@ -30,20 +30,6 @@ import syslog
|
||||
import pypad
|
||||
import configparser
|
||||
|
||||
def eprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stderr,end='')
|
||||
print(*args,file=sys.stderr)
|
||||
syslog.syslog(syslog.LOG_ERR,*args)
|
||||
|
||||
def iprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stdout,end='')
|
||||
print(*args,file=sys.stdout)
|
||||
syslog.syslog(syslog.LOG_INFO,*args)
|
||||
|
||||
def isTrue(string):
|
||||
l=['Yes','On','True','1']
|
||||
return string.lower() in map(str.lower,l)
|
||||
|
||||
def ProcessPad(update):
|
||||
if update.hasPadType(pypad.TYPE_NOW):
|
||||
n=1
|
||||
@@ -54,17 +40,17 @@ def ProcessPad(update):
|
||||
values['mount']=update.config().get(section,'Mountpoint')
|
||||
values['song']=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_NONE)
|
||||
values['mode']='updinfo'
|
||||
iprint('Updating '+update.config().get(section,'Hostname')+': song='+values['song'])
|
||||
update.syslog(syslog.LOG_INFO,'Updating '+update.config().get(section,'Hostname')+': song='+values['song'])
|
||||
url="http://%s:%s/admin/metadata" % (update.config().get(section,'Hostname'),update.config().get(section,'Tcpport'))
|
||||
try:
|
||||
response=requests.get(url,auth=HTTPBasicAuth(update.config().get(section,'Username'),update.config().get(section,'Password')),params=values)
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.RequestException as e:
|
||||
eprint(str(e))
|
||||
update.syslog(syslog.LOG_WARNING,str(e))
|
||||
n=n+1
|
||||
except configparser.NoSectionError:
|
||||
if(n==1):
|
||||
eprint('No icecast config found')
|
||||
update.syslog(syslog.LOG_WARNING,'No icecast config found')
|
||||
return
|
||||
|
||||
#
|
||||
@@ -87,6 +73,4 @@ except IndexError:
|
||||
eprint('pypad_icecast2: USAGE: cmd <hostname> <port> <config>')
|
||||
sys.exit(1)
|
||||
rcvr.setPadCallback(ProcessPad)
|
||||
iprint('Started')
|
||||
rcvr.start(sys.argv[1],int(sys.argv[2]))
|
||||
iprint('Stopped')
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# Write PAD updates to Live365 stations
|
||||
#
|
||||
# (C) Copyright 2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
# (C) Copyright 2018-2019 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
|
||||
@@ -52,9 +52,9 @@ def ProcessPad(update):
|
||||
curl.perform()
|
||||
code=curl.getinfo(pycurl.RESPONSE_CODE)
|
||||
if (code<200) or (code>=300):
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] returned response code '+str(code))
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] returned response code '+str(code))
|
||||
except pycurl.error:
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
curl.close()
|
||||
n=n+1
|
||||
|
||||
|
@@ -59,9 +59,9 @@ def ProcessPad(update):
|
||||
curl.perform()
|
||||
code=curl.getinfo(pycurl.RESPONSE_CODE)
|
||||
if (code<200) or (code>=300):
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] returned response code '+str(code))
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] returned response code '+str(code))
|
||||
except pycurl.error:
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
curl.close()
|
||||
n=n+1
|
||||
|
||||
|
@@ -104,9 +104,9 @@ def ProcessPad(update):
|
||||
curl.perform()
|
||||
code=curl.getinfo(pycurl.RESPONSE_CODE)
|
||||
if (code<200) or (code>=300):
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] returned response code '+str(code))
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] returned response code '+str(code))
|
||||
except pycurl.error:
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
curl.close()
|
||||
n=n+1
|
||||
|
||||
|
@@ -29,20 +29,6 @@ import syslog
|
||||
import pypad
|
||||
import configparser
|
||||
|
||||
def eprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stderr,end='')
|
||||
print(*args,file=sys.stderr)
|
||||
syslog.syslog(syslog.LOG_ERR,*args)
|
||||
|
||||
def iprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stdout,end='')
|
||||
print(*args,file=sys.stdout)
|
||||
syslog.syslog(syslog.LOG_INFO,*args)
|
||||
|
||||
def isTrue(string):
|
||||
l=['Yes','On','True','1']
|
||||
return string.lower() in map(str.lower,l)
|
||||
|
||||
def ProcessPad(update):
|
||||
if update.hasPadType(pypad.TYPE_NOW):
|
||||
n=1
|
||||
@@ -56,21 +42,21 @@ def ProcessPad(update):
|
||||
values['title']=update.resolvePadFields(update.config().get(section,'TitleString'),pypad.ESCAPE_NONE)
|
||||
values['artist']=update.resolvePadFields(update.config().get(section,'ArtistString'),pypad.ESCAPE_NONE)
|
||||
values['album']=update.resolvePadFields(update.config().get(section,'AlbumString'),pypad.ESCAPE_NONE)
|
||||
iprint('Updating TuneIn: artist='+values['artist']+' title='+values['title']+' album='+values['album'])
|
||||
update.syslog(syslog.LOG_INFO,'Updating TuneIn: artist='+values['artist']+' title='+values['title']+' album='+values['album'])
|
||||
try:
|
||||
response=requests.get('http://air.radiotime.com/Playing.ashx',params=values)
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.RequestException as e:
|
||||
eprint(str(e))
|
||||
update.syslog(syslog.LOG_WARNING,str(e))
|
||||
else:
|
||||
xml=ET.fromstring(response.text)
|
||||
status=xml.find('./head/status')
|
||||
if(status.text!='200'):
|
||||
eprint('Update Failed: '+xml.find('./head/fault').text)
|
||||
update.syslog(syslog.LOG_WARNING,'Update Failed: '+xml.find('./head/fault').text)
|
||||
n=n+1
|
||||
except configparser.NoSectionError:
|
||||
if(n==1):
|
||||
eprint('No station config found')
|
||||
update.syslog(syslog.LOG_WARNING,'No station config found')
|
||||
return
|
||||
|
||||
#
|
||||
@@ -93,6 +79,4 @@ except IndexError:
|
||||
eprint('pypad_tunein.py: USAGE: cmd <hostname> <port> <config>')
|
||||
sys.exit(1)
|
||||
rcvr.setPadCallback(ProcessPad)
|
||||
iprint('Started')
|
||||
rcvr.start(sys.argv[1],int(sys.argv[2]))
|
||||
iprint('Stopped')
|
||||
|
@@ -47,7 +47,7 @@ def ProcessPad(update):
|
||||
try:
|
||||
curl.perform()
|
||||
except pycurl.error:
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
curl.close()
|
||||
n=n+1
|
||||
|
||||
|
@@ -47,7 +47,7 @@ def ProcessPad(update):
|
||||
try:
|
||||
curl.perform()
|
||||
except pycurl.error:
|
||||
syslog.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
update.syslog(syslog.LOG_WARNING,'['+section+'] failed: '+curl.errstr())
|
||||
curl.close()
|
||||
n=n+1
|
||||
|
||||
|
@@ -30,21 +30,9 @@ import xml.etree.ElementTree as ET
|
||||
import time
|
||||
import pypad
|
||||
|
||||
|
||||
def eprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stderr,end='')
|
||||
print(*args,file=sys.stderr)
|
||||
syslog.syslog(syslog.LOG_ERR,*args)
|
||||
|
||||
def iprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stdout,end='')
|
||||
print(*args,file=sys.stdout)
|
||||
syslog.syslog(syslog.LOG_INFO,*args)
|
||||
|
||||
def dprint(*args,**kwargs):
|
||||
print(pypad_name+': ',file=sys.stdout,end='')
|
||||
print(*args,file=sys.stdout)
|
||||
syslog.syslog(syslog.LOG_DEBUG,*args)
|
||||
|
||||
def XcmdResponse():
|
||||
resp_code={b'+':'Command processed successfully',b'!':'Unknown command',b'-':'Invalid argument',b'/':'Command processed partially'}
|
||||
@@ -157,24 +145,24 @@ def ProcessPad(update):
|
||||
send_sock.settimeout(5)
|
||||
|
||||
encoder=(update.config().get(section,'IpAddress'),int(update.config().get(section,'TcpPort')))
|
||||
iprint('Connecting to {}:{}'.format(*encoder))
|
||||
iprint(xcmd.decode('utf-8'))
|
||||
update.syslog(syslog.LOG_INFO,'Connecting to {}:{}'.format(*encoder))
|
||||
update.syslog(syslog.LOG_INFO,xcmd.decode('utf-8'))
|
||||
|
||||
try:
|
||||
send_sock.connect(encoder)
|
||||
send_sock.sendall(xcmd)
|
||||
ack,response,respstr=XcmdResponse()
|
||||
if response:
|
||||
iprint(respstr)
|
||||
update.syslog(syslog.LOG_INFO,respstr)
|
||||
|
||||
except OSError as e:
|
||||
eprint("Socket error: {0}".format(e))
|
||||
update.syslog(syslog.LOG_WARNING,"Socket error: {0}".format(e))
|
||||
|
||||
except IOError as e:
|
||||
errno,strerror=e.args
|
||||
eprint("I/O error({0}): {1}".format(errno,strerror))
|
||||
update.syslog(syslog.LOG_WARNING,"I/O error({0}): {1}".format(errno,strerror))
|
||||
|
||||
iprint('Closing connection')
|
||||
update.syslog(syslog.LOG_INFO,'Closing connection')
|
||||
send_sock.close()
|
||||
|
||||
# Give the device time to process and close before sending another command
|
||||
@@ -200,6 +188,4 @@ except IndexError:
|
||||
eprint('pypad_xcmd.py: USAGE: cmd <hostname> <port> <config>')
|
||||
sys.exit(1)
|
||||
rcvr.setPadCallback(ProcessPad)
|
||||
iprint('Started')
|
||||
rcvr.start(sys.argv[1],int(sys.argv[2]))
|
||||
iprint('Stopped')
|
||||
|
Reference in New Issue
Block a user