From 7ca156116ee4df6c9f2209d63a20c611370e2785 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Fri, 3 Feb 2012 13:54:01 +0100 Subject: [PATCH] Support fetching the current FIP song Sadly the weird encoding stuff is required. --- modules/radiofrance/backend.py | 3 +++ modules/radiofrance/browser.py | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/radiofrance/backend.py b/modules/radiofrance/backend.py index d9e1315507..abb9d22bfd 100644 --- a/modules/radiofrance/backend.py +++ b/modules/radiofrance/backend.py @@ -99,6 +99,7 @@ class RadioFranceBackend(BaseBackend, ICapRadio, ICapCollection): _DIRECTJSON_RADIOS = ('lemouv', 'franceinter', ) _RSS_RADIOS = ('francemusique', ) + _ANTENNA_RADIOS = ('fip', ) def iter_resources(self, split_path): if len(split_path) == 1 and split_path[0] == 'francebleu': @@ -160,6 +161,8 @@ def fill_radio(self, radio, fields): title = dtitle if radio.id in self._RSS_RADIOS: title = self.browser.get_current_rss(radio.id) + if radio.id in self._ANTENNA_RADIOS: + artist, title = self.browser.get_current_antenna(radio.id) if title: if not radio.current or radio.current is NotLoaded: radio.current = Emission(0) diff --git a/modules/radiofrance/browser.py b/modules/radiofrance/browser.py index 4386371edd..5e30fe27ca 100644 --- a/modules/radiofrance/browser.py +++ b/modules/radiofrance/browser.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . -from weboob.tools.browser import BaseBrowser, BasePage +from weboob.tools.browser import BaseBrowser, BasePage, BrokenPageError from StringIO import StringIO from time import time @@ -52,11 +52,26 @@ def get_title(self): return ' '.join(titles) +class RssAntennaPage(BasePage): + ENCODING = 'ISO-8859-1' + def get_track(self): + # This information is not always available + try: + marquee = self.parser.select(self.document.getroot(), 'marquee', 1) + track = self.parser.select(marquee, 'font b', 2) + artist = unicode(track[0].text).strip() or None + title = unicode(track[1].text).strip() or None + return (artist, title) + except BrokenPageError: + return (None, None) + + class RadioFranceBrowser(BaseBrowser): DOMAIN = None ENCODING = 'UTF-8' PAGES = {r'/playerjs/direct/donneesassociees/html\?guid=$': DataPage, - r'http://players.tv-radio.com/radiofrance/metadatas/([a-z]+)RSS.html': RssPage} + r'http://players.tv-radio.com/radiofrance/metadatas/([a-z]+)RSS.html': RssPage, + r'http://players.tv-radio.com/radiofrance/metadatas/([a-z]+)RSS_a_lantenne.html': RssAntennaPage} def get_current_playerjs(self, _id): self.location('http://www.%s.fr/playerjs/direct/donneesassociees/html?guid=' % _id) @@ -80,3 +95,11 @@ def get_current_direct(self, _id): artist = unicode(artist) if artist else None title = unicode(title) if title else None return (artist, title) + + def get_current_antenna(self, _id): + self.ENCODING = RssAntennaPage.ENCODING + self.location('http://players.tv-radio.com/radiofrance/metadatas/%sRSS_a_lantenne.html' % _id) + assert self.is_on_page(RssAntennaPage) + result = self.page.get_track() + self.ENCODING = RadioFranceBrowser.ENCODING + return result -- GitLab