1
0
mirror of https://github.com/azlux/botamusique synced 2024-11-23 13:56:17 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
ba02cdebf2
radio: don't get stuck on mpd http streams
Merge pull request #285 from mweinelt/mpd-radio-stream
2021-06-01 23:39:44 +02:00
Martin Weinelt
48d54beffd
radio: don't get stuck on mpd http streams
MPD HTTP streaming provide the media content at every URL thrown at the
HTTP backend. So requests for shoutcast and icecast metadata get stuck
receiving the actual media content, instead of the expected metadata.

The conclusion is to only request these metadata files, when they're not
actually advertised as audio or video content types in a HEAD request.
2021-06-01 23:16:22 +02:00

View File

@ -22,8 +22,10 @@ def get_radio_server_description(url):
url_icecast = base_url + '/status-json.xsl'
url_shoutcast = base_url + '/stats?json=1'
try:
r = requests.get(url_shoutcast, timeout=10)
data = r.json()
response = requests.head(url_shoutcast, timeout=3)
if not response.headers.get('content-type', '').startswith(("audio/", "video/")):
response = requests.get(url_shoutcast, timeout=10)
data = response.json()
title_server = data['servertitle']
return title_server
# logging.info("TITLE FOUND SHOUTCAST: " + title_server)
@ -38,8 +40,10 @@ def get_radio_server_description(url):
return url
try:
r = requests.get(url_icecast, timeout=10)
data = r.json()
response = requests.head(url_shoutcast, timeout=3)
if not response.headers.get('content-type', '').startswith(("audio/", "video/")):
response = requests.get(url_icecast, timeout=10)
data = response.json()
source = data['icestats']['source']
if type(source) is list:
source = source[0]