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 __future__ import with_statement
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
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 .browser import NolifeTVBrowser
|
||||||
from .video import NolifeTVVideo
|
from .video import NolifeTVVideo
|
||||||
|
|
@ -38,6 +39,16 @@ class NolifeTVBackend(BaseBackend, ICapVideo):
|
||||||
DESCRIPTION = 'NolifeTV French video streaming website'
|
DESCRIPTION = 'NolifeTV French video streaming website'
|
||||||
LICENSE = 'AGPLv3+'
|
LICENSE = 'AGPLv3+'
|
||||||
BROWSER = NolifeTVBrowser
|
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):
|
def get_video(self, _id):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
from weboob.tools.browser.decorators import id2url
|
from weboob.tools.browser.decorators import id2url
|
||||||
|
|
||||||
from .pages.index import IndexPage
|
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/': IndexPage,
|
||||||
r'http://online.nolife-tv.com/index.php\?id=(?P<id>.+)': VideoPage}
|
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)
|
@id2url(NolifeTVVideo.id2url)
|
||||||
def get_video(self, url, video=None):
|
def get_video(self, url, video=None):
|
||||||
self.location(url)
|
self.location(url)
|
||||||
|
|
|
||||||
|
|
@ -41,21 +41,15 @@ class VideoPage(BasePage):
|
||||||
_id = to_unicode(self.group_dict['id'])
|
_id = to_unicode(self.group_dict['id'])
|
||||||
if video is None:
|
if video is None:
|
||||||
video = NolifeTVVideo(_id)
|
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
|
# Check if video is external.
|
||||||
#data = lxml.html.tostring(self.document.getroot())
|
try:
|
||||||
#m = re.search(r'<strong>.*?Runtime.*?</strong> (.+?)<br.*>', data)
|
div = self.parser.select(self.document.getroot(), 'div#message_lien_ext', 1)
|
||||||
#if m:
|
except BrokenPageError:
|
||||||
# txt = m.group(1).strip()
|
pass
|
||||||
# if txt == 'Unknown':
|
else:
|
||||||
# video.duration = NotAvailable
|
link = div.find('a').attrib['href']
|
||||||
# else:
|
raise ForbiddenVideo('Video is only available here: %s' % link)
|
||||||
# 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')
|
|
||||||
|
|
||||||
div = self.parser.select(self.document.getroot(), 'div#informations_video', 1)
|
div = self.parser.select(self.document.getroot(), 'div#informations_video', 1)
|
||||||
video.title = self.parser.select(div, 'div#ligne_titre_big', 1).text
|
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('&')])
|
values = dict([urllib.splitvalue(s) for s in data.split('&')])
|
||||||
|
|
||||||
if not 'url' in values:
|
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']
|
video.url = values['url']
|
||||||
|
|
||||||
return video
|
return video
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue