pax_global_header 0000666 0000000 0000000 00000000064 13443176020 0014512 g ustar 00root root 0000000 0000000 52 comment=c700a2f631ad8d4c1cb61b0854d1e7079508e562
woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/ 0000775 0000000 0000000 00000000000 13443176020 0022734 5 ustar 00root root 0000000 0000000 woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/ 0000775 0000000 0000000 00000000000 13443176020 0024404 5 ustar 00root root 0000000 0000000 woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/ 0000775 0000000 0000000 00000000000 13443176020 0026366 5 ustar 00root root 0000000 0000000 woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/__init__.py 0000664 0000000 0000000 00000001521 13443176020 0030476 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Nicolas Duhamel
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob module 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 this weboob module. If not, see .
from .module import CanalplusModule
__all__ = ['CanalplusModule']
woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/browser.py 0000664 0000000 0000000 00000006703 13443176020 0030431 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2010-2012 Nicolas Duhamel, Laurent Bachelier
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob module 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 this weboob module. If not, see .
from weboob.browser import PagesBrowser, URL
from weboob.tools.compat import quote_plus
from .pages import ChannelsPage, VideoPage
from .video import CanalplusVideo
from weboob.capabilities.collection import CollectionNotFound
__all__ = ['CanalplusBrowser']
class CanalplusBrowser(PagesBrowser):
BASEURL = u'http://service.canal-plus.com'
channels = URL('/video/rest/initPlayer/cplus/', ChannelsPage)
videos = URL('/video/rest/search/cplus/.*',
'/video/rest/getVideosLiees/cplus/(?P.+)',
'/video/rest/getMEAs/cplus/.*', VideoPage)
FORMATS = {
'sd': 0,
'hd': -1,
}
def __init__(self, quality, *args, **kwargs):
super(CanalplusBrowser, self).__init__(*args, **kwargs)
self.quality = self.FORMATS.get(quality, self.FORMATS['hd'])
def home(self):
self.location('http://service.canal-plus.com/video/rest/initPlayer/cplus/')
def search_videos(self, pattern):
self.location('http://service.canal-plus.com/video/rest/search/cplus/' + quote_plus(pattern.replace('/', '').encode('utf-8')))
return self.page.iter_results()
def get_video(self, url, video=None):
if not url.startswith('http'):
url = CanalplusVideo.id2url(url)
self.location(url)
video = self.page.get_video(video)
video.url = u'%s' % self.read_url(video.url)[self.quality]
return video
def read_url(self, url):
buf = self.open(url).text.split('\n')
return [line for line in buf if not line.startswith('#')]
def iter_resources(self, split_path):
if not self.is_on_page(ChannelsPage):
self.home()
channels = self.page.get_channels()
if len(split_path) == 0:
for channel in channels:
if channel.path_level == 1:
yield channel
elif len(split_path) == 1:
for channel in channels:
if channel.path_level == 2 and split_path == channel.parent_path:
yield channel
elif len(split_path) == 2:
subchannels = self.iter_resources(split_path[0:1])
try:
channel = [subchannel for subchannel in subchannels
if split_path == subchannel.split_path][0]
self.location("http://service.canal-plus.com/video/rest/getMEAs/cplus/%s" % channel._link_id)
assert self.is_on_page(VideoPage)
for video in self.page.iter_channel():
yield video
except IndexError:
raise CollectionNotFound(split_path)
else:
raise CollectionNotFound(split_path)
woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/favicon.png 0000664 0000000 0000000 00000001214 13443176020 0030517 0 ustar 00root root 0000000 0000000 PNG
IHDR @ @ iq sRGB bKGD pHYs tIME
()t tEXtComment Created with GIMPW IDATx1@JA
)lDA/g>#R B$0o&c+Mf~*DDDDDDDDDI\@, !< y0u n+ IGw^/qw b1ά{I)%͇RJe 8^zkm#mO nyWZ~ DQp`)n }LZVaZAqsf35`<Ǐ7
?X J! u\.v?Fʡ:(RnZ-uj 5uhYX.6.P@5KweY0Pa²,ezN-@Gֳ\|>N&4^3͔R 9,n}G>O\\(p\ A4Me@u]W
c|K읾B IENDB` woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/module.py 0000664 0000000 0000000 00000004706 13443176020 0030234 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Nicolas Duhamel
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob module 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 this weboob module. If not, see .
import re
from weboob.capabilities.video import CapVideo, BaseVideo
from weboob.tools.backend import Module, BackendConfig
from weboob.tools.value import Value
from .browser import CanalplusBrowser
from .video import CanalplusVideo
from weboob.capabilities.collection import CapCollection
__all__ = ['CanalplusModule']
class CanalplusModule(Module, CapVideo, CapCollection):
NAME = 'canalplus'
MAINTAINER = u'Nicolas Duhamel'
EMAIL = 'nicolas@jombi.fr'
VERSION = '1.6'
DESCRIPTION = 'Canal Plus French TV'
LICENSE = 'AGPLv3+'
CONFIG = BackendConfig(Value('quality', label='Quality of videos', choices=['hd', 'sd'], default='hd'))
BROWSER = CanalplusBrowser
def create_default_browser(self):
return self.create_browser(quality=self.config['quality'].get())
def search_videos(self, pattern, sortby=CapVideo.SEARCH_RELEVANCE, nsfw=False):
return self.browser.search_videos(pattern)
def get_video(self, _id):
m = re.match('https?://www\.canal-?plus\.fr/.*\?vid=(\d+)', _id)
if m:
_id = m.group(1)
return self.browser.get_video(_id)
def fill_video(self, video, fields):
if fields != ['thumbnail']:
# if we don't want only the thumbnail, we probably want also every fields
video = self.browser.get_video(CanalplusVideo.id2url(video.id), video)
if 'thumbnail' in fields and video.thumbnail:
video.thumbnail.data = self.browser.open(video.thumbnail.url).content
return video
OBJECTS = {CanalplusVideo: fill_video}
def iter_resources(self, objs, split_path):
if BaseVideo in objs:
return self.browser.iter_resources(split_path)
woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/pages.py 0000664 0000000 0000000 00000010250 13443176020 0030035 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2010-2012 Nicolas Duhamel, Laurent Bachelier
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob module 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 this weboob module. If not, see .
from datetime import datetime
import re
from weboob.browser.pages import XMLPage
from weboob.capabilities.collection import Collection
from weboob.capabilities.base import NotAvailable, NotLoaded
from weboob.capabilities.image import Thumbnail
from .video import CanalplusVideo
class ChannelsPage(XMLPage):
ENCODING = 'utf-8'
def get_channels(self):
"""
Extract all possible channels (paths) from the page
"""
channels = list()
for elem in self.doc[2].getchildren():
for e in elem.getchildren():
if e.tag == "NOM":
fid, name = self._clean_name(e.text)
channels.append(Collection([fid], name))
elif e.tag == "SELECTIONS":
for select in e:
sub_fid, subname = self._clean_name(select[1].text)
sub = Collection([fid, sub_fid], subname)
sub._link_id = select[0].text
channels.append(sub)
return channels
def _clean_name(self, name):
name = name.strip()
if name == name.upper():
name = name.capitalize()
friendly_id = re.sub(r"['/_ \(\)\-\+]+", u'-', name).strip(u'-').lower()
return friendly_id, name
class VideoPage(XMLPage):
ENCODING = 'utf-8'
def parse_video(self, el, video=None):
_id = el.find('ID').text
if _id == '-1':
# means the video is not found
return None
if not video:
video = CanalplusVideo(_id)
infos = el.find('INFOS')
video.title = u''
for part in infos.find('TITRAGE'):
if len(part.text.strip()) == 0:
continue
if len(video.title) > 0:
video.title += u' — '
video.title += part.text.strip()
video.description = infos.find('DESCRIPTION').text
media = el.find('MEDIA')
url = media.find('IMAGES').find('PETIT').text
if url:
video.thumbnail = Thumbnail(url)
video.thumbnail.url = video.thumbnail.id
else:
video.thumbnail = NotAvailable
for format in media.find('VIDEOS'):
if format.text is None:
continue
if format.tag == 'HLS':
video.ext = u'm3u8'
video.url = format.text
break
day, month, year = map(int, infos.find('PUBLICATION').find('DATE').text.split('/'))
hour, minute, second = map(int, infos.find('PUBLICATION').find('HEURE').text.split(':'))
video.date = datetime(year, month, day, hour, minute, second)
return video
def iter_results(self):
for vid in self.doc.iter(tag='VIDEO'):
video = self.parse_video(vid)
video.url = NotLoaded
yield video
def iter_channel(self):
for vid in self.doc.iter(tag='VIDEO'):
yield self.parse_video_channel(vid)
def parse_video_channel(self, el):
_id = el[0].text
video = CanalplusVideo(_id)
video.title = u'%s' % el[2][5][0].text
video.date = datetime.now()
return video
def get_video(self, video):
_id = self.params.get('id')
for vid in self.doc.iter(tag='VIDEO'):
if _id not in vid.find('ID').text:
continue
return self.parse_video(vid, video)
woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/test.py 0000664 0000000 0000000 00000002732 13443176020 0027723 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob module 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 this weboob module. If not, see .
from weboob.tools.test import BackendTest
from weboob.capabilities.video import BaseVideo
class CanalPlusTest(BackendTest):
MODULE = 'canalplus'
def test_canalplus(self):
l = list(self.backend.search_videos(u'guignol'))
self.assertTrue(len(l) > 0)
v = l[0]
self.backend.fillobj(v, ('url',))
self.assertTrue(v.url and (v.url.startswith('rtmp://') or v.url.startswith('http://')), 'URL for video "%s" not found: %s' % (v.id, v.url))
def test_ls(self):
l = list(self.backend.iter_resources((BaseVideo, ), []))
self.assertTrue(len(l) > 0)
l = list(self.backend.iter_resources((BaseVideo, ), [u'sport']))
self.assertTrue(len(l) > 0)
woob-c700a2f631ad8d4c1cb61b0854d1e7079508e562-modules-canalplus/modules/canalplus/video.py 0000664 0000000 0000000 00000001775 13443176020 0030060 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Nicolas Duhamel
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob module 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 this weboob module. If not, see .
from weboob.capabilities.video import BaseVideo
class CanalplusVideo(BaseVideo):
swf_player = False
@classmethod
def id2url(cls, _id):
return 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s' % _id