diff --git a/modules/arretsurimages/backend.py b/modules/arretsurimages/backend.py index e508aff2..6bfcaec8 100644 --- a/modules/arretsurimages/backend.py +++ b/modules/arretsurimages/backend.py @@ -18,6 +18,7 @@ # along with weboob. If not, see . +from weboob.capabilities.base import UserError from weboob.capabilities.video import ICapVideo, BaseVideo from weboob.capabilities.collection import ICapCollection, CollectionNotFound from weboob.tools.backend import BaseBackend, BackendConfig @@ -44,8 +45,9 @@ class ArretSurImagesBackend(BaseBackend, ICapVideo, ICapCollection): return self.create_browser(self.config['login'].get(), self.config['password'].get()) def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None): - with self.browser: - return self.browser.search_videos(pattern) +# with self.browser: +# return self.browser.search_videos(pattern) + raise UserError('Search does not work on ASI website, use ls latest command') def get_video(self, _id): with self.browser: @@ -61,5 +63,22 @@ class ArretSurImagesBackend(BaseBackend, ICapVideo, ICapCollection): 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']) + 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 ArretSurImages videos' + return + raise CollectionNotFound(collection.split_path) OBJECTS = {ArretSurImagesVideo: fill_video} diff --git a/modules/arretsurimages/browser.py b/modules/arretsurimages/browser.py index aeea08c3..015973ab 100644 --- a/modules/arretsurimages/browser.py +++ b/modules/arretsurimages/browser.py @@ -64,5 +64,10 @@ class ArretSurImagesBrowser(BaseBrowser): self.page.login(self.username, self.password) if not self.is_logged(): - raise BrowserIncorrectPassword() + raise BrowserIncorrectPassword() + + def latest_videos(self): + self.location(self.buildurl('/emissions.php')) + assert self.is_on_page(IndexPage) + return self.page.iter_videos() diff --git a/modules/arretsurimages/pages.py b/modules/arretsurimages/pages.py index ffa34c65..3b76cd0d 100644 --- a/modules/arretsurimages/pages.py +++ b/modules/arretsurimages/pages.py @@ -41,7 +41,6 @@ class IndexPage(BasePage): if m: _id = m.group(1) - video = ArretSurImagesVideo(_id) video.title = unicode(title) video.rating = None