]> git.0d.be Git - botaradio.git/commitdiff
fix: radio issue
authorTerry Geng <gengyanda@gmail.com>
Sun, 8 Mar 2020 15:08:47 +0000 (23:08 +0800)
committerTerry Geng <gengyanda@gmail.com>
Sun, 8 Mar 2020 15:08:47 +0000 (23:08 +0800)
command.py
media/radio.py
mumbleBot.py

index 968fad1103d0707e174cf612bea39fd3a648a6b8..cf5dec0b7713e00a8b5030342c947fc129e3e5cb 100644 (file)
@@ -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)
 
index 364c55be614a43e6cf5a3b226e6574b6bcd6a36b..6c3bdd3c89364a81192f76a8ce836f54ef9e0633 100644 (file)
@@ -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,
index a7ec5ce8f803b088cdefca57808132a8fec649f6..7726ba1d1d9617e7823b9af14fb3d6753dfac5e4 100644 (file)
@@ -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()