modify somafm module to use the modified ICapRadio

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2013-12-15 20:15:36 +01:00 committed by Florent
commit b965e8222c
2 changed files with 20 additions and 12 deletions

View file

@ -19,7 +19,8 @@
import lxml.etree import lxml.etree
from weboob.capabilities.radio import ICapRadio, Radio, Stream, Emission from weboob.capabilities.radio import ICapRadio, Radio
from weboob.capabilities.audiostream import BaseAudioStream, AudioStreamInfo
from weboob.capabilities.collection import ICapCollection from weboob.capabilities.collection import ICapCollection
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
from weboob.tools.browser import StandardBrowser from weboob.tools.browser import StandardBrowser
@ -62,21 +63,30 @@ class SomaFMBackend(BaseBackend, ICapRadio, ICapCollection):
document = self.browser.location(self.ALLINFO) document = self.browser.location(self.ALLINFO)
for channel in document.iter('channel'): for channel in document.iter('channel'):
radio = Radio(channel.get('id')) id=channel.get('id')
radio = Radio(id)
radio.title = channel.findtext('title') radio.title = channel.findtext('title')
radio.description = channel.findtext('description') radio.description = channel.findtext('description')
current_data = channel.findtext('lastPlaying') current_data = channel.findtext('lastPlaying')
current = Emission(0) current = AudioStreamInfo(0)
current.artist, current.title = self._parse_current(current_data) current.what, current.who = self._parse_current(current_data)
radio.current = current radio.current = current
radio.streams = [] radio.streams = []
stream_id = 0 stream_id = 0
for subtag in channel: for subtag in channel:
if subtag.tag.endswith('pls'): if subtag.tag.endswith('pls'):
stream = Stream(stream_id) stream = BaseAudioStream(stream_id)
stream.title = '%s/%s' % (subtag.tag.replace('pls', ''), subtag.get('format')) bitrate=subtag.text.replace('http://somafm.com/'+id,'').replace('.pls','')
if(bitrate != ''):
stream.bitrate=int(bitrate)
bitrate+='Kbps'
else:
stream.bitrate=0
bitrate=subtag.tag.replace('pls','')
stream.format=subtag.get('format')
stream.title = '%s/%s' % (bitrate, stream.format)
stream.url = subtag.text stream.url = subtag.text
radio.streams.append(stream) radio.streams.append(stream)
stream_id += 1 stream_id += 1
@ -110,10 +120,8 @@ class SomaFMBackend(BaseBackend, ICapRadio, ICapCollection):
def fill_radio(self, radio, fields): def fill_radio(self, radio, fields):
if 'current' in fields: if 'current' in fields:
if not radio.current: return self.get_radio(radio.id)
radio.current = Emission(0)
radio.current.artist, radio.current.title = self.get_current(radio.id)
return radio return radio
#OBJECTS = {Radio: fill_radio} OBJECTS = {Radio: fill_radio}

View file

@ -36,8 +36,8 @@ class SomaFMTest(BackendTest):
radio = self.backend.get_radio('doomed') radio = self.backend.get_radio('doomed')
self.assertTrue(radio.title) self.assertTrue(radio.title)
self.assertTrue(radio.description) self.assertTrue(radio.description)
self.assertTrue(radio.current.title) self.assertTrue(radio.current.who)
self.assertTrue(radio.current.artist) self.assertTrue(radio.current.what)
self.assertTrue(radio.streams[0].url) self.assertTrue(radio.streams[0].url)
self.assertTrue(radio.streams[0].title) self.assertTrue(radio.streams[0].title)