fill all available fields

This commit is contained in:
Romain Bignon 2010-11-09 23:27:00 +01:00
commit 08297f5f0b
5 changed files with 71 additions and 61 deletions

View file

@ -32,7 +32,7 @@ class CanalplusBackend(BaseBackend, ICapVideo):
NAME = 'canalplus' NAME = 'canalplus'
MAINTAINER = 'Nicolas Duhamel' MAINTAINER = 'Nicolas Duhamel'
EMAIL = 'nicolas@jombi.fr' EMAIL = 'nicolas@jombi.fr'
VERSION = '0.1' VERSION = '0.4'
DESCRIPTION = 'Canal plus french TV' DESCRIPTION = 'Canal plus french TV'
LICENSE = 'GPLv3' LICENSE = 'GPLv3'
CONFIG = ValuesDict(Value('quality', label='Quality of videos', choices=['hd', 'sd'], default='hd')) CONFIG = ValuesDict(Value('quality', label='Quality of videos', choices=['hd', 'sd'], default='hd'))
@ -50,7 +50,14 @@ class CanalplusBackend(BaseBackend, ICapVideo):
return self.browser.get_video(_id) return self.browser.get_video(_id)
def fill_video(self, video, fields): def fill_video(self, video, fields):
with self.browser: if fields != ['thumbnail']:
return self.browser.get_video(CanalplusVideo.id2url(video.id), video) # if we don't want only the thumbnail, we probably want also every fields
with self.browser:
video = self.browser.get_video(CanalplusVideo.id2url(video.id), video)
if 'thumbnail' in fields:
with self.browser:
video.thumbnail.data = self.browser.readurl(video.thumbnail.url)
return video
OBJECTS = {CanalplusVideo: fill_video} OBJECTS = {CanalplusVideo: fill_video}

View file

@ -20,7 +20,7 @@ import urllib
from weboob.tools.browser import BaseBrowser from weboob.tools.browser import BaseBrowser
from weboob.tools.browser.decorators import id2url from weboob.tools.browser.decorators import id2url
from .pages import InitPage, SearchResultPage, CanalplusVideo, VideoPage from .pages import InitPage, CanalplusVideo, VideoPage
import lxml.etree import lxml.etree
@ -40,7 +40,7 @@ class CanalplusBrowser(BaseBrowser):
DOMAIN = u'service.canal-plus.com' DOMAIN = u'service.canal-plus.com'
ENCODING = 'utf-8' ENCODING = 'utf-8'
PAGES = {r"http://service.canal-plus.com/video/rest/initPlayer/cplus/": InitPage, PAGES = {r"http://service.canal-plus.com/video/rest/initPlayer/cplus/": InitPage,
r"http://service.canal-plus.com/video/rest/search/cplus/.*": SearchResultPage, r"http://service.canal-plus.com/video/rest/search/cplus/.*": VideoPage,
r"http://service.canal-plus.com/video/rest/getVideosLiees/cplus/(?P<id>.+)": VideoPage, r"http://service.canal-plus.com/video/rest/getVideosLiees/cplus/(?P<id>.+)": VideoPage,
} }
@ -49,24 +49,24 @@ class CanalplusBrowser(BaseBrowser):
FORMATS = { 'sd': 'BAS_DEBIT', FORMATS = { 'sd': 'BAS_DEBIT',
'hd': 'HD' 'hd': 'HD'
} }
def __init__(self, quality, *args, **kwargs): def __init__(self, quality, *args, **kwargs):
BaseBrowser.__init__(self, parser= self.PARSER, *args, **kwargs) BaseBrowser.__init__(self, parser= self.PARSER, *args, **kwargs)
if quality in self.FORMATS: if quality in self.FORMATS:
self.quality = self.FORMATS[quality] self.quality = self.FORMATS[quality]
else: else:
self.quality = 'HD' self.quality = 'HD'
def home(self): def home(self):
self.location("http://service.canal-plus.com/video/rest/initPlayer/cplus/") self.location("http://service.canal-plus.com/video/rest/initPlayer/cplus/")
def iter_search_results(self, pattern): def iter_search_results(self, pattern):
self.location("http://service.canal-plus.com/video/rest/search/cplus/" + urllib.quote_plus(pattern) ) self.location("http://service.canal-plus.com/video/rest/search/cplus/" + urllib.quote_plus(pattern))
return self.page.iter_results() return self.page.iter_results()
@id2url(CanalplusVideo.id2url) @id2url(CanalplusVideo.id2url)
def get_video(self, url, video=None): def get_video(self, url, video=None):
self.location(url) self.location(url)
return self.page.get_video(video, self.quality) return self.page.get_video(video, self.quality)

View file

@ -16,8 +16,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from .initpage import InitPage from .initpage import InitPage
from .searchresultpage import SearchResultPage
from .video import CanalplusVideo from .video import CanalplusVideo
from .videopage import VideoPage from .videopage import VideoPage
__all__ = ['InitPage', 'SearchResultPage', 'VideoPage', 'CanalplusVideo'] __all__ = ['InitPage', 'VideoPage', 'CanalplusVideo']

View file

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010 Nicolas Duhamel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.tools.browser import BasePage
from .video import CanalplusVideo
__all__ = ['SearchResultPage']
class SearchResultPage(BasePage):
def iter_results(self):
for vid in self.document.getchildren():
#id
_id = vid[0].text
#Titre
titre = vid[2][9][0].text
#Sous titre
titre = titre + " " + vid[2][9][1].text
yield CanalplusVideo(_id, title=titre)

View file

@ -15,26 +15,63 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from datetime import datetime
from weboob.capabilities.video import VideoThumbnail
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from .video import CanalplusVideo from .video import CanalplusVideo
__all__ = ['VideoPage'] __all__ = ['VideoPage']
class VideoPage(BasePage): class VideoPage(BasePage):
def on_loaded(self): def parse_video(self, el, video=None, quality=None):
pass _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')
video.thumbnail = VideoThumbnail(media.find('IMAGES').find('PETIT').text)
lastest_format = None
for format in media.find('VIDEOS'):
if format.text is None:
continue
if format.tag == quality:
video.url = format.text
break
lastest_format = format
if not video.url and lastest_format is not None:
video.url = lastest_format.text
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.document.getchildren():
yield self.parse_video(vid)
def get_video(self, video, quality): def get_video(self, video, quality):
if not video: _id = self.group_dict['id']
video = CanalplusVideo(self.group_dict['id'])
for vid in self.document.getchildren(): for vid in self.document.getchildren():
url = None if not _id in vid.find('ID').text:
lastest = None continue
for format in vid[5][1].getchildren(): return self.parse_video(vid, video, quality)
if format.tag == quality:
url = format.text
if format.text:
lastest = format
if url == None:
url = lastest.text
video.url = url
return video