NolifeTV module update

Use mobile.nolife-tv.com instead of online.nolife-tv.com.
Add theme/type entries.
These changes are inspired by XBMC NolifeTV plugin from Julien Gormotte:
julien@gormotte.info

videoob> ls
~ (theme) Par theme (nolifetv)
~ (type) Par type (nolifetv)
~ (latest) Latest NolifeTV videos (nolifetv)
videoob> cd theme
videoob:/theme> ls
~ (Actualités) Actualités (nolifetv)
~ (Fictions) Fictions (nolifetv)
~ (Musique) Musique (nolifetv)
~ (Nolife) Nolife (nolifetv)
~ (Culture & Style) Culture & Style (nolifetv)
~ (Jeu vidéo) Jeu vidéo (nolifetv)
~ (Sélection pour découvrir Nolife) Sélection pour découvrir Nolife (nolifetv)
~ (Japon) Japon (nolifetv)
videoob:/theme> cd Japon
videoob:/theme/Japon> ls
~ (77) Japan in Motion (nolifetv)
~ (68) J-Top (Speed run) (nolifetv)
~ (84) Nochan (nolifetv)
~ (49) OTO (nolifetv)
~ (100) toco toco (nolifetv)
~ (112) Nihongo ga dekimasu ka (nolifetv)
~ (57) Tôkyô Café (nolifetv)
videoob:/theme/Japon> cd 57
Hint: There are more results available for nolifetv (use option -n or count command)
 1 — Tôkyô Café - 239 - La statue Gundam à Odaiba (nolifetv)
 2 — Tôkyô Café - 238 - UNCHAIN (nolifetv)
 3 — Tôkyô Café - 237 - The End au Théâtre du Châtelet (nolifetv)
 4 — Tôkyô Café - 236 - Scéance photo à Asobi Station dans le quartier de Harajuku avec YANO Anna (nolifetv)
 5 — Tôkyô Café - 235 - Le TGS 2013 vu par Suzuka (nolifetv)
 6 — Tôkyô Café - 234 - Street Live de Itowokashi à Tôkyô (chanson en intégralité) (nolifetv)
 7 — Tôkyô Café - 234 - Street Live de Itowokashi à Tôkyô (nolifetv)
 8 — Tôkyô Café - 233 - Tsume Fan Day (nolifetv)
 9 — Tôkyô Café - 232 - Puzzle & Dragons (nolifetv)
10 — Tôkyô Café - 231 - Japan Expo 2013 (nolifetv)

Signed-off-by: Clément Calmels <cboulte@gmail.com>
Signed-off-by: Romain Bignon <romain@symlink.me>
This commit is contained in:
Clément Calmels 2013-12-19 22:56:10 +01:00 committed by Romain Bignon
commit 7100d35acd
8 changed files with 277 additions and 280 deletions

View file

@ -18,20 +18,19 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.video import ICapVideo, BaseVideo
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
from weboob.capabilities.collection import ICapCollection, CollectionNotFound, Collection
from weboob.tools.value import Value, ValueBackendPassword
from weboob.tools.backend import BaseBackend, BackendConfig
from .browser import NolifeTVBrowser
from .video import NolifeTVVideo
import urllib, time
from hashlib import md5
__all__ = ['NolifeTVBackend']
class NolifeTVBackend(BaseBackend, ICapVideo, ICapCollection):
NAME = 'nolifetv'
MAINTAINER = u'Romain Bignon'
@ -40,52 +39,88 @@ class NolifeTVBackend(BaseBackend, ICapVideo, ICapCollection):
DESCRIPTION = 'NolifeTV French video streaming website'
LICENSE = 'AGPLv3+'
BROWSER = NolifeTVBrowser
CONFIG = BackendConfig(Value('username', label='Username', default=''),
ValueBackendPassword('password', label='Password', default=''))
CONFIG = BackendConfig(Value('username', label='Username', default=''),
ValueBackendPassword('password', label='Password', default=''),
Value('quality', label='Quality',
choices = { '1':'LQ', '2':'HQ', '3':'TV', '4':'720p', '5':'1080p' },
default = '5' ))
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)
return self.create_browser(self.config['username'].get(), self.config['password'].get())
def iter_resources(self, objs, split_path):
with self.browser:
if BaseVideo in objs:
collection = self.get_collection(objs, split_path)
if collection.path_level == 0:
yield Collection([u'theme'], u'Par theme')
yield Collection([u'type'], u'Par type')
yield Collection([u'latest'], u'Latest NolifeTV videos')
if collection.path_level == 1:
if split_path[0] == 'latest':
for vid in self.browser.get_latest():
yield vid
else:
for cat in self.browser.iter_category(split_path[0]):
yield cat
if collection.path_level == 2:
for cat in self.browser.iter_family(split_path[0], split_path[1]):
yield cat
if collection.path_level == 3:
for cat in self.browser.iter_video(split_path[2]):
yield cat
def validate_collection(self, objs, collection):
if BaseVideo in objs:
if collection.path_level == 0:
return
if collection.path_level == 1 and collection.split_path[0] in [u'theme', u'type', u'latest']:
return
if collection.path_level > 1:
return
raise CollectionNotFound(collection.split_path)
def get_video(self, _id):
with self.browser:
video = self.browser.get_video(_id)
return self.browser.get_video(_id)
def fill_video(self, video, fields):
with self.browser:
self.browser.get_video(NolifeTVVideo.id2url(video.id), video)
if 'thumbnail' in fields and video.thumbnail:
with self.browser:
video.thumbnail.data = self.browser.readurl(video.thumbnail.url)
if 'url' in fields:
with self.browser:
video.url = self.get_url(video.id, self.config['quality'].get())
return video
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False):
with self.browser:
return self.browser.search_videos(pattern)
def fill_video(self, video, fields):
if fields != ['thumbnail']:
# if we don't want only the thumbnail, we probably want also every fields
with self.browser:
video = self.browser.get_video(NolifeTVVideo.id2url(video.id), video)
if 'thumbnail' in fields and video.thumbnail:
with self.browser:
video.thumbnail.data = self.browser.readurl(video.thumbnail.url)
OBJECTS = { NolifeTVVideo: fill_video }
return video
SALT = 'a53be1853770f0ebe0311d6993c7bcbe'
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 genkey(self):
# This website is really useful to get info: http://www.showmycode.com/
timestamp = str(int(time.time()))
skey = md5(md5(timestamp).hexdigest() + self.SALT).hexdigest()
return skey, timestamp
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 NoLiveTV videos'
return
raise CollectionNotFound(collection.split_path)
def get_url(self, id, quality):
skey, timestamp = self.genkey()
self.browser.readurl('http://online.nolife-tv.com/_nlfplayer/api/api_player.php',
'quality=%s&a=EML&skey=%s&id%%5Fnlshow=%s&timestamp=%s' % (quality, skey, id, timestamp))
OBJECTS = {NolifeTVVideo: fill_video}
skey, timestamp = self.genkey()
data = self.browser.readurl('http://online.nolife-tv.com/_nlfplayer/api/api_player.php',
'quality=%s&a=UEM%%7CSEM%%7CMEM%%7CCH%%7CSWQ&skey=%s&id%%5Fnlshow=%s&timestamp=%s' % (quality, skey, id, timestamp))
values = dict([urllib.splitvalue(s) for s in data.split('&')])
if not 'url' in values:
return None
return unicode(values['url'])