Create Radioob Module for Nectarine Demoscene Music
Signed-off-by: Thomas Lecavelier <thomas-weboob@lecavelier.name>
This commit is contained in:
parent
5143cafa02
commit
3510bdb215
6 changed files with 193 additions and 0 deletions
3
modules/nectarine/__init__.py
Normal file
3
modules/nectarine/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from .backend import NectarineBackend
|
||||||
|
|
||||||
|
__all__ = ['NectarineBackend']
|
||||||
58
modules/nectarine/backend.py
Normal file
58
modules/nectarine/backend.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright(C) 2013 Thomas Lecavelier
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# 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.capabilities.radio import ICapRadio, Radio
|
||||||
|
from weboob.capabilities.collection import ICapCollection
|
||||||
|
from weboob.tools.backend import BaseBackend
|
||||||
|
from .browser import NectarineBrowser
|
||||||
|
|
||||||
|
__all__ = ['NectarineBackend']
|
||||||
|
|
||||||
|
class NectarineBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
|
NAME = 'nectarine'
|
||||||
|
MAINTAINER = u'Thomas Lecavelier'
|
||||||
|
EMAIL = 'thomas-weboob@lecavelier.name'
|
||||||
|
VERSION = '0.h'
|
||||||
|
DESCRIPTION = u'Nectarine Demoscene Radio'
|
||||||
|
# License of your module
|
||||||
|
LICENSE = 'AGPLv3+'
|
||||||
|
|
||||||
|
BROWSER = NectarineBrowser
|
||||||
|
|
||||||
|
def iter_resources(self, objs, split_path):
|
||||||
|
if Radio in objs:
|
||||||
|
self._restrict_level(split_path)
|
||||||
|
for radio in self.browser.iter_radios_list():
|
||||||
|
self.browser.get_current_emission()
|
||||||
|
radio.current = self.browser.get_current_emission()
|
||||||
|
yield radio
|
||||||
|
|
||||||
|
def iter_radios_search(self, pattern):
|
||||||
|
for radio in self.browser.iter_radios_list():
|
||||||
|
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
|
||||||
|
self.browser.get_current_emission()
|
||||||
|
radio.current = self.browser.get_current_emission()
|
||||||
|
|
||||||
|
yield radio
|
||||||
|
|
||||||
|
def get_radio(self, radio):
|
||||||
|
if not isinstance(radio, Radio):
|
||||||
|
for rad in self.browser.iter_radios_list():
|
||||||
|
if rad.id == radio:
|
||||||
|
return rad
|
||||||
|
return None
|
||||||
49
modules/nectarine/browser.py
Normal file
49
modules/nectarine/browser.py
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
# * -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Thomas Lecavelier
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
from .pages import LivePage, StreamsPage
|
||||||
|
|
||||||
|
__all__ = ['NectarineBrowser']
|
||||||
|
|
||||||
|
class NectarineBrowser(BaseBrowser):
|
||||||
|
DOMAIN = 'www.scenemusic.net'
|
||||||
|
PROTOCOL = 'https'
|
||||||
|
ENCODING = 'utf-8'
|
||||||
|
USER_AGENT = BaseBrowser.USER_AGENTS['desktop_firefox']
|
||||||
|
PAGES = {
|
||||||
|
'https://www\.scenemusic\.net/demovibes/xml/streams/': StreamsPage,
|
||||||
|
'https://www\.scenemusic\.net/demovibes/xml/queue/': LivePage
|
||||||
|
}
|
||||||
|
|
||||||
|
def home(self):
|
||||||
|
self.location('/demovibes/xml/streams/')
|
||||||
|
|
||||||
|
assert self.is_on_page(StreamsPage)
|
||||||
|
|
||||||
|
def iter_radios_list(self):
|
||||||
|
self.location('/demovibes/xml/streams/')
|
||||||
|
|
||||||
|
assert self.is_on_page(StreamsPage)
|
||||||
|
return self.page.iter_radios_list()
|
||||||
|
|
||||||
|
def get_current_emission(self):
|
||||||
|
self.location('/demovibes/xml/queue/')
|
||||||
|
assert self.is_on_page(LivePage)
|
||||||
|
return self.page.get_current_emission()
|
||||||
BIN
modules/nectarine/favicon.png
Normal file
BIN
modules/nectarine/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
54
modules/nectarine/pages.py
Normal file
54
modules/nectarine/pages.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# * -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Thomas Lecavelier
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# 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 BasePage
|
||||||
|
from weboob.capabilities.radio import Radio, Stream, Emission
|
||||||
|
|
||||||
|
__all__ = ['LivePage', 'StreamsPage']
|
||||||
|
|
||||||
|
class StreamsPage(BasePage):
|
||||||
|
def iter_radios_list(self):
|
||||||
|
radio = Radio('necta')
|
||||||
|
radio.title = u'Nectarine'
|
||||||
|
radio.description = u'Nectarine Demoscene Radio'
|
||||||
|
radio.streams = []
|
||||||
|
|
||||||
|
index = -1
|
||||||
|
|
||||||
|
for el in self.document.xpath('//stream'):
|
||||||
|
index += 1
|
||||||
|
stream_url = unicode(el.findtext('url'))
|
||||||
|
bitrate = unicode(el.findtext('bitrate'))
|
||||||
|
encode = unicode(el.findtext('type'))
|
||||||
|
country = unicode(el.findtext('country')).upper()
|
||||||
|
stream = Stream(index)
|
||||||
|
stream.title = ' '.join([radio.title, country, encode, bitrate, 'kbps'])
|
||||||
|
stream.url = stream_url
|
||||||
|
radio.streams.append(stream)
|
||||||
|
|
||||||
|
yield radio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class LivePage(BasePage):
|
||||||
|
def get_current_emission(self):
|
||||||
|
current = Emission(0)
|
||||||
|
current.artist = unicode(self.document.xpath('//playlist/now/entry/artist')[0].text)
|
||||||
|
current.title = unicode(self.document.xpath('//playlist/now/entry/song')[0].text)
|
||||||
|
return current
|
||||||
29
modules/nectarine/test.py
Normal file
29
modules/nectarine/test.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2013 Thomas Lecavelier
|
||||||
|
#
|
||||||
|
# This file is part of weboob.
|
||||||
|
#
|
||||||
|
# weboob is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# weboob is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# 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.test import BackendTest
|
||||||
|
|
||||||
|
|
||||||
|
class NectarineTest(BackendTest):
|
||||||
|
BACKEND = 'nectarine'
|
||||||
|
|
||||||
|
def test_nectarine(self):
|
||||||
|
l = list(self.backend.iter_radios_search(''))
|
||||||
|
self.assertTrue(len(l) > 0)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue