support authentication (thanks to Lord for giving me an account)
This commit is contained in:
parent
f308fed5ae
commit
439a6ec515
3 changed files with 48 additions and 18 deletions
|
|
@ -21,7 +21,8 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.video import ICapVideo
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import Value, ValueBackendPassword
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
|
||||
from .browser import NolifeTVBrowser
|
||||
from .video import NolifeTVVideo
|
||||
|
|
@ -38,6 +39,16 @@ class NolifeTVBackend(BaseBackend, ICapVideo):
|
|||
DESCRIPTION = 'NolifeTV French video streaming website'
|
||||
LICENSE = 'AGPLv3+'
|
||||
BROWSER = NolifeTVBrowser
|
||||
CONFIG = BackendConfig(Value('username', label='Username', default=''),
|
||||
ValueBackendPassword('password', label='Password', default=''))
|
||||
|
||||
def create_default_browser(self):
|
||||
username = self.config['username'].get()
|
||||
if len(username) > 0:
|
||||
password = self.config['password'].get()
|
||||
else:
|
||||
password = None
|
||||
return self.create_browser(username, password)
|
||||
|
||||
def get_video(self, _id):
|
||||
with self.browser:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
from weboob.tools.browser.decorators import id2url
|
||||
|
||||
from .pages.index import IndexPage
|
||||
|
|
@ -38,6 +38,31 @@ class NolifeTVBrowser(BaseBrowser):
|
|||
r'http://online.nolife-tv.com/': IndexPage,
|
||||
r'http://online.nolife-tv.com/index.php\?id=(?P<id>.+)': VideoPage}
|
||||
|
||||
def is_logged(self):
|
||||
if self.password is None:
|
||||
return True
|
||||
|
||||
login = self.page.document.getroot().cssselect('div#form_login')
|
||||
return len(login) == 0
|
||||
|
||||
def login(self):
|
||||
if self.password is None:
|
||||
return
|
||||
|
||||
params = {'cookieuser': 1,
|
||||
'do': 'login',
|
||||
'securitytoken': 'guest',
|
||||
'vb_login_username': self.username,
|
||||
'vb_login_password': self.password,
|
||||
}
|
||||
|
||||
self.readurl('http://forum.nolife-tv.com/login.php?do=login', urllib.urlencode(params))
|
||||
|
||||
self.location('/', no_login=True)
|
||||
|
||||
if not self.is_logged():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
@id2url(NolifeTVVideo.id2url)
|
||||
def get_video(self, url, video=None):
|
||||
self.location(url)
|
||||
|
|
|
|||
|
|
@ -41,21 +41,15 @@ class VideoPage(BasePage):
|
|||
_id = to_unicode(self.group_dict['id'])
|
||||
if video is None:
|
||||
video = NolifeTVVideo(_id)
|
||||
#title_el = self.parser.select(self.document.getroot(), 'title', 1)
|
||||
#video.title = to_unicode(title_el.text.strip())
|
||||
|
||||
## youjizz HTML is crap, we must parse it with regexps
|
||||
#data = lxml.html.tostring(self.document.getroot())
|
||||
#m = re.search(r'<strong>.*?Runtime.*?</strong> (.+?)<br.*>', data)
|
||||
#if m:
|
||||
# txt = m.group(1).strip()
|
||||
# if txt == 'Unknown':
|
||||
# video.duration = NotAvailable
|
||||
# else:
|
||||
# minutes, seconds = (int(v) for v in to_unicode(txt).split(':'))
|
||||
# video.duration = datetime.timedelta(minutes=minutes, seconds=seconds)
|
||||
#else:
|
||||
# raise BrokenPageError('Unable to retrieve video duration')
|
||||
# Check if video is external.
|
||||
try:
|
||||
div = self.parser.select(self.document.getroot(), 'div#message_lien_ext', 1)
|
||||
except BrokenPageError:
|
||||
pass
|
||||
else:
|
||||
link = div.find('a').attrib['href']
|
||||
raise ForbiddenVideo('Video is only available here: %s' % link)
|
||||
|
||||
div = self.parser.select(self.document.getroot(), 'div#informations_video', 1)
|
||||
video.title = self.parser.select(div, 'div#ligne_titre_big', 1).text
|
||||
|
|
@ -86,7 +80,7 @@ class VideoPage(BasePage):
|
|||
values = dict([urllib.splitvalue(s) for s in data.split('&')])
|
||||
|
||||
if not 'url' in values:
|
||||
raise ForbiddenVideo(values['message'].decode('iso-8859-15'))
|
||||
raise ForbiddenVideo(values.get('message', 'Not available').decode('iso-8859-15'))
|
||||
video.url = values['url']
|
||||
|
||||
return video
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue