[weboob] [PATCH 1/1] Create Radioob Module for Nectarine Demoscene Music

Thomas Lecavelier thomas at lecavelier.name
Wed Aug 14 14:02:27 CEST 2013


From: Thomas Lecavelier <thomas-weboob at lecavelier.name>


Signed-off-by: Thomas Lecavelier <thomas-weboob at lecavelier.name>
---
 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 0000000..bfdb52b
--- /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 0000000..9261be7
--- /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 <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 at 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 0000000..70cbec4
--- /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 <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()
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)<h;3K|Lk000e1NJLTq002M$002M;1^@s6s%dfF0000PbVXQnQ*UN;
zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU&^GQTORCwC#n^|mBRT#(5otZn+X`w?q
zrL~koG3<*4DnbKNDj*Pu3yaYZM1r8kgeW{nMB~7N2`)j6BtnQ5A1V=JRidF<%3h(d
z*s!*=&=%U6GSgYx>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)wIOO<CDnJI{AzNT*ecA at dzFp1ZT-0bf$a!Z=kDK#t
zZ`MZ6dAa5f at Sx!txVI at 0$LYC`(u6R>4%IV%p9a3_C*IkogY4G?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
z+1HWX5)opTUqd!_)2E at Glwn|4n~22eyNOE>jOp!C0WtuB1 at c$y!xGZ<&xd0p#Db7<
z9p^OR22CS98HEvem{2-2U2UO}c@$RIShh7noJZW>OV6}B=z7gd4bn6ngAcvo1U6}m
z%2y%jTlOf;6oTx7(FE?zEKEOxF4H&n9xE*{$U8#fhePkpnS{<s%k8V2OAAdDF;$mx
zbajzhS;0bDm^CTg!W-hLzlB)F3g5`*qjz07n*p}op>+pMVZD&FH#QXa3Ykz(IBw&-
zt=6+sDnJHc01Jr67b^?i<-8_OzZHp!NpD40M at YV>ujv({N{Lf6M$haM7K%O8&S(7*
zAx#lxlOe+NW3>=py+S36dI{}+=IEvR<)$y*ig&3|tl`<J10JaW834focPm9&9ad6r
zkoanG4lFP~--JCmd2>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 at 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<zg5Z^itppX|2`~OKy9gewU4xbOoWn282}jo8Gyli{3E~so?L|Il#J*b00000
LNkvXXu0mjf#SnQr

literal 0
HcmV?d00001

diff --git a/modules/nectarine/pages.py b/modules/nectarine/pages.py
new file mode 100644
index 0000000..43f0c0d
--- /dev/null
+++ b/modules/nectarine/pages.py
@@ -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
diff --git a/modules/nectarine/test.py b/modules/nectarine/test.py
new file mode 100644
index 0000000..d095e9f
--- /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 <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)
-- 
1.7.10.2 (Apple Git-33)



More information about the weboob mailing list