Skip to content
module.py 2.65 KiB
Newer Older
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed
# -*- coding: utf-8 -*-

# Copyright(C) 2015 Guilhem Bonnefille
#
Roger Philibert's avatar
Roger Philibert committed
# This file is part of a woob module.
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed
#
Roger Philibert's avatar
Roger Philibert committed
# This woob module is free software: you can redistribute it and/or modify
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Roger Philibert's avatar
Roger Philibert committed
# This woob module is distributed in the hope that it will be useful,
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
Roger Philibert's avatar
Roger Philibert committed
# along with this woob module. If not, see <http://www.gnu.org/licenses/>.
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed

from woob.capabilities.video import CapVideo, BaseVideo
from woob.capabilities.collection import CapCollection, Collection
from woob.tools.backend import Module
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed

from .browser import RmllBrowser
from .video import RmllVideo


__all__ = ['RmllModule']


class RmllModule(Module, CapVideo, CapCollection):
    NAME = 'rmll'
    MAINTAINER = u'Guyou'
    EMAIL = 'guilhem.bonnefille@gmail.com'
Romain Bignon's avatar
Romain Bignon committed
    VERSION = '3.6'
    DESCRIPTION = 'Videos from RMLL'
    LICENSE = 'AGPLv3+'
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed

    BROWSER = RmllBrowser

    def create_default_browser(self):
        return self.create_browser()

    def get_video(self, _id):
        self.logger.debug("Getting video for %s", _id)
        return self.browser.get_video(_id)

    def search_videos(self, pattern, sortby=CapVideo.SEARCH_RELEVANCE, nsfw=False):
        return self.browser.search_videos(pattern)

    def fill_video(self, video, fields):
        self.logger.debug("Fill video %s for fields %s", video.id, fields)
        if fields != ['thumbnail']:
            # if we don't want only the thumbnail, we probably want also every fields
            video = self.browser.get_video(video.id, video)
        if 'thumbnail' in fields and video and video.thumbnail:
            video.thumbnail.data = self.browser.open(video.thumbnail.url).content

        return video

    def iter_resources(self, objs, split_path):
        if BaseVideo in objs:
            if len(split_path) == 0:
                # Add fake Collection
                yield Collection(['latest'], u'Latest')
            if len(split_path) == 1 and split_path[0] == 'latest':
                for video in self.browser.get_latest_videos():
                    yield video
            else:
                channel_videos = self.browser.get_channel_videos(split_path)
                if channel_videos:
                    for content in channel_videos:
                        yield content
Guilhem Bonnefille's avatar
Guilhem Bonnefille committed

    OBJECTS = {RmllVideo: fill_video}