weboob-devel/contrib/plugin.video.videoobmc/resources/lib/videoobmc2.py
Laurent Bachelier 74a4ef6723 Use the print function everywhere
python modernize.py --no-six -f libmodernize.fixes.fix_print -w

With manual fixes as the import was put always on top.
2014-10-06 17:00:17 +02:00

54 lines
2.1 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from .base.weboobmc2 import Weboobmc
from weboob.capabilities.video import BaseVideo, CapVideo
from weboob.capabilities.collection import CapCollection, Collection
class Videoobmc(Weboobmc):
def __init__(self, count=10, nsfw=False):
Weboobmc.__init__(self, count=count)
self.backends = self.weboob.load_backends(CapVideo)
self.nsfw = nsfw
def search(self, pattern, backend=''):
kwargs = {'pattern': pattern,
'nsfw': self.nsfw,
'backends': backend}
fields = ['id', 'title', 'date', 'description', 'author', 'duration', 'thumbnail', 'url']
try:
for _backend, video in self.weboob.do(self._do_complete, self.count, fields, 'search_videos', **kwargs):
yield video
except Exception as e:
print(e)
def get_video(self, video, _backend):
backend = self.weboob.get_backend(_backend)
fields = ['id', 'title', 'date', 'description', 'author', 'duration', 'thumbnail', 'url']
return backend.fillobj(video, fields)
def ls(self, backend, path=''):
kwargs = {'split_path': path.split('/') if path else [],
'caps': CapCollection,
'objs': (BaseVideo, ),
'backends': backend}
fields = [] # ['id', 'title', 'date', 'description', 'author', 'duration', 'thumbnail', 'url']
result = self.weboob.do(self._do_complete, self.count, fields, 'iter_resources', **kwargs)
return self.separate_collections_and_videos(result)
def separate_collections_and_videos(self, objs):
videos = []
categories = []
for backend, obj in objs:
if isinstance(obj, Collection):
categories.append(obj)
else:
videos.append(obj)
return categories, videos
def download(self, _id, dest, backend):
for backend, _video in self.weboob.do('get_video', _id, backends=backend):
self.download_obj(_video, dest)