pyflages / pep8 fix
This commit is contained in:
parent
455a11b887
commit
5fc90ec3b2
3 changed files with 28 additions and 30 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
from weboob.capabilities.base import UserError
|
|
||||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
|
|
@ -40,19 +39,19 @@ class ArretSurImagesBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
CONFIG = BackendConfig(ValueBackendPassword('login', label='email', masked=False),
|
CONFIG = BackendConfig(ValueBackendPassword('login', label='email', masked=False),
|
||||||
ValueBackendPassword('password', label='Password'))
|
ValueBackendPassword('password', label='Password'))
|
||||||
BROWSER = ArretSurImagesBrowser
|
BROWSER = ArretSurImagesBrowser
|
||||||
|
|
||||||
def create_default_browser(self):
|
def create_default_browser(self):
|
||||||
return self.create_browser(self.config['login'].get(), self.config['password'].get())
|
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):
|
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)
|
||||||
# raise UserError('Search does not work on ASI website, use ls latest command')
|
# raise UserError('Search does not work on ASI website, use ls latest command')
|
||||||
|
|
||||||
def get_video(self, _id):
|
def get_video(self, _id):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.get_video(_id)
|
return self.browser.get_video(_id)
|
||||||
|
|
||||||
def fill_video(self, video, fields):
|
def fill_video(self, video, fields):
|
||||||
if fields != ['thumbnail']:
|
if fields != ['thumbnail']:
|
||||||
# if we don't want only the thumbnail, we probably want also every fields
|
# 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:
|
with self.browser:
|
||||||
video.thumbnail.data = self.browser.readurl(video.thumbnail.url)
|
video.thumbnail.data = self.browser.readurl(video.thumbnail.url)
|
||||||
|
|
||||||
return video
|
return video
|
||||||
|
|
||||||
def iter_resources(self, objs, split_path):
|
def iter_resources(self, objs, split_path):
|
||||||
if BaseVideo in objs:
|
if BaseVideo in objs:
|
||||||
collection = self.get_collection(objs, split_path)
|
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']:
|
if BaseVideo in objs and collection.split_path == [u'latest']:
|
||||||
collection.title = u'Latest ArretSurImages videos'
|
collection.title = u'Latest ArretSurImages videos'
|
||||||
return
|
return
|
||||||
raise CollectionNotFound(collection.split_path)
|
raise CollectionNotFound(collection.split_path)
|
||||||
|
|
||||||
OBJECTS = {ArretSurImagesVideo: fill_video}
|
OBJECTS = {ArretSurImagesVideo: fill_video}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class ArretSurImagesBrowser(BaseBrowser):
|
||||||
'%s://%s/forum/login.php' % (PROTOCOL, DOMAIN): LoginPage,
|
'%s://%s/forum/login.php' % (PROTOCOL, DOMAIN): LoginPage,
|
||||||
'%s://%s/forum/index.php' % (PROTOCOL, DOMAIN): LoginRedirectPage,
|
'%s://%s/forum/index.php' % (PROTOCOL, DOMAIN): LoginRedirectPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
def home(self):
|
def home(self):
|
||||||
self.location('http://www.arretsurimages.net')
|
self.location('http://www.arretsurimages.net')
|
||||||
|
|
||||||
|
|
@ -47,15 +47,15 @@ class ArretSurImagesBrowser(BaseBrowser):
|
||||||
self.location(self.buildurl('/emissions.php'))
|
self.location(self.buildurl('/emissions.php'))
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
||||||
@id2url(ArretSurImagesVideo.id2url)
|
@id2url(ArretSurImagesVideo.id2url)
|
||||||
def get_video(self, url, video=None):
|
def get_video(self, url, video=None):
|
||||||
self.login()
|
self.login()
|
||||||
self.location(url)
|
self.location(url)
|
||||||
return self.page.get_video(video)
|
return self.page.get_video(video)
|
||||||
|
|
||||||
def is_logged(self):
|
def is_logged(self):
|
||||||
return self.is_on_page(LoginPage) == False
|
return not self.is_on_page(LoginPage)
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
if not self.is_on_page(LoginPage):
|
if not self.is_on_page(LoginPage):
|
||||||
|
|
@ -64,10 +64,9 @@ class ArretSurImagesBrowser(BaseBrowser):
|
||||||
self.page.login(self.username, self.password)
|
self.page.login(self.username, self.password)
|
||||||
|
|
||||||
if not self.is_logged():
|
if not self.is_logged():
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
||||||
def latest_videos(self):
|
def latest_videos(self):
|
||||||
self.location(self.buildurl('/emissions.php'))
|
self.location(self.buildurl('/emissions.php'))
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
return self.page.iter_videos()
|
return self.page.iter_videos()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import mechanize
|
|
||||||
|
|
||||||
from weboob.capabilities.base import UserError
|
from weboob.capabilities.base import UserError
|
||||||
from weboob.tools.browser import BasePage, BrokenPageError
|
from weboob.tools.browser import BasePage, BrokenPageError
|
||||||
|
|
@ -51,6 +50,7 @@ class IndexPage(BasePage):
|
||||||
|
|
||||||
yield video
|
yield video
|
||||||
|
|
||||||
|
|
||||||
class ForbiddenVideo(UserError):
|
class ForbiddenVideo(UserError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -83,40 +83,40 @@ class VideoPage(BasePage):
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
title = self.document.getroot().cssselect('div[id=titrage-contenu] h1')[0].text
|
title = self.document.getroot().cssselect('div[id=titrage-contenu] h1')[0].text
|
||||||
return title;
|
return title
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
m = re.match(r'http://videos.arretsurimages.net/telecharger/(.*)', self.get_firstUrl())
|
m = re.match(r'http://videos.arretsurimages.net/telecharger/(.*)', self.get_firstUrl())
|
||||||
_id = ''
|
|
||||||
if m:
|
if m:
|
||||||
return m.group(1)
|
return m.group(1)
|
||||||
self.logger.warning('Unable to parse ID')
|
self.logger.warning('Unable to parse ID')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_url(self):
|
def get_url(self):
|
||||||
firstUrl = self.get_firstUrl()
|
firstUrl = self.get_firstUrl()
|
||||||
doc = self.browser.get_document(self.browser.openurl(firstUrl))
|
doc = self.browser.get_document(self.browser.openurl(firstUrl))
|
||||||
links = doc.xpath('//a');
|
links = doc.xpath('//a')
|
||||||
url = None;
|
url = None
|
||||||
i = 1
|
i = 1
|
||||||
for link in links :
|
for link in links:
|
||||||
# we take the second link of the page
|
# we take the second link of the page
|
||||||
if i == 2:
|
if i == 2:
|
||||||
url = link.attrib['href']
|
url = link.attrib['href']
|
||||||
i=i+1
|
i += 1
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
class LoginPage(BasePage):
|
class LoginPage(BasePage):
|
||||||
def login(self, username, password):
|
def login(self, username, password):
|
||||||
response = self.browser.response()
|
response = self.browser.response()
|
||||||
response.set_data(response.get_data().replace("<br/>", "<br />")) #Python mechanize is broken, fixing it.
|
response.set_data(response.get_data().replace("<br/>", "<br />")) # Python mechanize is broken, fixing it.
|
||||||
self.browser.set_response(response)
|
self.browser.set_response(response)
|
||||||
self.browser.select_form(nr=0)
|
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['redir'] = '/forum/index.php'
|
||||||
self.browser['username'] = username
|
self.browser['username'] = username
|
||||||
self.browser['password'] = password
|
self.browser['password'] = password
|
||||||
self.browser.submit()
|
self.browser.submit()
|
||||||
|
|
||||||
|
|
||||||
class LoginRedirectPage(BasePage):
|
class LoginRedirectPage(BasePage):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue