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 re
|
||||
import requests
|
||||
import magic
|
||||
|
||||
from weboob.capabilities.radio import ICapRadio, Radio
|
||||
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 '
|
||||
'configuration file.')
|
||||
|
||||
r=requests.get(stream.url, stream=True)
|
||||
buf=r.iter_content(256).next()
|
||||
m=magic.open(magic.MIME_TYPE)
|
||||
m.load()
|
||||
mime=m.buffer(buf).strip()
|
||||
if mime == "text/plain" or \
|
||||
mime == "audio/x-scpls" or \
|
||||
mime == "application/x-mpegurl":
|
||||
playlistFormat=None
|
||||
r=requests.get(stream.url, stream=True)
|
||||
for line in r.iter_lines():
|
||||
if playlistFormat is None:
|
||||
if line == "[playlist]":
|
||||
playlistFormat = "pls"
|
||||
elif line == "#EXTM3U":
|
||||
playlistFormat = "m3u"
|
||||
elif playlistFormat == "pls":
|
||||
if line.startswith('File'):
|
||||
stream.url = line.split('=', 1).pop(1).strip()
|
||||
break
|
||||
elif playlistFormat == "m3u":
|
||||
if line[0] != "#":
|
||||
stream.url = line.strip();
|
||||
break
|
||||
r = requests.get(stream.url, stream=True)
|
||||
buf = r.iter_content(512).next()
|
||||
r.close()
|
||||
playlistFormat = None
|
||||
for line in buf.split("\n"):
|
||||
if playlistFormat is None:
|
||||
if line == "[playlist]":
|
||||
playlistFormat = "pls"
|
||||
elif line == "#EXTM3U":
|
||||
playlistFormat = "m3u"
|
||||
else:
|
||||
break
|
||||
elif playlistFormat == "pls":
|
||||
if line.startswith('File'):
|
||||
stream.url = line.split('=', 1).pop(1).strip()
|
||||
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)
|
||||
except (InvalidMediaPlayer, MediaPlayerNotFound) as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue