radio: don't get stuck on mpd http streams
Merge pull request #285 from mweinelt/mpd-radio-stream
This commit is contained in:
commit
ba02cdebf2
@ -22,11 +22,13 @@ def get_radio_server_description(url):
|
|||||||
url_icecast = base_url + '/status-json.xsl'
|
url_icecast = base_url + '/status-json.xsl'
|
||||||
url_shoutcast = base_url + '/stats?json=1'
|
url_shoutcast = base_url + '/stats?json=1'
|
||||||
try:
|
try:
|
||||||
r = requests.get(url_shoutcast, timeout=10)
|
response = requests.head(url_shoutcast, timeout=3)
|
||||||
data = r.json()
|
if not response.headers.get('content-type', '').startswith(("audio/", "video/")):
|
||||||
title_server = data['servertitle']
|
response = requests.get(url_shoutcast, timeout=10)
|
||||||
return title_server
|
data = response.json()
|
||||||
# logging.info("TITLE FOUND SHOUTCAST: " + title_server)
|
title_server = data['servertitle']
|
||||||
|
return title_server
|
||||||
|
# logging.info("TITLE FOUND SHOUTCAST: " + title_server)
|
||||||
except (requests.exceptions.ConnectionError,
|
except (requests.exceptions.ConnectionError,
|
||||||
requests.exceptions.HTTPError,
|
requests.exceptions.HTTPError,
|
||||||
requests.exceptions.ReadTimeout,
|
requests.exceptions.ReadTimeout,
|
||||||
@ -38,16 +40,18 @@ def get_radio_server_description(url):
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(url_icecast, timeout=10)
|
response = requests.head(url_shoutcast, timeout=3)
|
||||||
data = r.json()
|
if not response.headers.get('content-type', '').startswith(("audio/", "video/")):
|
||||||
source = data['icestats']['source']
|
response = requests.get(url_icecast, timeout=10)
|
||||||
if type(source) is list:
|
data = response.json()
|
||||||
source = source[0]
|
source = data['icestats']['source']
|
||||||
title_server = source['server_name']
|
if type(source) is list:
|
||||||
if 'server_description' in source:
|
source = source[0]
|
||||||
title_server += ' - ' + source['server_description']
|
title_server = source['server_name']
|
||||||
# logging.info("TITLE FOUND ICECAST: " + title_server)
|
if 'server_description' in source:
|
||||||
return title_server
|
title_server += ' - ' + source['server_description']
|
||||||
|
# logging.info("TITLE FOUND ICECAST: " + title_server)
|
||||||
|
return title_server
|
||||||
except (requests.exceptions.ConnectionError,
|
except (requests.exceptions.ConnectionError,
|
||||||
requests.exceptions.HTTPError,
|
requests.exceptions.HTTPError,
|
||||||
requests.exceptions.ReadTimeout,
|
requests.exceptions.ReadTimeout,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user