Move the "empty search for latest" to collections
There is now a "latest" collection (or "latest_nsfw"). The feature didn't look much used, since it didn't work on many backends. Using collections will make it easy to support other things like most viewed, featured, etc. As a bonus, I added tests for every backend with the feature.
This commit is contained in:
parent
4d628112d5
commit
e958c229e6
32 changed files with 366 additions and 112 deletions
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
from weboob.tools.value import Value
|
from weboob.tools.value import Value
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ from .video import ArteVideo
|
||||||
__all__ = ['ArteBackend']
|
__all__ = ['ArteBackend']
|
||||||
|
|
||||||
|
|
||||||
class ArteBackend(BaseBackend, ICapVideo):
|
class ArteBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
NAME = 'arte'
|
NAME = 'arte'
|
||||||
MAINTAINER = 'Romain Bignon'
|
MAINTAINER = 'Romain Bignon'
|
||||||
EMAIL = 'romain@weboob.org'
|
EMAIL = 'romain@weboob.org'
|
||||||
|
|
@ -50,7 +51,7 @@ class ArteBackend(BaseBackend, ICapVideo):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.get_video(_id)
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern)
|
return self.browser.search_videos(pattern)
|
||||||
|
|
||||||
|
|
@ -65,4 +66,21 @@ class ArteBackend(BaseBackend, ICapVideo):
|
||||||
|
|
||||||
return video
|
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'])
|
||||||
|
if collection.split_path == [u'latest']:
|
||||||
|
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']:
|
||||||
|
collection.title = u'Latest Arte videos'
|
||||||
|
return
|
||||||
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {ArteVideo: fill_video}
|
OBJECTS = {ArteVideo: fill_video}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class ArteBrowser(BaseBrowser):
|
||||||
r'http://videos.arte.tv/\w+/videos/(?P<id>.+)\.html': VideoPage
|
r'http://videos.arte.tv/\w+/videos/(?P<id>.+)\.html': VideoPage
|
||||||
}
|
}
|
||||||
|
|
||||||
SEARCH_LANG = {'fr': 'recherche', 'de':'suche', 'en': 'search'}
|
SEARCH_LANG = {'fr': 'recherche', 'de': 'suche', 'en': 'search'}
|
||||||
|
|
||||||
def __init__(self, lang, quality, *args, **kwargs):
|
def __init__(self, lang, quality, *args, **kwargs):
|
||||||
BaseBrowser.__init__(self, *args, **kwargs)
|
BaseBrowser.__init__(self, *args, **kwargs)
|
||||||
|
|
@ -52,9 +52,11 @@ class ArteBrowser(BaseBrowser):
|
||||||
self.location('http://videos.arte.tv/fr/videos/toutesLesVideos')
|
self.location('http://videos.arte.tv/fr/videos/toutesLesVideos')
|
||||||
|
|
||||||
def search_videos(self, pattern):
|
def search_videos(self, pattern):
|
||||||
if not pattern:
|
self.location(self.buildurl('/%s/do_search/videos/%s' % (self.lang, self.SEARCH_LANG[self.lang]), q=pattern.encode('utf-8')))
|
||||||
self.home()
|
assert self.is_on_page(IndexPage)
|
||||||
else:
|
return self.page.iter_videos()
|
||||||
self.location(self.buildurl('/%s/do_search/videos/%s' % (self.lang, self.SEARCH_LANG[self.lang]), q=pattern.encode('utf-8')))
|
|
||||||
|
def latest_videos(self):
|
||||||
|
self.home()
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,22 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.test import BackendTest
|
from weboob.tools.test import BackendTest
|
||||||
|
from weboob.capabilities.video import BaseVideo
|
||||||
|
|
||||||
|
|
||||||
class ArteTest(BackendTest):
|
class ArteTest(BackendTest):
|
||||||
BACKEND = 'arte'
|
BACKEND = 'arte'
|
||||||
|
|
||||||
def test_arte(self):
|
def test_search(self):
|
||||||
l = list(self.backend.search_videos('arte'))
|
l = list(self.backend.search_videos('arte'))
|
||||||
if len(l) > 0:
|
if len(l) > 0:
|
||||||
v = l[0]
|
v = l[0]
|
||||||
self.backend.fillobj(v, ('url',))
|
self.backend.fillobj(v, ('url',))
|
||||||
self.assertTrue(v.url and v.url.startswith('rtmp://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
self.assertTrue(v.url and v.url.startswith('rtmp://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
||||||
|
|
||||||
|
def test_latest(self):
|
||||||
|
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
|
||||||
|
assert len(l)
|
||||||
|
v = l[0]
|
||||||
|
self.backend.fillobj(v, ('url',))
|
||||||
|
self.assertTrue(v.url and v.url.startswith('rtmp://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class CanalplusBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
def create_default_browser(self):
|
def create_default_browser(self):
|
||||||
return self.create_browser(quality=self.config['quality'].get())
|
return self.create_browser(quality=self.config['quality'].get())
|
||||||
|
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern)
|
return self.browser.search_videos(pattern)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend
|
from weboob.tools.backend import BaseBackend
|
||||||
from .browser import CappedBrowser, CappedVideo
|
from .browser import CappedBrowser, CappedVideo
|
||||||
|
|
||||||
|
|
@ -18,7 +19,7 @@ from .browser import CappedBrowser, CappedVideo
|
||||||
__all__ = ['CappedBackend']
|
__all__ = ['CappedBackend']
|
||||||
|
|
||||||
|
|
||||||
class CappedBackend(BaseBackend, ICapVideo):
|
class CappedBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
NAME = 'cappedtv'
|
NAME = 'cappedtv'
|
||||||
MAINTAINER = 'Lord'
|
MAINTAINER = 'Lord'
|
||||||
EMAIL = 'lord@lordtoniok.com'
|
EMAIL = 'lord@lordtoniok.com'
|
||||||
|
|
@ -31,7 +32,7 @@ class CappedBackend(BaseBackend, ICapVideo):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.get_video(_id)
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=None, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=None, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern)
|
return self.browser.search_videos(pattern)
|
||||||
|
|
||||||
|
|
@ -45,4 +46,21 @@ class CappedBackend(BaseBackend, ICapVideo):
|
||||||
|
|
||||||
return video
|
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'])
|
||||||
|
if collection.split_path == [u'latest']:
|
||||||
|
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']:
|
||||||
|
collection.title = u'Latest CappedTV videos'
|
||||||
|
return
|
||||||
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {CappedVideo: fill_video}
|
OBJECTS = {CappedVideo: fill_video}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ class IndexPage(BasePage):
|
||||||
seconds = parts[0]
|
seconds = parts[0]
|
||||||
elif len(parts) == 2:
|
elif len(parts) == 2:
|
||||||
hours = 0
|
hours = 0
|
||||||
minutes , seconds = parts
|
minutes, seconds = parts
|
||||||
elif len(parts) == 3:
|
elif len(parts) == 3:
|
||||||
hours, minutes, seconds = parts
|
hours, minutes, seconds = parts
|
||||||
else:
|
else:
|
||||||
|
|
@ -78,7 +78,6 @@ class IndexPage(BasePage):
|
||||||
yield video
|
yield video
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# parser for the video page
|
# parser for the video page
|
||||||
class VideoPage(BasePage):
|
class VideoPage(BasePage):
|
||||||
def get_video(self, video=None):
|
def get_video(self, video=None):
|
||||||
|
|
@ -118,10 +117,12 @@ class CappedBrowser(BaseBrowser):
|
||||||
assert self.is_on_page(VideoPage), 'Should be on video page.'
|
assert self.is_on_page(VideoPage), 'Should be on video page.'
|
||||||
return self.page.get_video(video)
|
return self.page.get_video(video)
|
||||||
|
|
||||||
def search_videos(self,pattern):
|
def search_videos(self, pattern):
|
||||||
if not pattern:
|
self.location('/search?s=%s' % (urllib.quote_plus(pattern.encode('utf-8'))))
|
||||||
self.home()
|
assert self.is_on_page(IndexPage)
|
||||||
else:
|
return self.page.iter_videos()
|
||||||
self.location('/search?s=%s' % (urllib.quote_plus(pattern.encode('utf-8'))))
|
|
||||||
|
def latest_videos(self):
|
||||||
|
self.home()
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,23 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.test import BackendTest
|
from weboob.tools.test import BackendTest
|
||||||
|
from weboob.capabilities.video import BaseVideo
|
||||||
|
|
||||||
__all__ = ['CappedTest']
|
|
||||||
|
|
||||||
|
|
||||||
class CappedTest(BackendTest):
|
class CappedTest(BackendTest):
|
||||||
BACKEND = 'cappedtv'
|
BACKEND = 'cappedtv'
|
||||||
|
|
||||||
def test_capped(self):
|
def test_search(self):
|
||||||
l = list(self.backend.search_videos('kewlers'))
|
l = list(self.backend.search_videos('kewlers'))
|
||||||
self.assertTrue(len(l) > 0)
|
self.assertTrue(len(l) > 0)
|
||||||
v = l[0]
|
v = l[0]
|
||||||
self.backend.fillobj(v, ('url',))
|
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.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)
|
self.backend.browser.openurl(v.url)
|
||||||
|
|
||||||
|
def test_latest(self):
|
||||||
|
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
|
||||||
|
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))
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend
|
from weboob.tools.backend import BaseBackend
|
||||||
|
|
||||||
from .browser import DailymotionBrowser
|
from .browser import DailymotionBrowser
|
||||||
|
|
@ -30,7 +31,7 @@ from .video import DailymotionVideo
|
||||||
__all__ = ['DailymotionBackend']
|
__all__ = ['DailymotionBackend']
|
||||||
|
|
||||||
|
|
||||||
class DailymotionBackend(BaseBackend, ICapVideo):
|
class DailymotionBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
NAME = 'dailymotion'
|
NAME = 'dailymotion'
|
||||||
MAINTAINER = 'Romain Bignon'
|
MAINTAINER = 'Romain Bignon'
|
||||||
EMAIL = 'romain@weboob.org'
|
EMAIL = 'romain@weboob.org'
|
||||||
|
|
@ -44,7 +45,7 @@ class DailymotionBackend(BaseBackend, ICapVideo):
|
||||||
return self.browser.get_video(_id)
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
SORTBY = ['relevance', 'rated', 'visited', None]
|
SORTBY = ['relevance', 'rated', 'visited', None]
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern, self.SORTBY[sortby])
|
return self.browser.search_videos(pattern, self.SORTBY[sortby])
|
||||||
|
|
||||||
|
|
@ -59,4 +60,21 @@ class DailymotionBackend(BaseBackend, ICapVideo):
|
||||||
|
|
||||||
return video
|
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'])
|
||||||
|
if collection.split_path == [u'latest']:
|
||||||
|
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']:
|
||||||
|
collection.title = u'Latest Dailymotion videos'
|
||||||
|
return
|
||||||
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {DailymotionVideo: fill_video}
|
OBJECTS = {DailymotionVideo: fill_video}
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,18 @@ class DailymotionBrowser(BaseBrowser):
|
||||||
self.location('/1')
|
self.location('/1')
|
||||||
|
|
||||||
def search_videos(self, pattern, sortby):
|
def search_videos(self, pattern, sortby):
|
||||||
if not pattern:
|
pattern = pattern.replace('/', '').encode('utf-8')
|
||||||
self.home()
|
if sortby is None:
|
||||||
|
url = '/search/%s/1' % quote_plus(pattern)
|
||||||
else:
|
else:
|
||||||
pattern = pattern.replace('/', '').encode('utf-8')
|
url = '/%s/search/%s/1' % (sortby, quote_plus(pattern))
|
||||||
if sortby is None:
|
self.location(url)
|
||||||
url = '/search/%s/1' % quote_plus(pattern)
|
|
||||||
else:
|
assert self.is_on_page(IndexPage)
|
||||||
url = '/%s/search/%s/1' % (sortby, quote_plus(pattern))
|
return self.page.iter_videos()
|
||||||
self.location(url)
|
|
||||||
|
def latest_videos(self):
|
||||||
|
self.home()
|
||||||
|
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,23 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.test import BackendTest
|
from weboob.tools.test import BackendTest
|
||||||
|
from weboob.capabilities.video import BaseVideo
|
||||||
|
|
||||||
|
|
||||||
class DailymotionTest(BackendTest):
|
class DailymotionTest(BackendTest):
|
||||||
BACKEND = 'dailymotion'
|
BACKEND = 'dailymotion'
|
||||||
|
|
||||||
def test_dailymotion(self):
|
def test_search(self):
|
||||||
l = list(self.backend.search_videos('chirac'))
|
l = list(self.backend.search_videos('chirac'))
|
||||||
self.assertTrue(len(l) > 0)
|
self.assertTrue(len(l) > 0)
|
||||||
v = l[0]
|
v = l[0]
|
||||||
self.backend.fillobj(v, ('url',))
|
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.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)
|
self.backend.browser.openurl(v.url)
|
||||||
|
|
||||||
|
def test_latest(self):
|
||||||
|
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
|
||||||
|
assert len(l)
|
||||||
|
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))
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from weboob.capabilities.gallery import ICapGallery
|
from weboob.capabilities.gallery import ICapGallery, BaseGallery
|
||||||
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
from weboob.tools.misc import ratelimit
|
from weboob.tools.misc import ratelimit
|
||||||
from weboob.tools.value import Value, ValueBackendPassword
|
from weboob.tools.value import Value, ValueBackendPassword
|
||||||
|
|
@ -32,7 +33,7 @@ from .gallery import EHentaiGallery, EHentaiImage
|
||||||
__all__ = ['EHentaiBackend']
|
__all__ = ['EHentaiBackend']
|
||||||
|
|
||||||
|
|
||||||
class EHentaiBackend(BaseBackend, ICapGallery):
|
class EHentaiBackend(BaseBackend, ICapGallery, ICapCollection):
|
||||||
NAME = 'ehentai'
|
NAME = 'ehentai'
|
||||||
MAINTAINER = 'Roger Philibert'
|
MAINTAINER = 'Roger Philibert'
|
||||||
EMAIL = 'roger.philibert@gmail.com'
|
EMAIL = 'roger.philibert@gmail.com'
|
||||||
|
|
@ -53,7 +54,7 @@ class EHentaiBackend(BaseBackend, ICapGallery):
|
||||||
password = None
|
password = None
|
||||||
return self.create_browser(self.config['domain'].get(), username, password)
|
return self.create_browser(self.config['domain'].get(), username, password)
|
||||||
|
|
||||||
def search_gallery(self, pattern=None, sortby=None, max_results=None):
|
def search_gallery(self, pattern, sortby=None, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_gallery(pattern)
|
return self.browser.search_gallery(pattern)
|
||||||
|
|
||||||
|
|
@ -94,6 +95,23 @@ class EHentaiBackend(BaseBackend, ICapGallery):
|
||||||
ratelimit("ehentai_get", 2)
|
ratelimit("ehentai_get", 2)
|
||||||
image.data = self.browser.readurl(image.url)
|
image.data = self.browser.readurl(image.url)
|
||||||
|
|
||||||
|
def iter_resources(self, objs, split_path):
|
||||||
|
if BaseGallery 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 gallery in self.browser.latest_gallery():
|
||||||
|
yield gallery
|
||||||
|
|
||||||
|
def validate_collection(self, objs, collection):
|
||||||
|
if collection.path_level == 0:
|
||||||
|
return
|
||||||
|
if BaseGallery in objs and collection.split_path == [u'latest_nsfw']:
|
||||||
|
collection.title = u'Latest E-Hentai galleries (NSFW)'
|
||||||
|
return
|
||||||
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {
|
OBJECTS = {
|
||||||
EHentaiGallery: fill_gallery,
|
EHentaiGallery: fill_gallery,
|
||||||
EHentaiImage: fill_image}
|
EHentaiImage: fill_image}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,11 @@ class EHentaiBrowser(BaseBrowser):
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_galleries()
|
return self.page.iter_galleries()
|
||||||
|
|
||||||
|
def latest_gallery(self):
|
||||||
|
self.location('/')
|
||||||
|
assert self.is_on_page(IndexPage)
|
||||||
|
return self.page.iter_galleries()
|
||||||
|
|
||||||
def iter_gallery_images(self, gallery):
|
def iter_gallery_images(self, gallery):
|
||||||
self.location(gallery.url)
|
self.location(gallery.url)
|
||||||
assert self.is_on_page(GalleryPage)
|
assert self.is_on_page(GalleryPage)
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,13 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.test import BackendTest
|
from weboob.tools.test import BackendTest
|
||||||
|
from weboob.capabilities.gallery import BaseGallery
|
||||||
|
|
||||||
|
|
||||||
class EHentaiTest(BackendTest):
|
class EHentaiTest(BackendTest):
|
||||||
BACKEND = 'ehentai'
|
BACKEND = 'ehentai'
|
||||||
|
|
||||||
def test_ehentai(self):
|
def test_search(self):
|
||||||
l = list(self.backend.search_gallery('lol'))
|
l = list(self.backend.search_gallery('lol'))
|
||||||
self.assertTrue(len(l) > 0)
|
self.assertTrue(len(l) > 0)
|
||||||
v = l[0]
|
v = l[0]
|
||||||
|
|
@ -36,3 +37,7 @@ class EHentaiTest(BackendTest):
|
||||||
self.backend.fillobj(img, ('url',))
|
self.backend.fillobj(img, ('url',))
|
||||||
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for first image in gallery "%s" not found: %s' % (v.id, img.url))
|
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for first image in gallery "%s" not found: %s' % (v.id, img.url))
|
||||||
self.backend.browser.openurl(img.url)
|
self.backend.browser.openurl(img.url)
|
||||||
|
|
||||||
|
def test_latest(self):
|
||||||
|
l = list(self.backend.iter_resources([BaseGallery], [u'latest_nsfw']))
|
||||||
|
assert len(l) > 0
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend
|
from weboob.tools.backend import BaseBackend
|
||||||
|
|
||||||
from .browser import PluzzBrowser
|
from .browser import PluzzBrowser
|
||||||
|
|
@ -30,7 +31,7 @@ from .video import PluzzVideo
|
||||||
__all__ = ['PluzzBackend']
|
__all__ = ['PluzzBackend']
|
||||||
|
|
||||||
|
|
||||||
class PluzzBackend(BaseBackend, ICapVideo):
|
class PluzzBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
NAME = 'francetelevisions'
|
NAME = 'francetelevisions'
|
||||||
MAINTAINER = 'Romain Bignon'
|
MAINTAINER = 'Romain Bignon'
|
||||||
EMAIL = 'romain@weboob.org'
|
EMAIL = 'romain@weboob.org'
|
||||||
|
|
@ -43,7 +44,7 @@ class PluzzBackend(BaseBackend, ICapVideo):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.get_video(_id)
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern)
|
return self.browser.search_videos(pattern)
|
||||||
|
|
||||||
|
|
@ -58,4 +59,21 @@ class PluzzBackend(BaseBackend, ICapVideo):
|
||||||
|
|
||||||
return video
|
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'])
|
||||||
|
if collection.split_path == [u'latest']:
|
||||||
|
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']:
|
||||||
|
collection.title = u'Latest France Télévisions videos'
|
||||||
|
return
|
||||||
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {PluzzVideo: fill_video}
|
OBJECTS = {PluzzVideo: fill_video}
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,13 @@ class PluzzBrowser(BaseBrowser):
|
||||||
self.location('/replay/1')
|
self.location('/replay/1')
|
||||||
|
|
||||||
def search_videos(self, pattern):
|
def search_videos(self, pattern):
|
||||||
if not pattern:
|
self.location(self.buildurl('/recherche.html', q=pattern.encode('utf-8')))
|
||||||
self.home()
|
|
||||||
else:
|
assert self.is_on_page(IndexPage)
|
||||||
self.location(self.buildurl('/recherche.html', q=pattern.encode('utf-8')))
|
return self.page.iter_videos()
|
||||||
|
|
||||||
|
def latest_videos(self):
|
||||||
|
self.home()
|
||||||
|
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
@ -79,11 +82,11 @@ class PluzzBrowser(BaseBrowser):
|
||||||
|
|
||||||
for vid in root.find('videos'):
|
for vid in root.find('videos'):
|
||||||
if vid.findtext('statut') == 'ONLINE' and vid.findtext('format') == 'wmv':
|
if vid.findtext('statut') == 'ONLINE' and vid.findtext('format') == 'wmv':
|
||||||
video.url = vid.findtext('url')
|
video.url = vid.findtext('url')
|
||||||
|
|
||||||
date = root.findtext('diffusions/diffusion')
|
date = root.findtext('diffusions/diffusion')
|
||||||
if date:
|
if date:
|
||||||
video.date = datetime.datetime.strptime(date, '%d/%m/%Y %H:%M')
|
video.date = datetime.datetime.strptime(date, '%d/%m/%Y %H:%M')
|
||||||
|
|
||||||
video.description = root.findtext('synopsis')
|
video.description = root.findtext('synopsis')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,22 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.test import BackendTest
|
from weboob.tools.test import BackendTest
|
||||||
|
from weboob.capabilities.video import BaseVideo
|
||||||
|
|
||||||
class PluzzTest(BackendTest):
|
class PluzzTest(BackendTest):
|
||||||
BACKEND = 'francetelevisions'
|
BACKEND = 'francetelevisions'
|
||||||
|
|
||||||
def test_francetelevisions(self):
|
def test_search(self):
|
||||||
# If the test fails, it might be good news!
|
# If the test fails, it might be good news!
|
||||||
l = list(self.backend.search_videos('Plus belle la vie'))
|
l = list(self.backend.search_videos('Plus belle la vie'))
|
||||||
self.assertTrue(len(l) > 0)
|
self.assertTrue(len(l) > 0)
|
||||||
v = l[0]
|
v = l[0]
|
||||||
self.backend.fillobj(v, ('url',))
|
self.backend.fillobj(v, ('url',))
|
||||||
self.assertTrue(v.url and v.url.startswith('mms://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
self.assertTrue(v.url and v.url.startswith('mms://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
||||||
|
|
||||||
|
def test_latest(self):
|
||||||
|
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
|
||||||
|
assert len(l)
|
||||||
|
v = l[0]
|
||||||
|
self.backend.fillobj(v, ('url',))
|
||||||
|
assert v.url
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class InaBackend(BaseBackend, ICapVideo):
|
||||||
def get_video(self, _id):
|
def get_video(self, _id):
|
||||||
return self.browser.get_video(_id)
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern)
|
return self.browser.search_videos(pattern)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.value import Value, ValueBackendPassword
|
from weboob.tools.value import Value, ValueBackendPassword
|
||||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ from .video import NolifeTVVideo
|
||||||
__all__ = ['NolifeTVBackend']
|
__all__ = ['NolifeTVBackend']
|
||||||
|
|
||||||
|
|
||||||
class NolifeTVBackend(BaseBackend, ICapVideo):
|
class NolifeTVBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
NAME = 'nolifetv'
|
NAME = 'nolifetv'
|
||||||
MAINTAINER = 'Romain Bignon'
|
MAINTAINER = 'Romain Bignon'
|
||||||
EMAIL = 'romain@weboob.org'
|
EMAIL = 'romain@weboob.org'
|
||||||
|
|
@ -55,7 +56,7 @@ class NolifeTVBackend(BaseBackend, ICapVideo):
|
||||||
video = self.browser.get_video(_id)
|
video = self.browser.get_video(_id)
|
||||||
return video
|
return video
|
||||||
|
|
||||||
def search_videos(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.search_videos(pattern)
|
return self.browser.search_videos(pattern)
|
||||||
|
|
||||||
|
|
@ -70,4 +71,21 @@ class NolifeTVBackend(BaseBackend, ICapVideo):
|
||||||
|
|
||||||
return video
|
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'])
|
||||||
|
if collection.split_path == [u'latest']:
|
||||||
|
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']:
|
||||||
|
collection.title = u'Latest NoLiveTV videos'
|
||||||
|
return
|
||||||
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {NolifeTVVideo: fill_video}
|
OBJECTS = {NolifeTVVideo: fill_video}
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,11 @@ class NolifeTVBrowser(BaseBrowser):
|
||||||
return self.page.get_video(video)
|
return self.page.get_video(video)
|
||||||
|
|
||||||
def search_videos(self, pattern):
|
def search_videos(self, pattern):
|
||||||
if not pattern:
|
self.location('/index.php?', 'search=%s' % urllib.quote_plus(pattern.encode('utf-8')))
|
||||||
self.home()
|
assert self.is_on_page(IndexPage)
|
||||||
else:
|
return self.page.iter_videos()
|
||||||
self.location('/index.php?', 'search=%s' % urllib.quote_plus(pattern.encode('utf-8')))
|
|
||||||
|
def latest_videos(self):
|
||||||
|
self.home()
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,15 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.test import BackendTest
|
from weboob.tools.test import BackendTest
|
||||||
|
from weboob.capabilities.video import BaseVideo
|
||||||
|
|
||||||
from .pages.video import ForbiddenVideo
|
from .pages.video import ForbiddenVideo
|
||||||
|
|
||||||
|
|
||||||
class NolifeTVTest(BackendTest):
|
class NolifeTVTest(BackendTest):
|
||||||
BACKEND = 'nolifetv'
|
BACKEND = 'nolifetv'
|
||||||
|
|
||||||
def test_nolife(self):
|
def test_search(self):
|
||||||
l = list(self.backend.search_videos('nolife'))
|
l = list(self.backend.search_videos('nolife'))
|
||||||
self.assertTrue(len(l) > 0)
|
self.assertTrue(len(l) > 0)
|
||||||
for v in l:
|
for v in l:
|
||||||
|
|
@ -35,3 +38,15 @@ class NolifeTVTest(BackendTest):
|
||||||
else:
|
else:
|
||||||
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def test_latest(self):
|
||||||
|
l = list(self.backend.iter_resources([BaseVideo], [u'latest']))
|
||||||
|
assert len(l) > 0
|
||||||
|
for v in l:
|
||||||
|
try:
|
||||||
|
self.backend.fillobj(v, ('url',))
|
||||||
|
except ForbiddenVideo:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
||||||
|
break
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue