From e957a1fe012ef1dd5ccee3bcb6d3b24d16aeb036 Mon Sep 17 00:00:00 2001 From: Pecusx Date: Fri, 5 May 2017 23:41:00 +0200 Subject: [PATCH] New streaming (mpd and pianobar) with metadata --- radio4.py | 10 ++++++++++ radio_class.py | 9 ++++++++- version | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/radio4.py b/radio4.py index 3ab6b8e..b64d9e2 100755 --- a/radio4.py +++ b/radio4.py @@ -32,6 +32,7 @@ from time import strftime import shutil import atexit import traceback +import requests # Class imports from radio_daemon import Daemon @@ -53,6 +54,7 @@ DOWN = 1 #CurrentFile = CurrentStationFile PlaylistsDirectory = "/var/lib/mpd/playlists/" + log = Log() radio = Radio() lcd = Lcd() @@ -549,6 +551,14 @@ def display_current(lcd,radio,toggleScrolling): current_artist = radio.getCurrentArtist() lcd.line2(current_artist) + # Send metadata to icecast server + if radio.streaming: + if radio.streammetadata != title: + radio.streammetadata = title + metadataFormatted = radio.streammetadata.replace(" ","+") #add "+" instead of " " for icecast2 + requestToSend = ("http://localhost:8001/admin/metadata?mount=/mpd&mode=updinfo&song=") +(metadataFormatted) + r = requests.get((requestToSend), auth=("admin","mympd")) + # Display stream error if radio.gotError(): errorStr = radio.getErrorString() diff --git a/radio_class.py b/radio_class.py index cf97b0f..ce32b34 100755 --- a/radio_class.py +++ b/radio_class.py @@ -168,6 +168,10 @@ class Radio: pandora_station_name = '' pandora_song_name = '' pandora_progress = '' + + + # Metadata for icecast server + streammetadata = '' # Clock and timer options timer = False # Timer on @@ -1387,6 +1391,7 @@ class Radio: output_id = 2 self.streaming = True self.execCommand("service icecast2 start") + self.execCommand("service darkice start") self.execMpcCommand("enable " + str(output_id)) self.storeStreaming("on") self.streamingStatus() @@ -1397,9 +1402,11 @@ class Radio: output_id = 2 self.streaming = False self.execMpcCommand("disable " + str(output_id)) + self.execCommand("service darkice stop") self.execCommand("service icecast2 stop") self.storeStreaming("off") self.streamingStatus() + self.streammetadata = '' return self.streaming # Display streaming status @@ -2661,7 +2668,7 @@ class Radio: #self.speak(current) # (Pecus) #self.speak(name) # (Pecus) #self.speak(title) # (Pecus) - self.speakAlways(time + ' . ' + current + '. ' + name + '. ' + title) # says even id excluded speaking in config file (Pecus) + self.speakAlways(time + ' , ' + current + ', ' + name + ', ' + title) # says even id excluded speaking in config file (Pecus) return # Is speech enabled diff --git a/version b/version index 393b602..41b9d31 100644 --- a/version +++ b/version @@ -1 +1 @@ -5.4h +5.5a