From 2ef550eb7bb8506cf5621c5404c58443576a7fc3 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Mon, 16 May 2011 22:01:30 +0200 Subject: [PATCH] Add error handling code for shoutcast errors --- mopidy/outputs/shoutcast.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mopidy/outputs/shoutcast.py b/mopidy/outputs/shoutcast.py index 26af449b..4298bba5 100644 --- a/mopidy/outputs/shoutcast.py +++ b/mopidy/outputs/shoutcast.py @@ -1,6 +1,10 @@ +import logging + from mopidy import settings from mopidy.outputs import BaseOutput +logger = logging.getLogger('mopidy.outputs.shoutcast') + class ShoutcastOutput(BaseOutput): """ Shoutcast streaming output. @@ -16,11 +20,26 @@ class ShoutcastOutput(BaseOutput): % settings.SHOUTCAST_OUTPUT_ENCODER def modify_bin(self): - shoutcast = self.bin.get_by_name('shoutcast') - self.set_properties(shoutcast, { + self.set_properties(self.bin.get_by_name('shoutcast'), { u'ip': settings.SHOUTCAST_OUTPUT_SERVER, u'mount': settings.SHOUTCAST_OUTPUT_MOUNT, u'port': settings.SHOUTCAST_OUTPUT_PORT, u'username': settings.SHOUTCAST_OUTPUT_USERNAME, u'password': settings.SHOUTCAST_OUTPUT_PASSWORD, }) + + def on_connect(self): + self.gstreamer.connect_message_handler( + self.bin.get_by_name('shoutcast'), self.message_handler) + + def on_remove(self): + self.gstreamer.remove_message_handler( + self.bin.get_by_name('shoutcast')) + + def message_handler(self, message): + if message.type != self.MESSAGE_ERROR: + return False + error, debug = message.parse_error() + logger.warning('%s (%s)', error, debug) + self.remove() + return True