From 3539df5400f3a82b913b4bfba390f0a8f38bac06 Mon Sep 17 00:00:00 2001 From: Azlux Date: Wed, 31 Jul 2019 00:07:17 +0200 Subject: [PATCH] fix radio description --- README.md | 11 ++++++++++- media/radio.py | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 48de322..7cd81a8 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ Bot the can play : 4. [Generate a certificate](#optional-generate-a-certificate) 5. [Starting the bot](#starting-the-bot) 6. [Custom commands](#custom-commands) -7. [Contributors](#contributors) +7. [Known issues](#known-issues) +8. [Contributors](#contributors) ### Web interface @@ -86,6 +87,14 @@ you have the section : - strings : you can customize all string the bot can say. - debug : option to activate ffmpeg or pymumble debug. (Can be very verbose) +### Known Issues + +During installation, you can have the error: +``` +ImportError: libtiff.so.5: cannot open shared object file: No such file or directory +``` +You need to install a missing system librairie: `apt install libtiff5` + ### Contributors If you want to participate, You're welcome to fork and pull requests (fixes and new features). diff --git a/media/radio.py b/media/radio.py index 04d9345..db9ad8a 100644 --- a/media/radio.py +++ b/media/radio.py @@ -1,10 +1,12 @@ import re -import urllib +import urllib.request +import urllib.error import logging import json import http.client import struct + def get_radio_server_description(url): p = re.compile('(https?\:\/\/[^\/]*)', re.IGNORECASE) res = re.search(p, url) @@ -29,18 +31,20 @@ def get_radio_server_description(url): try: request = urllib.request.Request(url_icecast) response = urllib.request.urlopen(request) - data = json.loads(response.read().decode('utf-8', errors='ignore'), strict=False) - source = data['icestats']['source'] - if type(source) is list: - source = source[0] - title_server = source['server_name'] + ' - ' + source['server_description'] - logging.info("TITLE FOUND ICECAST: " + title_server) - if not title_server: - title_server = url + response_data = response.read().decode('utf-8', errors='ignore') + if response_data: + data = json.loads(response_data, strict=False) + source = data['icestats']['source'] + if type(source) is list: + source = source[0] + title_server = source['server_name'] + if 'server_description' in source: + title_server += ' - ' + source['server_description'] + logging.info("TITLE FOUND ICECAST: " + title_server) + if not title_server: + title_server = url except urllib.error.URLError: title_server = url - except urllib.error.HTTPError: - return False except http.client.BadStatusLine: pass return title_server @@ -67,4 +71,3 @@ def get_radio_title(url): except (urllib.error.URLError, urllib.error.HTTPError): pass return 'Unable to get the music title' -