fix radio description

This commit is contained in:
Azlux 2019-07-31 00:07:17 +02:00
parent 42a99352df
commit 3539df5400
2 changed files with 25 additions and 13 deletions

View File

@ -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).

View File

@ -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)
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'] + ' - ' + source['server_description']
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'