Better icecast metadata formatting (with special characters)

This commit is contained in:
Pecusx
2017-05-06 08:52:38 +02:00
committed by GitHub
parent 5448870354
commit 0e2bd3cf23
+12 -4
View File
@@ -517,7 +517,8 @@ def display_current(lcd,radio,toggleScrolling):
title = radio.getCurrentTitle() title = radio.getCurrentTitle()
current_id = radio.getCurrentID() current_id = radio.getCurrentID()
source = radio.getSource() source = radio.getSource()
streeamname = ''
# Display progress of the currently playing track # Display progress of the currently playing track
if radio.muted(): if radio.muted():
displayVolume(lcd,radio) displayVolume(lcd,radio)
@@ -528,7 +529,9 @@ def display_current(lcd,radio,toggleScrolling):
displayVolume(lcd,radio) displayVolume(lcd,radio)
if source == radio.RADIO: if source == radio.RADIO:
streamname = '[' + station + '] - ' + title
if len(title) < 1: if len(title) < 1:
streamname = '[' + station + ']'
bitrate = radio.getBitRate() bitrate = radio.getBitRate()
if bitrate > 0: if bitrate > 0:
title = "Station " + str(current_id) + ' ' + str(bitrate) +'k' title = "Station " + str(current_id) + ' ' + str(bitrate) +'k'
@@ -541,6 +544,7 @@ def display_current(lcd,radio,toggleScrolling):
else: else:
lcd.line2(station) lcd.line2(station)
elif source == radio.PANDORA: elif source == radio.PANDORA:
streamname = title
if toggleScrolling: if toggleScrolling:
lcd.line3(title) lcd.line3(title)
lcd.scroll2(station, interrupt) lcd.scroll2(station, interrupt)
@@ -551,12 +555,16 @@ def display_current(lcd,radio,toggleScrolling):
playlist = radio.getPlayList() playlist = radio.getPlayList()
current_artist = radio.getCurrentArtist() current_artist = radio.getCurrentArtist()
lcd.line2(current_artist) lcd.line2(current_artist)
streamname = current_artist + ' - ' + title
# Send metadata to icecast server # Send metadata to icecast server
if radio.streaming: if radio.streaming:
if radio.streammetadata != title: if radio.streammetadata != streamname:
radio.streammetadata = title radio.streammetadata = streamname
metadataFormatted = radio.streammetadata.replace(" ","+") #add "+" instead of " " for icecast2 metadataFormatted = streamname.replace("%","%25")
metadataFormatted = metadataFormatted.replace("&","%26")
metadataFormatted = metadataFormatted.replace("@","%40")
metadataFormatted = metadataFormatted.replace(" ","+") #add "+" instead of " " for icecast2
requestToSend = ("http://localhost:8001/admin/metadata?mount=/mpd&mode=updinfo&song=") +(metadataFormatted) requestToSend = ("http://localhost:8001/admin/metadata?mount=/mpd&mode=updinfo&song=") +(metadataFormatted)
r = requests.get((requestToSend), auth=("admin","mympd")) r = requests.get((requestToSend), auth=("admin","mympd"))