From 3510bdb21516557455bec5ef460985bec20669fc Mon Sep 17 00:00:00 2001 From: Thomas Lecavelier Date: Wed, 14 Aug 2013 14:02:27 +0200 Subject: [PATCH] Create Radioob Module for Nectarine Demoscene Music Signed-off-by: Thomas Lecavelier --- modules/nectarine/__init__.py | 3 ++ modules/nectarine/backend.py | 58 ++++++++++++++++++++++++++++++++++ modules/nectarine/browser.py | 49 ++++++++++++++++++++++++++++ modules/nectarine/favicon.png | Bin 0 -> 1873 bytes modules/nectarine/pages.py | 54 +++++++++++++++++++++++++++++++ modules/nectarine/test.py | 29 +++++++++++++++++ 6 files changed, 193 insertions(+) create mode 100644 modules/nectarine/__init__.py create mode 100644 modules/nectarine/backend.py create mode 100644 modules/nectarine/browser.py create mode 100644 modules/nectarine/favicon.png create mode 100644 modules/nectarine/pages.py create mode 100644 modules/nectarine/test.py diff --git a/modules/nectarine/__init__.py b/modules/nectarine/__init__.py new file mode 100644 index 00000000..bfdb52b5 --- /dev/null +++ b/modules/nectarine/__init__.py @@ -0,0 +1,3 @@ +from .backend import NectarineBackend + +__all__ = ['NectarineBackend'] diff --git a/modules/nectarine/backend.py b/modules/nectarine/backend.py new file mode 100644 index 00000000..9261be72 --- /dev/null +++ b/modules/nectarine/backend.py @@ -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 . + +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 diff --git a/modules/nectarine/browser.py b/modules/nectarine/browser.py new file mode 100644 index 00000000..70cbec4f --- /dev/null +++ b/modules/nectarine/browser.py @@ -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 . + +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() diff --git a/modules/nectarine/favicon.png b/modules/nectarine/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..870086b52868f085ed7c5d531f977430bd3d7409 GIT binary patch literal 1873 zcmV-X2d?;uP)1=mqgopG0PRulc2TV-QefrJqU8Z0E|8u_YJEsb}kHg$(F5n#N zFuch**`|)iMO|tS$FzX%C(eEQ9MznaySJoze&NsQBRG4!#wDE90Bhvz+v5A1J%mHY z2Kh1Q1E37_gUl-|n{&vKae=dT!8{5QZ8mmr*8B93cQmd%g7Z37%Xw)q^cLsK&-NE_ z4!e!t;k~yEdd_Vjqlt62mMG)wIOO4%IV%p9a3_C*IkogY4G?-77fnI2ODk6(9rf z5G-Ij&J5sk1}*L?%bdk|<`_!_=hAsICUdq-d=k%zcbuk|d2fLeu>`#=5*L_cpA6Ia zE4{>qzL*(NnO7C$=6IKIdzPmDVsL z61;ehRa!t=U;qp3Dz}tyUiEnHG0x)`uY~Mf*|YJWZ!3?0H8m5Qk)8&&`s=~ZPw4|Y z9R1+h79-h2F@q;FJGdl^Ca>NgS->T5oipY{Ju+JN80Sp~oJgF$f4kHyEil*vU|=>I z^mLq6p!^Knh}Cc&JFWn-*K()g<}df6ie;-_-wvKSm9BBSQ7$mMon-vuAu1PIVrU4l z7q)Ey=jWrUW^Jw4!Sx4T15Yysz^aa{F*Z}5%lX0$wo&+M4<1AVi8-CfO;~Fi`l;;V#f#vRCr^UQ%F0q& zVBBb$H9`rYd`XSWtSW_^FV!~B6@DZwAT40n{qm(M(G~9cf-O08u=GJ1zx*$EqML<^(>XBP0pj>prG}5l0L+R zhLcXAzq3KFjgShE0T3*p*lZ9>&AK9$+AczK(hFy>5$U9@mP=oOn;Is9CzO4=cjSXN8ot|Y$1;_vh7O)@L zoX$U-ulN-ii4s+jc_af~vO^jrMP;K%THV!~!CfbjTQQ4?bQy3{BQz4A^OJ;Un(IF% z+1HWX5)opTUqd!_)2E@Glwn|4n~22eyNOE>jOp!C0WtuB1@c$y!xGZ<&xd0p#Db7< z9p^OR22CS98HEvem{2-2U2UO}c@$RIShh7noJZW>OV6}B=z7gd4bn6ngAcvo1U6}m z%2y%jTlOf;6oTx7(FE?zEKEOxF4H&n9xE*{$U8#fhePkpnS{+pMVZD&FH#QXa3Ykz(IBw&- zt=6+sDnJHc01Jr67b^?i<-8_OzZHp!NpD40M@YV>ujv({N{Lf6M$haM7K%O8&S(7* zAx#lxlOe+NW3>=py+S36dI{}+=IEvR<)$y*ig&3|tl`kLJ(<+-Y-pl;ueVZSV+he~GTcBbzZN4&T4>&|kg%;TAZ+;= znoq0AK_7W$nK2(+XYa?l#=2izN2LN}03L7__*b5S>uOi$HFG|#`Nv^)2$PJT$VNWG zrsUC3uB!ApO>mn|Ar1(e+rmOgYcP`3eL|vtrZdpRd8XBjFHw@CF2-!~N!vxK02zS$ zm<1{}6k(X|C~8M-X|pkC?#wee(6=?qh)v7xXaaWVi?B@?;SCJy3r4+Q0il!@yEj3h zT<{28Ab%{`fOiFxSZ}jf-1|ANo;?CSX?Di&$8B;YkVd_6*xe-+AOmn8v%ouxvLKt? zHD3RNJak_P!)V-Y$c8m6rX+S+7<4-H=MyZcQC*<4QY{_Fe~sBr&~8tu02zS)I1&24 z9LeL. + +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 diff --git a/modules/nectarine/test.py b/modules/nectarine/test.py new file mode 100644 index 00000000..d095e9f4 --- /dev/null +++ b/modules/nectarine/test.py @@ -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 . + + +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)