2024-05-29 Fred Gleason <fredg@paravelsystems.com>

* Fixed a bug in the 'pypad_icecast2.py PyPAD script that caused
	mojibake when sending ISO-8859-1 characters with code points >= 0x80.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2024-05-29 15:20:20 -04:00
parent c4e6914c29
commit 0ef5a88a02
2 changed files with 17 additions and 4 deletions

View File

@ -24791,3 +24791,6 @@
* Removed the resynchronization code from the 'RDJsonFramer' class. * Removed the resynchronization code from the 'RDJsonFramer' class.
* Fixed a bug in rdpadd(8) that could cause corruption when processing * Fixed a bug in rdpadd(8) that could cause corruption when processing
JSON updates. JSON updates.
2024-05-29 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in the 'pypad_icecast2.py PyPAD script that caused
mojibake when sending ISO-8859-1 characters with code points >= 0x80.

View File

@ -4,7 +4,7 @@
# #
# Send PAD updates to Icecast2 mountpoint # Send PAD updates to Icecast2 mountpoint
# #
# (C) Copyright 2018-2022 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 # 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 # it under the terms of the GNU General Public License version 2 as
@ -25,8 +25,10 @@ import sys
import socket import socket
import requests import requests
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from requests import Session, Request
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import syslog import syslog
from urllib.parse import quote
try: try:
from rivendellaudio import pypad from rivendellaudio import pypad
except ModuleNotFoundError: except ModuleNotFoundError:
@ -36,6 +38,10 @@ import configparser
def eprint(*args,**kwargs): def eprint(*args,**kwargs):
print(*args,file=sys.stderr,**kwargs) print(*args,file=sys.stderr,**kwargs)
def IcecastQuote(string):
string=quote(string,safe=' ',encoding='ISO-8859-1',errors='replace')
return string
def ProcessPad(update): def ProcessPad(update):
if update.hasPadType(pypad.TYPE_NOW): if update.hasPadType(pypad.TYPE_NOW):
n=1 n=1
@ -47,7 +53,6 @@ def ProcessPad(update):
try: try:
values={} values={}
values['mount']=update.config().get(section,'Mountpoint') values['mount']=update.config().get(section,'Mountpoint')
values['song']=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_NONE)
values['mode']='updinfo' values['mode']='updinfo'
hostname=update.config().get(section,'Hostname') hostname=update.config().get(section,'Hostname')
tcpport=update.config().get(section,'Tcpport') tcpport=update.config().get(section,'Tcpport')
@ -64,9 +69,13 @@ def ProcessPad(update):
# #
if update.shouldBeProcessed(section): if update.shouldBeProcessed(section):
try: try:
response=requests.get(url,auth=HTTPBasicAuth(username,password),params=values) req=Request('GET',url,auth=HTTPBasicAuth(username,password),params=values)
prep=req.prepare()
song=update.resolvePadFields(update.config().get(section,'FormatString'),pypad.ESCAPE_NONE)
prep.url=prep.url+'&song='+IcecastQuote(song)
response=sess.send(prep)
response.raise_for_status() response.raise_for_status()
update.syslog(syslog.LOG_INFO,'Updating '+hostname+': song='+values['song']) update.syslog(syslog.LOG_INFO,'Updating http://'+hostname+values['mount']+': song='+song)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
update.syslog(syslog.LOG_WARNING,str(e)) update.syslog(syslog.LOG_WARNING,str(e))
n=n+1 n=n+1
@ -91,4 +100,5 @@ except IndexError:
eprint('pypad_icecast2: USAGE: cmd <hostname> <port> <config>') eprint('pypad_icecast2: USAGE: cmd <hostname> <port> <config>')
sys.exit(1) sys.exit(1)
rcvr.setPadCallback(ProcessPad) rcvr.setPadCallback(ProcessPad)
sess=Session()
rcvr.start(sys.argv[1],int(sys.argv[2])) rcvr.start(sys.argv[1],int(sys.argv[2]))