2019-08-11 Fred Gleason <fredg@paravelsystems.com>

* Fixed a bug in the 'pypad.update.shouldBeProcessed()' method
	that caused log selection directives to be ignored.
	* Refactored the 'pypad_icecast2.py' script to work properly with
	the fixed 'pypad.update.shouldBeProcessed()' method.
	* Refactored the 'pypad_shoutcast2.py' script to work properly with
	the fixed 'pypad.update.shouldBeProcessed()' method.
This commit is contained in:
Fred Gleason
2019-08-11 17:44:44 -04:00
parent 987090c46f
commit 56feb08896
4 changed files with 63 additions and 33 deletions

View File

@@ -34,25 +34,37 @@ def ProcessPad(update):
if update.hasPadType(pypad.TYPE_NOW):
n=1
while(True):
#
# First, get all of our configuration values
#
section='Icecast'+str(n)
try:
values={}
values['mount']=update.config().get(section,'Mountpoint')
values['song']=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_NONE)
values['mode']='updinfo'
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:
update.syslog(syslog.LOG_WARNING,str(e))
n=n+1
hostname=update.config().get(section,'Hostname')
tcpport=update.config().get(section,'Tcpport')
username=update.config().get(section,'Username')
password=update.config().get(section,'Password')
url="http://%s:%s/admin/metadata" % (hostname,tcpport)
except configparser.NoSectionError:
if(n==1):
update.syslog(syslog.LOG_WARNING,'No icecast config found')
return
#
# Now, send the update
#
if update.shouldBeProcessed(section):
try:
response=requests.get(url,auth=HTTPBasicAuth(username,password),params=values)
response.raise_for_status()
update.syslog(syslog.LOG_INFO,'Updating '+hostname+': song='+values['song'])
except requests.exceptions.RequestException as e:
update.syslog(syslog.LOG_WARNING,str(e))
n=n+1
#
# Program Name
#

View File

@@ -27,23 +27,18 @@ import pycurl
import pypad
from io import BytesIO
last_updates={}
def eprint(*args,**kwargs):
print(*args,file=sys.stderr,**kwargs)
def ProcessPad(update):
try:
last_updates[update.machine()]
except KeyError:
last_updates[update.machine()]=None
n=1
try:
if update.hasPadType(pypad.TYPE_NOW):
n=1
while(True):
#
# First, get all of our configuration values
#
section='Shoutcast'+str(n)
if update.shouldBeProcessed(section) and update.hasPadType(pypad.TYPE_NOW) and (last_updates[update.machine()] != update.startDateTimeString(pypad.TYPE_NOW)):
last_updates[update.machine()]=update.startDateTimeString(pypad.TYPE_NOW)
try:
song=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_URL)
url='http://'+update.config().get(section,'Hostname')+':'+str(update.config().get(section,'Tcpport'))+'/admin.cgi?pass='+update.escape(update.config().get(section,'Password'),pypad.ESCAPE_URL)+'&mode=updinfo&song='+song
curl=pycurl.Curl()
@@ -55,6 +50,13 @@ def ProcessPad(update):
#
headers.append('User-Agent: '+'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2')
curl.setopt(curl.HTTPHEADER,headers);
except configparser.NoSectionError:
return
#
# Now, send the update
#
if update.shouldBeProcessed(section):
try:
curl.perform()
code=curl.getinfo(pycurl.RESPONSE_CODE)
@@ -65,8 +67,6 @@ def ProcessPad(update):
curl.close()
n=n+1
except configparser.NoSectionError:
return
#
# 'Main' function