radioob: get rid of magic
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
690010a8d2
commit
34a7481895
1 changed files with 20 additions and 25 deletions
|
|
@ -22,7 +22,6 @@ import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
import magic
|
|
||||||
|
|
||||||
from weboob.capabilities.radio import ICapRadio, Radio
|
from weboob.capabilities.radio import ICapRadio, Radio
|
||||||
from weboob.capabilities.audio import ICapAudio, BaseAudio
|
from weboob.capabilities.audio import ICapAudio, BaseAudio
|
||||||
|
|
@ -179,30 +178,26 @@ class Radioob(ReplApplication):
|
||||||
self.logger.debug(u'You can set the media_player key to the player you prefer in the radioob '
|
self.logger.debug(u'You can set the media_player key to the player you prefer in the radioob '
|
||||||
'configuration file.')
|
'configuration file.')
|
||||||
|
|
||||||
r=requests.get(stream.url, stream=True)
|
r = requests.get(stream.url, stream=True)
|
||||||
buf=r.iter_content(256).next()
|
buf = r.iter_content(512).next()
|
||||||
m=magic.open(magic.MIME_TYPE)
|
r.close()
|
||||||
m.load()
|
playlistFormat = None
|
||||||
mime=m.buffer(buf).strip()
|
for line in buf.split("\n"):
|
||||||
if mime == "text/plain" or \
|
if playlistFormat is None:
|
||||||
mime == "audio/x-scpls" or \
|
if line == "[playlist]":
|
||||||
mime == "application/x-mpegurl":
|
playlistFormat = "pls"
|
||||||
playlistFormat=None
|
elif line == "#EXTM3U":
|
||||||
r=requests.get(stream.url, stream=True)
|
playlistFormat = "m3u"
|
||||||
for line in r.iter_lines():
|
else:
|
||||||
if playlistFormat is None:
|
break
|
||||||
if line == "[playlist]":
|
elif playlistFormat == "pls":
|
||||||
playlistFormat = "pls"
|
if line.startswith('File'):
|
||||||
elif line == "#EXTM3U":
|
stream.url = line.split('=', 1).pop(1).strip()
|
||||||
playlistFormat = "m3u"
|
break
|
||||||
elif playlistFormat == "pls":
|
elif playlistFormat == "m3u":
|
||||||
if line.startswith('File'):
|
if line[0] != "#":
|
||||||
stream.url = line.split('=', 1).pop(1).strip()
|
stream.url = line.strip()
|
||||||
break
|
break
|
||||||
elif playlistFormat == "m3u":
|
|
||||||
if line[0] != "#":
|
|
||||||
stream.url = line.strip();
|
|
||||||
break
|
|
||||||
|
|
||||||
self.player.play(stream, player_name=player_name, player_args=media_player_args)
|
self.player.play(stream, player_name=player_name, player_args=media_player_args)
|
||||||
except (InvalidMediaPlayer, MediaPlayerNotFound) as e:
|
except (InvalidMediaPlayer, MediaPlayerNotFound) as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue