Commit 7ca15611 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧

Support fetching the current FIP song

Sadly the weird encoding stuff is required.
parent 3c9c2c74
......@@ -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 @@ class RadioFranceBackend(BaseBackend, ICapRadio, ICapCollection):
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)
......
......@@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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 @@ class RssPage(BasePage):
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 @@ class RadioFranceBrowser(BaseBrowser):
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment