new backend CanalPlus
This commit is contained in:
parent
26d69cd0f8
commit
47432020a3
8 changed files with 313 additions and 0 deletions
20
weboob/backends/canalplus/__init__.py
Normal file
20
weboob/backends/canalplus/__init__.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2010 Romain Bignon
|
||||||
|
#
|
||||||
|
# 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 .backend import CanalplusBackend
|
||||||
|
|
||||||
|
__all__ = ['CanalplusBackend']
|
||||||
55
weboob/backends/canalplus/backend.py
Normal file
55
weboob/backends/canalplus/backend.py
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
# -*- 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 __future__ import with_statement
|
||||||
|
|
||||||
|
from weboob.capabilities.video import ICapVideo
|
||||||
|
from weboob.tools.backend import BaseBackend
|
||||||
|
from weboob.tools.value import ValuesDict, Value
|
||||||
|
|
||||||
|
from .browser import CanalplusBrowser
|
||||||
|
from .pages import CanalplusVideo
|
||||||
|
|
||||||
|
__all__ = ['CanalplusBackend']
|
||||||
|
|
||||||
|
|
||||||
|
class CanalplusBackend(BaseBackend, ICapVideo):
|
||||||
|
NAME = 'canalplus'
|
||||||
|
MAINTAINER = 'Nicolas Duhamel'
|
||||||
|
EMAIL = 'nicolas@jombi.fr'
|
||||||
|
VERSION = '0.1'
|
||||||
|
DESCRIPTION = 'Canal plus french TV'
|
||||||
|
LICENSE = 'GPLv3'
|
||||||
|
CONFIG = ValuesDict(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'])
|
||||||
|
|
||||||
|
def iter_search_results(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
|
with self.browser:
|
||||||
|
return self.browser.iter_search_results(pattern)
|
||||||
|
|
||||||
|
def get_video(self, _id):
|
||||||
|
with self.browser:
|
||||||
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
|
def fill_video(self, video, fields):
|
||||||
|
return self.browser.get_video(CanalplusVideo.id2url(video.id))
|
||||||
|
|
||||||
|
OBJECTS = {CanalplusVideo: fill_video}
|
||||||
72
weboob/backends/canalplus/browser.py
Normal file
72
weboob/backends/canalplus/browser.py
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
# -*- 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.
|
||||||
|
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
from weboob.tools.browser import BaseBrowser
|
||||||
|
from weboob.tools.browser.decorators import id2url
|
||||||
|
|
||||||
|
from .pages import InitPage, SearchResultPage, CanalplusVideo, VideoPage
|
||||||
|
|
||||||
|
import lxml.etree
|
||||||
|
|
||||||
|
class XMLParser:
|
||||||
|
def parse(self, data, encoding=None):
|
||||||
|
if encoding is None:
|
||||||
|
parser = None
|
||||||
|
else:
|
||||||
|
parser = lxml.etree.XMLParser(encoding=encoding, strip_cdata=False)
|
||||||
|
return lxml.etree.XML(data.get_data(), parser)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['CanalplusBrowser']
|
||||||
|
|
||||||
|
|
||||||
|
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/search/cplus/.*": SearchResultPage,
|
||||||
|
r"http://service.canal-plus.com/video/rest/getVideosLiees/cplus/(?P<id>.+)": VideoPage,
|
||||||
|
}
|
||||||
|
|
||||||
|
#We need lxml.etree.XMLParser for read CDATA
|
||||||
|
PARSER = XMLParser()
|
||||||
|
FORMATS = { 'sd': 'BAS_DEBIT',
|
||||||
|
'hd': 'HD'
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, quality, *args, **kwargs):
|
||||||
|
BaseBrowser.__init__(self, parser= self.PARSER, *args, **kwargs)
|
||||||
|
if quality in self.FORMATS:
|
||||||
|
self.quality = self.FORMATS[quality]
|
||||||
|
else:
|
||||||
|
self.quality = 'HD'
|
||||||
|
|
||||||
|
def home(self):
|
||||||
|
self.location("http://service.canal-plus.com/video/rest/initPlayer/cplus/")
|
||||||
|
|
||||||
|
def iter_search_results(self, pattern):
|
||||||
|
self.location("http://service.canal-plus.com/video/rest/search/cplus/" + urllib.quote_plus(pattern) )
|
||||||
|
return self.page.iter_results()
|
||||||
|
|
||||||
|
@id2url(CanalplusVideo.id2url)
|
||||||
|
def get_video(self, url, video=None):
|
||||||
|
self.location(url)
|
||||||
|
return self.page.get_video(video, self.quality)
|
||||||
|
|
||||||
|
|
||||||
23
weboob/backends/canalplus/pages/__init__.py
Normal file
23
weboob/backends/canalplus/pages/__init__.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- 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 .initpage import InitPage
|
||||||
|
from .searchresultpage import SearchResultPage
|
||||||
|
from .video import CanalplusVideo
|
||||||
|
from .videopage import VideoPage
|
||||||
|
|
||||||
|
__all__ = ['InitPage', 'SearchResultPage', 'VideoPage', 'CanalplusVideo']
|
||||||
40
weboob/backends/canalplus/pages/initpage.py
Normal file
40
weboob/backends/canalplus/pages/initpage.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
# -*- 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
|
||||||
|
|
||||||
|
__all__ = ['InitPage']
|
||||||
|
|
||||||
|
class InitPage(BasePage):
|
||||||
|
def on_loaded(self):
|
||||||
|
channels = []
|
||||||
|
### Parse liste des channels
|
||||||
|
for elem in self.document[2].getchildren():
|
||||||
|
channel = {}
|
||||||
|
for e in elem.getchildren():
|
||||||
|
subchannels = []
|
||||||
|
if e.tag == "NOM":
|
||||||
|
channel['nom'] = e.text
|
||||||
|
elif e.tag == "SELECTIONS":
|
||||||
|
|
||||||
|
for select in e:
|
||||||
|
subchannel = {}
|
||||||
|
subchannel['id'] = select[0].text
|
||||||
|
subchannel['nom'] = select[1].text
|
||||||
|
subchannels.append(subchannel)
|
||||||
|
channel['subchannels'] = subchannels
|
||||||
|
channels.append(channel)
|
||||||
33
weboob/backends/canalplus/pages/searchresultpage.py
Normal file
33
weboob/backends/canalplus/pages/searchresultpage.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- 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)
|
||||||
28
weboob/backends/canalplus/pages/video.py
Normal file
28
weboob/backends/canalplus/pages/video.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- 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.capabilities.video import BaseVideo
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['CanalplusVideo']
|
||||||
|
|
||||||
|
|
||||||
|
class CanalplusVideo(BaseVideo):
|
||||||
|
@classmethod
|
||||||
|
def id2url(cls, _id):
|
||||||
|
return 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s' % _id
|
||||||
42
weboob/backends/canalplus/pages/videopage.py
Normal file
42
weboob/backends/canalplus/pages/videopage.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# -*- 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__ = ['VideoPage']
|
||||||
|
|
||||||
|
class VideoPage(BasePage):
|
||||||
|
def on_loaded(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_video(self, video, quality):
|
||||||
|
if not video:
|
||||||
|
video = CanalplusVideo(self.group_dict['id'])
|
||||||
|
print quality
|
||||||
|
print video.id
|
||||||
|
for vid in self.document.getchildren():
|
||||||
|
url = None
|
||||||
|
lastest = None
|
||||||
|
for format in vid[5][1].getchildren():
|
||||||
|
if format.tag == quality:
|
||||||
|
url = format.text
|
||||||
|
if format.text:
|
||||||
|
lastest = format
|
||||||
|
if url == None:
|
||||||
|
url = lastest.text
|
||||||
|
video.url = url
|
||||||
|
return video
|
||||||
Loading…
Add table
Add a link
Reference in a new issue