コード例 #1
0
ファイル: api.py プロジェクト: reconman/Medusa
    def __init__(self, *args, **kwargs):  # pylint: disable=too-many-locals,too-many-arguments
        """Imdb constructor."""
        super(Imdb, self).__init__(*args, **kwargs)

        self.indexer = 10

        # Initiate the imdbpie API
        self.imdb_api = imdbpie.Imdb(session=self.config['session'])

        self.config['artwork_prefix'] = '{base_url}{image_size}{file_path}'

        # An api to indexer series/episode object mapping
        self.series_map = [
            ('id', 'imdb_id'),
            ('id', 'base.id'),
            ('seriesname', 'title'),
            ('seriesname', 'base.title'),
            ('summary', 'plot.outline.text'),
            ('firstaired', 'year'),
            ('poster', 'base.image.url'),
            ('show_url', 'base.id'),
            ('firstaired', 'base.seriesStartYear'),
            ('rating', 'ratings.rating'),
            ('votes', 'ratings.ratingCount'),
            ('nextepisode', 'base.nextEpisode'),
            ('lastaired', 'base.seriesEndYear'),
            # Could not find contentrating in api.
        ]

        self.episode_map = [
            ('id', 'id'),
            ('episodename', 'title'),
            ('firstaired', 'year'),
            ('absolute_number', 'absolute_number'),
        ]
コード例 #2
0
ファイル: imdb.py プロジェクト: steflavoie/Medusa
    def fetch_popular_shows(self):
        """Get popular show information from IMDB."""
        popular_shows = []

        # Clean expired cache items.
        imdb_show_details_cache.clean()
        tvdb_mapping_cache.clean()

        imdb_api = imdbpie.Imdb()
        imdb_result = imdb_api.popular_shows()

        for imdb_show in imdb_result:
            show = dict()
            imdb_tt = imdb_show['tconst']

            if imdb_tt:
                show['imdb_tt'] = imdb_show['tconst']
                cached_show_details = imdb_show_details_cache.get(imdb_tt)
                if not cached_show_details:
                    show_details = imdb_api.get_title_by_id(imdb_tt)
                    imdb_show_details_cache.append(imdb_tt, show_details)
                else:
                    show_details = cached_show_details.value

                if show_details:
                    show['year'] = getattr(show_details, 'year')
                    show['name'] = getattr(show_details, 'title')
                    show['image_url_large'] = getattr(show_details,
                                                      'cover_url')
                    show['image_path'] = posixpath.join(
                        'images', 'imdb_popular',
                        os.path.basename(show['image_url_large']))
                    show[
                        'imdb_url'] = 'http://www.imdb.com/title/{imdb_tt}'.format(
                            imdb_tt=imdb_tt)
                    show['votes'] = getattr(show_details, 'votes', 0)
                    show['outline'] = getattr(show_details, 'plot_outline',
                                              'Not available')
                    show['rating'] = getattr(show_details, 'rating', 0)
                else:
                    continue

            if all([show['year'], show['name'], show['imdb_tt']]):
                popular_shows.append(show)

        result = []
        for show in popular_shows:
            try:
                recommended_show = self._create_recommended_show(show)
                if recommended_show:
                    result.append(recommended_show)
            except RequestException:
                log.warning(
                    u'Could not connect to indexers to check if you already have'
                    u' this show in your library: {show} ({year})', {
                        'show': show['name'],
                        'year': show['name']
                    })

        return result
コード例 #3
0
    def fetch_popular_shows(self):
        """Get popular show information from IMDB."""
        popular_shows = []

        # Clean expired cache items.
        imdb_show_details_cache.clean()
        tvdb_mapping_cache.clean()

        imdb_api = imdbpie.Imdb()
        imdb_result = imdb_api.get_popular_shows()

        for imdb_show in imdb_result['ranks']:
            show = dict()
            imdb_tt = imdb_show['id'].strip('/').split('/')[-1]

            if imdb_tt:
                show['imdb_tt'] = imdb_tt
                cached_show_details = imdb_show_details_cache.get(imdb_tt)
                if not cached_show_details:
                    show_details = imdb_api.get_title(imdb_tt)
                    imdb_show_details_cache.append(imdb_tt, show_details)
                else:
                    show_details = cached_show_details.value

                if show_details:
                    show['year'] = imdb_show['year']
                    show['name'] = imdb_show['title']
                    show['image_url_large'] = imdb_show['image']['url']
                    show['image_path'] = posixpath.join('images', 'imdb_popular',
                                                        os.path.basename(show['image_url_large']))
                    show['image_url'] = '{0}{1}'.format(imdb_show['image']['url'].split('V1')[0], '_SY600_AL_.jpg')
                    show['imdb_url'] = 'http://www.imdb.com{imdb_id}'.format(imdb_id=imdb_show['id'])
                    show['votes'] = show_details['ratings']['ratingCount']
                    show['outline'] = show_details['plot'].get('outline', {}).get('text')
                    show['rating'] = show_details['ratings']['rating']
                else:
                    continue

            if all([show['year'], show['name'], show['imdb_tt']]):
                popular_shows.append(show)

        result = []
        for show in popular_shows:
            try:
                recommended_show = self._create_recommended_show(show)
                if recommended_show:
                    result.append(recommended_show)
            except RequestException:
                log.warning(
                    u'Could not connect to indexers to check if you already have'
                    u' this show in your library: {show} ({year})',
                    {'show': show['name'], 'year': show['name']}
                )

        return result
コード例 #4
0
ファイル: recommended.py プロジェクト: thomas2902/Medusa
)
from medusa.cache import recommended_series_cache
from medusa.helpers import ensure_list
from medusa.indexers.utils import indexer_id_to_name
from medusa.logger.adapters.style import BraceAdapter
from medusa.session.core import MedusaSession

from simpleanidb import Anidb

from six import binary_type

log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())

session = MedusaSession()
imdb_api = imdbpie.Imdb(session=session)

anidb_api = None


def load_anidb_api(func):
    """
    Decorate a function to lazy load the anidb_api.

    We need to do this, because we're passing the Medusa cache location to the lib. As the module is imported before
    the app.CACHE_DIR location has been read, we can't initialize it at module level.
    """
    def func_wrapper(aid):
        global anidb_api
        if anidb_api is None:
            anidb_api = Anidb(cache_dir=app.CACHE_DIR)
コード例 #5
0
from medusa.cache import recommended_series_cache
from medusa.indexers.indexer_config import INDEXER_TVDBV2
from medusa.logger.adapters.style import BraceAdapter
from medusa.session.core import MedusaSession
from medusa.show.recommendations.recommended import (
    RecommendedShow, cached_get_imdb_series_details, create_key_from_series,
    update_recommended_series_cache_index)

from requests import RequestException

from six import binary_type

log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())

imdb_api = imdbpie.Imdb()


class ImdbPopular(object):
    """Gets a list of most popular TV series from imdb."""
    def __init__(self):
        """Initialize class."""
        self.cache_subfolder = __name__.split(
            '.')[-1] if '.' in __name__ else __name__
        self.session = MedusaSession()
        self.recommender = 'IMDB Popular'
        self.default_img_src = 'poster.png'

    @recommended_series_cache.cache_on_arguments(
        namespace='imdb', function_key_generator=create_key_from_series)
    def _create_recommended_show(self, series, storage_key=None):