diff --git a/modules/arretsurimages/backend.py b/modules/arretsurimages/backend.py index 8497b21b..41315443 100644 --- a/modules/arretsurimages/backend.py +++ b/modules/arretsurimages/backend.py @@ -18,7 +18,6 @@ # 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 @@ -40,19 +39,19 @@ class ArretSurImagesBackend(BaseBackend, ICapVideo, ICapCollection): CONFIG = BackendConfig(ValueBackendPassword('login', label='email', masked=False), ValueBackendPassword('password', label='Password')) BROWSER = ArretSurImagesBrowser - + def create_default_browser(self): 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) # raise UserError('Search does not work on ASI website, use ls latest command') - + def get_video(self, _id): with self.browser: - return self.browser.get_video(_id) - + return self.browser.get_video(_id) + def fill_video(self, video, fields): if fields != ['thumbnail']: # if we don't want only the thumbnail, we probably want also every fields @@ -62,8 +61,8 @@ class ArretSurImagesBackend(BaseBackend, ICapVideo, ICapCollection): with self.browser: video.thumbnail.data = self.browser.readurl(video.thumbnail.url) - return video - + return video + def iter_resources(self, objs, split_path): if BaseVideo in objs: collection = self.get_collection(objs, split_path) @@ -79,6 +78,6 @@ class ArretSurImagesBackend(BaseBackend, ICapVideo, ICapCollection): if BaseVideo in objs and collection.split_path == [u'latest']: collection.title = u'Latest ArretSurImages videos' return - raise CollectionNotFound(collection.split_path) + raise CollectionNotFound(collection.split_path) OBJECTS = {ArretSurImagesVideo: fill_video} diff --git a/modules/arretsurimages/browser.py b/modules/arretsurimages/browser.py index 015973ab..b2433100 100644 --- a/modules/arretsurimages/browser.py +++ b/modules/arretsurimages/browser.py @@ -39,7 +39,7 @@ class ArretSurImagesBrowser(BaseBrowser): '%s://%s/forum/login.php' % (PROTOCOL, DOMAIN): LoginPage, '%s://%s/forum/index.php' % (PROTOCOL, DOMAIN): LoginRedirectPage, } - + def home(self): self.location('http://www.arretsurimages.net') @@ -47,15 +47,15 @@ class ArretSurImagesBrowser(BaseBrowser): self.location(self.buildurl('/emissions.php')) assert self.is_on_page(IndexPage) return self.page.iter_videos() - + @id2url(ArretSurImagesVideo.id2url) def get_video(self, url, video=None): self.login() self.location(url) return self.page.get_video(video) - + def is_logged(self): - return self.is_on_page(LoginPage) == False + return not self.is_on_page(LoginPage) def login(self): if not self.is_on_page(LoginPage): @@ -64,10 +64,9 @@ 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() - + return self.page.iter_videos() diff --git a/modules/arretsurimages/pages.py b/modules/arretsurimages/pages.py index 3b76cd0d..d83048fc 100644 --- a/modules/arretsurimages/pages.py +++ b/modules/arretsurimages/pages.py @@ -18,7 +18,6 @@ # along with weboob. If not, see . import re -import mechanize from weboob.capabilities.base import UserError from weboob.tools.browser import BasePage, BrokenPageError @@ -51,6 +50,7 @@ class IndexPage(BasePage): yield video + class ForbiddenVideo(UserError): pass @@ -83,40 +83,40 @@ class VideoPage(BasePage): def get_title(self): title = self.document.getroot().cssselect('div[id=titrage-contenu] h1')[0].text - return title; - + return title + def get_id(self): m = re.match(r'http://videos.arretsurimages.net/telecharger/(.*)', self.get_firstUrl()) - _id = '' if m: return m.group(1) self.logger.warning('Unable to parse ID') return 0 - + def get_url(self): firstUrl = self.get_firstUrl() doc = self.browser.get_document(self.browser.openurl(firstUrl)) - links = doc.xpath('//a'); - url = None; + links = doc.xpath('//a') + url = None i = 1 - for link in links : + for link in links: # we take the second link of the page if i == 2: url = link.attrib['href'] - i=i+1 + i += 1 return url - + + class LoginPage(BasePage): def login(self, username, password): response = self.browser.response() - response.set_data(response.get_data().replace("
", "
")) #Python mechanize is broken, fixing it. + response.set_data(response.get_data().replace("
", "
")) # Python mechanize is broken, fixing it. self.browser.set_response(response) self.browser.select_form(nr=0) - self.browser.form.set_all_readonly(False) + self.browser.form.set_all_readonly(False) self.browser['redir'] = '/forum/index.php' self.browser['username'] = username self.browser['password'] = password - self.browser.submit() + self.browser.submit() class LoginRedirectPage(BasePage):