website change: get the new json file containing current songs
This commit is contained in:
parent
2cc992a8bc
commit
7ee6ce1c4a
1 changed files with 16 additions and 25 deletions
|
|
@ -21,33 +21,12 @@
|
||||||
from weboob.capabilities.radio import ICapRadio, Radio, Stream, Emission
|
from weboob.capabilities.radio import ICapRadio, Radio, Stream, Emission
|
||||||
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend
|
from weboob.tools.backend import BaseBackend
|
||||||
from weboob.tools.browser import BaseBrowser, BasePage
|
from weboob.tools.browser import StandardBrowser
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['OuiFMBackend']
|
__all__ = ['OuiFMBackend']
|
||||||
|
|
||||||
|
|
||||||
class PlayerPage(BasePage):
|
|
||||||
def get_current(self):
|
|
||||||
title = self.parser.select(self.document.getroot(), 'span.titre_en_cours', 1).text
|
|
||||||
artist = self.parser.select(self.document.getroot(), 'span.artiste_en_cours', 1).text
|
|
||||||
return unicode(artist).strip(), unicode(title).strip()
|
|
||||||
|
|
||||||
class OuiFMBrowser(BaseBrowser):
|
|
||||||
DOMAIN = u'www.ouifm.fr'
|
|
||||||
PAGES = {r'.*ouifm.fr/player/decode_json.*.php': PlayerPage,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_current(self, radio):
|
|
||||||
if radio == 'general':
|
|
||||||
_radio = ''
|
|
||||||
else:
|
|
||||||
_radio = '_%s' % radio
|
|
||||||
self.location('/player/decode_json%s.php' % _radio)
|
|
||||||
assert self.is_on_page(PlayerPage)
|
|
||||||
|
|
||||||
return self.page.get_current()
|
|
||||||
|
|
||||||
class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
NAME = 'ouifm'
|
NAME = 'ouifm'
|
||||||
MAINTAINER = 'Romain Bignon'
|
MAINTAINER = 'Romain Bignon'
|
||||||
|
|
@ -55,7 +34,7 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
VERSION = '0.9'
|
VERSION = '0.9'
|
||||||
DESCRIPTION = u'The Ouï FM french radio'
|
DESCRIPTION = u'The Ouï FM french radio'
|
||||||
LICENSE = 'AGPLv3+'
|
LICENSE = 'AGPLv3+'
|
||||||
BROWSER = OuiFMBrowser
|
BROWSER = StandardBrowser
|
||||||
|
|
||||||
_RADIOS = {'general': (u'OUÏ FM', u'OUI FM', u'http://ouifm.ice.infomaniak.ch/ouifm-high.mp3'),
|
_RADIOS = {'general': (u'OUÏ FM', u'OUI FM', u'http://ouifm.ice.infomaniak.ch/ouifm-high.mp3'),
|
||||||
'alternatif': (u'OUÏ FM Alternatif', u'OUI FM - L\'Alternative Rock', u'http://ouifm.ice.infomaniak.ch/ouifm2.mp3'),
|
'alternatif': (u'OUÏ FM Alternatif', u'OUI FM - L\'Alternative Rock', u'http://ouifm.ice.infomaniak.ch/ouifm2.mp3'),
|
||||||
|
|
@ -64,6 +43,9 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
'inde': (u'OUÏ FM Indé', u'OUI FM - Rock Indé', u'http://ouifm.ice.infomaniak.ch/ouifm5.mp3'),
|
'inde': (u'OUÏ FM Indé', u'OUI FM - Rock Indé', u'http://ouifm.ice.infomaniak.ch/ouifm5.mp3'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def create_default_browser(self):
|
||||||
|
return self.create_browser(parser='json')
|
||||||
|
|
||||||
def iter_resources(self, splited_path):
|
def iter_resources(self, splited_path):
|
||||||
if len(splited_path) > 0:
|
if len(splited_path) > 0:
|
||||||
raise CollectionNotFound()
|
raise CollectionNotFound()
|
||||||
|
|
@ -76,6 +58,15 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
|
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
|
||||||
yield radio
|
yield radio
|
||||||
|
|
||||||
|
def get_current(self, radio):
|
||||||
|
document = self.browser.location('http://rock.ouifm.fr/dynamic-menu.json')
|
||||||
|
suffix = ''
|
||||||
|
if radio != 'general':
|
||||||
|
suffix = '_%s' % radio
|
||||||
|
|
||||||
|
last = document['last%s' % suffix][0]
|
||||||
|
return last['artiste%s' % suffix].strip(), last['titre%s' % suffix].strip()
|
||||||
|
|
||||||
def get_radio(self, radio):
|
def get_radio(self, radio):
|
||||||
if not isinstance(radio, Radio):
|
if not isinstance(radio, Radio):
|
||||||
radio = Radio(radio)
|
radio = Radio(radio)
|
||||||
|
|
@ -87,7 +78,7 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
radio.title = title
|
radio.title = title
|
||||||
radio.description = description
|
radio.description = description
|
||||||
|
|
||||||
artist, title = self.browser.get_current(radio.id)
|
artist, title = self.get_current(radio.id)
|
||||||
current = Emission(0)
|
current = Emission(0)
|
||||||
current.artist = artist
|
current.artist = artist
|
||||||
current.title = title
|
current.title = title
|
||||||
|
|
@ -103,7 +94,7 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
if 'current' in fields:
|
if 'current' in fields:
|
||||||
if not radio.current:
|
if not radio.current:
|
||||||
radio.current = Emission(0)
|
radio.current = Emission(0)
|
||||||
radio.current.artist, radio.current.title = self.browser.get_current(radio.id)
|
radio.current.artist, radio.current.title = self.get_current(radio.id)
|
||||||
return radio
|
return radio
|
||||||
|
|
||||||
OBJECTS = {Radio: fill_radio}
|
OBJECTS = {Radio: fill_radio}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue