diff --git a/modules/canalplus/browser.py b/modules/canalplus/browser.py index 43a315cc..be36f1c5 100644 --- a/modules/canalplus/browser.py +++ b/modules/canalplus/browser.py @@ -25,7 +25,7 @@ import lxml.etree from weboob.tools.browser import BaseBrowser from weboob.tools.browser.decorators import id2url -from .pages import InitPage, VideoPage +from .pages import ChannelsPage, VideoPage from .video import CanalplusVideo from weboob.capabilities.collection import CollectionNotFound @@ -46,7 +46,7 @@ class CanalplusBrowser(BaseBrowser): DOMAIN = u'service.canal-plus.com' ENCODING = 'utf-8' PAGES = { - r'http://service.canal-plus.com/video/rest/initPlayer/cplus/': InitPage, + r'http://service.canal-plus.com/video/rest/initPlayer/cplus/': ChannelsPage, r'http://service.canal-plus.com/video/rest/search/cplus/.*': VideoPage, r'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/(?P.+)': VideoPage, r'http://service.canal-plus.com/video/rest/getMEAs/cplus/.*': VideoPage, @@ -76,7 +76,7 @@ class CanalplusBrowser(BaseBrowser): return self.page.get_video(video, self.quality) def iter_resources(self, split_path): - if not self.is_on_page(InitPage): + if not self.is_on_page(ChannelsPage): self.home() channels = self.page.get_channels() diff --git a/modules/canalplus/pages/videopage.py b/modules/canalplus/pages.py similarity index 75% rename from modules/canalplus/pages/videopage.py rename to modules/canalplus/pages.py index 9e04cb8d..633abb0c 100644 --- a/modules/canalplus/pages/videopage.py +++ b/modules/canalplus/pages.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Nicolas Duhamel +# Copyright(C) 2010-2012 Nicolas Duhamel, Laurent Bachelier # # This file is part of weboob. # @@ -17,16 +17,36 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . - from datetime import datetime +from weboob.tools.browser import BasePage +from weboob.capabilities.collection import Collection from weboob.capabilities.base import NotAvailable from weboob.tools.capabilities.thumbnail import Thumbnail -from weboob.tools.browser import BasePage -from ..video import CanalplusVideo + +from .video import CanalplusVideo + +__all__ = ['ChannelsPage', 'VideoPage'] -__all__ = ['VideoPage'] +class ChannelsPage(BasePage): + def get_channels(self): + """ + Extract all possible channels (paths) from the page + """ + channels = list() + for elem in self.document[2].getchildren(): + for e in elem.getchildren(): + if e.tag == "NOM": + name = unicode(e.text.strip()) + channels.append(Collection([name])) + elif e.tag == "SELECTIONS": + for select in e: + subname = unicode(select[1].text.strip()) + sub = Collection([name, subname]) + sub._link_id = select[0].text + channels.append(sub) + return channels class VideoPage(BasePage): @@ -80,14 +100,13 @@ class VideoPage(BasePage): for vid in self.document.getchildren(): yield self.parse_video_channel(vid) - def parse_video_channel(self,el): + def parse_video_channel(self, el): _id = el[0].text video = CanalplusVideo(_id) video.title = el[2][3][0].text video.date = datetime.now() return video - def get_video(self, video, quality): _id = self.group_dict['id'] for vid in self.document.getchildren(): diff --git a/modules/canalplus/pages/__init__.py b/modules/canalplus/pages/__init__.py deleted file mode 100644 index 1f5ee4cb..00000000 --- a/modules/canalplus/pages/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2010-2011 Nicolas Duhamel -# -# 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 .initpage import InitPage -from .videopage import VideoPage - -__all__ = ['InitPage', 'VideoPage'] diff --git a/modules/canalplus/pages/initpage.py b/modules/canalplus/pages/initpage.py deleted file mode 100644 index c4f4daee..00000000 --- a/modules/canalplus/pages/initpage.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2010-2012 Nicolas Duhamel, Laurent Bachelier -# -# 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 BasePage - -from weboob.capabilities.collection import Collection - -__all__ = ['InitPage'] - - -class InitPage(BasePage): - def get_channels(self): - """ - Extract all possible channels (paths) from the page - """ - channels = list() - for elem in self.document[2].getchildren(): - for e in elem.getchildren(): - if e.tag == "NOM": - name = unicode(e.text.strip()) - channels.append(Collection([name])) - elif e.tag == "SELECTIONS": - for select in e: - subname = unicode(select[1].text.strip()) - sub = Collection([name, subname]) - sub._link_id = select[0].text - channels.append(sub) - return channels