Commit 965da256 authored by Roger Philibert's avatar Roger Philibert Committed by Romain Bignon

add module jacquieetmichel

parent 7d6fea2d
......@@ -40,7 +40,7 @@ Christophe Benz <christophe.benz@gmail.com>
* Bouygues, INA, SFR and Youtube modules maintainer.
Roger Philibert <roger.philibert@gmail.com>
* Ehentai, Izneo, OKC and Youjizz modules maintainer.
* Ehentai, Izneo, JacquieEtMichel, OKC and Youjizz modules maintainer.
Nicolas Duhamel <nicolas@jombi.fr>
* BP, CanalPlus and Orange modules maintainer.
......
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Romain Bignon
#
# 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 .backend import JacquieEtMichelBackend
__all__ = ['JacquieEtMichelBackend']
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Roger Philibert
#
# 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.video import ICapVideo, BaseVideo
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
from weboob.tools.backend import BaseBackend
from .browser import JacquieEtMichelBrowser
from .video import JacquieEtMichelVideo
__all__ = ['JacquieEtMichelBackend']
class JacquieEtMichelBackend(BaseBackend, ICapVideo, ICapCollection):
NAME = 'jacquieetmichel'
MAINTAINER = u'Roger Philibert'
EMAIL = 'roger.philibert@gmail.com'
VERSION = '0.h'
DESCRIPTION = 'Jacquie et Michel TV'
LICENSE = 'AGPLv3+'
BROWSER = JacquieEtMichelBrowser
def get_video(self, _id):
with self.browser:
video = self.browser.get_video(_id)
return video
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False):
if not nsfw:
return iter([])
with self.browser:
return self.browser.search_videos(pattern)
def fill_video(self, video, fields):
if fields != ['thumbnail']:
# if we don't want only the thumbnail, we probably want also every fields
with self.browser:
video = self.browser.get_video(JacquieEtMichelVideo.id2url(video.id), video)
if 'thumbnail' in fields and video.thumbnail:
with self.browser:
video.thumbnail.data = self.browser.readurl(video.thumbnail.url)
return video
def iter_resources(self, objs, split_path):
if BaseVideo in objs:
collection = self.get_collection(objs, split_path)
if collection.path_level == 0:
yield self.get_collection(objs, [u'latest_nsfw'])
if collection.split_path == [u'latest_nsfw']:
for video in self.browser.latest_videos():
yield video
def validate_collection(self, objs, collection):
if collection.path_level == 0:
return
if BaseVideo in objs and collection.split_path == [u'latest_nsfw']:
collection.title = u'Latest Jacquie & Michel videos (NSFW)'
return
raise CollectionNotFound(collection.split_path)
OBJECTS = {JacquieEtMichelVideo: fill_video}
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Roger Philibert
#
# 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/>.
import urllib
from weboob.tools.browser import BaseBrowser
from weboob.tools.browser.decorators import id2url
from .video import JacquieEtMichelVideo
from .pages import VideoPage, ResultsPage
__all__ = ['JacquieEtMichelBrowser']
class JacquieEtMichelBrowser(BaseBrowser):
DOMAIN = u'jacquieetmicheltv.net'
ENCODING = None
PAGES = {r'https?://.*jacquieetmicheltv.net/': ResultsPage,
r'https?://.*jacquieetmicheltv.net/videolist/.*': ResultsPage,
r'https?://.*jacquieetmicheltv.net/showvideo/(?P<id>\d+)/.*': VideoPage,
}
@id2url(JacquieEtMichelVideo.id2url)
def get_video(self, url, video=None):
self.location(url)
assert self.is_on_page(VideoPage), 'Should be on video page.'
return self.page.get_video(video)
def search_videos(self, pattern):
self.location('/videolist/searchmodevideo/query%s/' % (urllib.quote(pattern.encode('utf-8'))))
assert self.is_on_page(ResultsPage)
return self.page.iter_videos()
def latest_videos(self):
self.home()
assert self.is_on_page(ResultsPage)
return self.page.iter_videos()
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Roger Philibert
#
# 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/>.
import re
from weboob.capabilities.base import NotAvailable
from weboob.tools.capabilities.thumbnail import Thumbnail
from weboob.tools.browser import BasePage, BrokenPageError
from weboob.tools.misc import to_unicode
from .video import JacquieEtMichelVideo
__all__ = ['ResultsPage', 'VideoPage']
class ResultsPage(BasePage):
def iter_videos(self):
for span in self.document.xpath('//ul[@id="list"]/li'):
a = self.parser.select(span, 'a', 1)
url = a.attrib['href']
_id = re.sub(r'/showvideo/(\d+)/.*', r'\1', url)
video = JacquieEtMichelVideo(_id)
video.thumbnail = Thumbnail(unicode(span.find('.//img').attrib['src']))
title_el = self.parser.select(span, 'h2', 1)
video.title = to_unicode(title_el.text.strip())
video.description = self.parser.tocleanstring(span.xpath('.//div[@class="desc"]')[0])
video.set_empty_fields(NotAvailable, ('url,'))
yield video
class VideoPage(BasePage):
def get_video(self, video=None):
_id = to_unicode(self.group_dict['id'])
if video is None:
video = JacquieEtMichelVideo(_id)
title_el = self.parser.select(self.document.getroot(), 'h1', 1)
video.title = to_unicode(title_el.text.strip())
video.description = self.document.xpath('//meta[@name="description"]')[0].attrib['content']
for script in self.document.xpath('.//script'):
if script.text is None:
continue
m = re.search('"(http://[^"]+.mp4)"', script.text, re.MULTILINE)
if m:
video.url = to_unicode(m.group(1))
break
if not video.url:
raise BrokenPageError('Unable to find URL')
video.set_empty_fields(NotAvailable)
return video
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Roger Philibert
#
# 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
from weboob.capabilities.video import BaseVideo
class JacquieEtMichelTest(BackendTest):
BACKEND = 'jacquieetmichel'
def test_search(self):
self.assertTrue(len(list(self.backend.search_videos('anus', nsfw=False))) == 0)
l = list(self.backend.search_videos('anus', nsfw=True))
self.assertTrue(len(l) > 0)
v = l[0]
self.backend.fillobj(v, ('url',))
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
self.backend.browser.openurl(v.url)
def test_latest(self):
l = list(self.backend.iter_resources([BaseVideo], [u'latest_nsfw']))
self.assertTrue(len(l) > 0)
v = l[0]
self.backend.fillobj(v, ('url',))
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Roger Philibert
#
# 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.video import BaseVideo
__all__ = ['JacquieEtMichelVideo']
class JacquieEtMichelVideo(BaseVideo):
def __init__(self, *args, **kwargs):
BaseVideo.__init__(self, *args, **kwargs)
self.ext = u'mp4'
self.nsfw = True
@classmethod
def id2url(cls, _id):
return 'http://jacquieetmicheltv.net/showvideo/%s/t/' % _id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment