diff --git a/command.py b/command.py index 968fad1..cf5dec0 100644 --- a/command.py +++ b/command.py @@ -353,7 +353,7 @@ def cmd_play_radio(bot, user, text, command, parameter): parameter = parameter.split()[0] url = util.get_url_from_input(parameter) if url: - music_wrapper = get_item_wrapper_from_scrap(bot, type='radio', url=url) + music_wrapper = get_item_wrapper_from_scrap(bot, type='radio', url=url, user=user) var.playlist.append(music_wrapper) log.info("cmd: add to playlist: " + music_wrapper.format_debug_string()) @@ -667,7 +667,7 @@ def cmd_last(bot, user, text, command, parameter): if len(var.playlist) > 0: bot.interrupt() - var.playlist.point_to(len(var.playlist) - 1) + var.playlist.point_to(len(var.playlist) - 1 - 1) else: bot.send_msg(constants.strings('queue_empty'), text) @@ -775,7 +775,7 @@ def cmd_repeat(bot, user, text, command, parameter): var.playlist.current_index + 1, music ) - log.info("bot: add to playlist: " + music.format_debug_string) + log.info("bot: add to playlist: " + music.format_debug_string()) bot.send_msg(constants.strings("repeat", song=music.format_song_string(), n=str(repeat)), text) diff --git a/media/radio.py b/media/radio.py index 364c55b..6c3bdd3 100644 --- a/media/radio.py +++ b/media/radio.py @@ -22,12 +22,15 @@ def get_radio_server_description(url): url_shoutcast = base_url + '/stats?json=1' title_server = None try: - r = requests.get(url_shoutcast, timeout=5) + r = requests.get(url_shoutcast, timeout=10) data = r.json() title_server = data['servertitle'] return title_server # logging.info("TITLE FOUND SHOUTCAST: " + title_server) - except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout) as e: + except (requests.exceptions.ConnectionError, + requests.exceptions.HTTPError, + requests.exceptions.ReadTimeout, + requests.exceptions.Timeout) as e: error_traceback = traceback.format_exc() error = error_traceback.rstrip().split("\n")[-1] log.debug("radio: unsuccessful attempts on fetching radio description (shoutcast): " + error) @@ -35,7 +38,7 @@ def get_radio_server_description(url): return False # ? try: - r = requests.get(url_icecast, timeout=5) + r = requests.get(url_icecast, timeout=10) data = r.json() source = data['icestats']['source'] if type(source) is list: @@ -45,7 +48,10 @@ def get_radio_server_description(url): title_server += ' - ' + source['server_description'] # logging.info("TITLE FOUND ICECAST: " + title_server) return title_server - except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout) as e: + except (requests.exceptions.ConnectionError, + requests.exceptions.HTTPError, + requests.exceptions.ReadTimeout, + requests.exceptions.Timeout) as e: error_traceback = traceback.format_exc() error = error_traceback.rstrip().split("\n")[-1] log.debug("radio: unsuccessful attempts on fetching radio description (icecast): " + error) @@ -58,7 +64,7 @@ def get_radio_title(url): log.debug("radio: fetching radio server description") try: - r = requests.get(url, headers={'Icy-MetaData': '1'}, stream=True, timeout=5) + r = requests.get(url, headers={'Icy-MetaData': '1'}, stream=True, timeout=10) icy_metaint_header = int(r.headers['icy-metaint']) r.raw.read(icy_metaint_header) @@ -71,8 +77,13 @@ def get_radio_title(url): title = m.group(1) if title: return title.decode() - except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as e: - pass + except (requests.exceptions.ConnectionError, + requests.exceptions.HTTPError, + requests.exceptions.ReadTimeout, + requests.exceptions.Timeout) as e: + error_traceback = traceback.format_exc() + error = error_traceback.rstrip().split("\n")[-1] + log.debug("radio: unsuccessful attempts on fetching radio title (icy): " + e) return url @@ -125,6 +136,8 @@ class RadioItem(BaseItem): dict['url'] = self.url dict['title'] = self.title + return dict + def format_debug_string(self): return "[radio] {name} ({url})".format( name=self.title, diff --git a/mumbleBot.py b/mumbleBot.py index a7ec5ce..7726ba1 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -215,7 +215,7 @@ class MumbleBot: # use the first word as a command, the others one as parameters if len(message) > 0: - command = message[0] + command = message[0].lower() parameter = '' if len(message) > 1: parameter = message[1].rstrip()