From 8d15911d67e9b89cf2eab1bc55b3dfdb53f608c2 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Thu, 2 Feb 2012 15:25:13 +0100 Subject: [PATCH] Fix some failures with badly set 'current' field. --- modules/radiofrance/backend.py | 31 +++++++++++++++----------- weboob/applications/radioob/radioob.py | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/radiofrance/backend.py b/modules/radiofrance/backend.py index 3d1baa117a..09c35af0a5 100644 --- a/modules/radiofrance/backend.py +++ b/modules/radiofrance/backend.py @@ -18,6 +18,7 @@ # along with weboob. If not, see . +from weboob.capabilities.base import NotLoaded from weboob.capabilities.radio import ICapRadio, Radio, Stream, Emission from weboob.capabilities.collection import ICapCollection, CollectionNotFound, Collection from weboob.tools.backend import BaseBackend @@ -42,6 +43,7 @@ def get_title(self): if len(title): return title + class RssPage(BasePage): def get_title(self): titles = [] @@ -189,6 +191,8 @@ def get_radio(self, radio): else: url = self._MP3_URL % (radio.id, radio.id) + # This should be asked demand, but is required for now as Radioob + # does not require it. self.fillobj(radio, ('current', )) stream = Stream(0) @@ -199,23 +203,24 @@ def get_radio(self, radio): def fill_radio(self, radio, fields): if 'current' in fields: - if not radio.current: - radio.current = Emission(0) - radio.current.artist = None - radio.current.title = None + artist = None + title = None if radio.id in self._PLAYERJS_RADIOS: - radio.current.title = self.browser.get_current_playerjs(radio.id) + title = self.browser.get_current_playerjs(radio.id) if radio.id in self._DIRECTJSON_RADIOS: - artist, title = self.browser.get_current_direct(radio.id) - if artist: - radio.current.artist = artist - if title: - if radio.current.title: - radio.current.title = "%s [%s]" % (title, radio.current.title) + artist, dtitle = self.browser.get_current_direct(radio.id) + if dtitle: + if title: + title = "%s [%s]" % (dtitle, title) else: - radio.current.title = title + title = dtitle if radio.id in self._RSS_RADIOS: - radio.current.title = self.browser.get_current_rss(radio.id) + title = self.browser.get_current_rss(radio.id) + if title: + if not radio.current or radio.current is NotLoaded: + radio.current = Emission(0) + radio.current.title = title + radio.current.arist = artist return radio OBJECTS = {Radio: fill_radio} diff --git a/weboob/applications/radioob/radioob.py b/weboob/applications/radioob/radioob.py index 3d3ab7bdc9..87be803657 100644 --- a/weboob/applications/radioob/radioob.py +++ b/weboob/applications/radioob/radioob.py @@ -118,7 +118,7 @@ def do_info(self, _id): print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) return 2 - radio = self.get_object(_id, 'get_radio') + radio = self.get_object(_id, 'get_radio', ['streams', 'current']) if not radio: print >>sys.stderr, 'Radio not found:', _id return 3 -- GitLab