예제 #1
0
    def add_movie(self, tmdb_id=None, **kwargs):
        if not tmdb_id:
            return

        # Get movie details
        details = TMDb().get_request_sc('movie',
                                        tmdb_id,
                                        append_to_response='external_ids')
        if not details or not details.get('title'):
            return
        imdb_id = details.get('external_ids', {}).get('imdb_id')
        name = u'{} ({})'.format(details['title'],
                                 details['release_date'][:4]) if details.get(
                                     'release_date') else details['title']

        # Only add strm if not in library
        file = self.kodi_db_movies.get_info(info='file',
                                            imdb_id=imdb_id,
                                            tmdb_id=tmdb_id)
        if not file:
            file = create_file(STRM_MOVIE.format(tmdb_id),
                               name,
                               name,
                               basedir=BASEDIR_MOVIE)
            create_nfo('movie', tmdb_id, name, basedir=BASEDIR_MOVIE)
            self._log._add('movie', tmdb_id, 'added strm file', path=file)
        else:
            self._log._add('movie', tmdb_id, 'item in library', path=file)

        # Return our playlist rule
        return ('filename', file.replace('\\', '/').split('/')[-1])
    def _legacy_conversion(self, folder, tmdb_id):
        # Get details
        details = TMDb().get_request_sc('tv', tmdb_id, append_to_response='external_ids')
        if not details or not details.get('first_air_date'):
            return  # Skip shows without details/year

        # Get new name and compare to old name
        name = u'{} ({})'.format(details.get('name'), details['first_air_date'][:4])
        if folder == name:
            return  # Skip if already converted

        # Convert name
        basedir = BASEDIR_TV.replace('\\', '/')
        old_folder = u'{}{}/'.format(basedir, validify_filename(folder))
        new_folder = u'{}{}/'.format(basedir, validify_filename(name))
        xbmcvfs.rename(old_folder, new_folder)
class _TVShow():
    def __init__(self, tmdb_id, force=False):
        self._cache = _TVShowCache(tmdb_id, force)
        self.tmdb_id = tmdb_id
        self.details = None
        self.name = None

    def get_details(self):
        self.details = TMDb().get_request_sc('tv', self.tmdb_id, append_to_response='external_ids')
        if not self.details:
            return
        self.tvdb_id = self.details.get('external_ids', {}).get('tvdb_id')
        self.imdb_id = self.details.get('external_ids', {}).get('imdb_id')
        return self.details

    def get_name(self):
        name = u'{}{}'.format(
            self.details.get('name'),
            u' ({})'.format(self.details['first_air_date'][:4]) if self.details.get('first_air_date') else '')
        self.name = get_unique_folder(name, self.tmdb_id, BASEDIR_TV)
        return self.name

    def get_dbid(self, kodi_db=None):
        kodi_db = kodi_db or rpc.get_kodi_library('tv')
        self.dbid = kodi_db.get_info(info='dbid', imdb_id=self.imdb_id, tmdb_id=self.tmdb_id, tvdb_id=self.tvdb_id)
        return self.dbid

    def get_episode_db_info(self, season, episode, info='dbid'):
        if not self.dbid:
            return
        return rpc.KodiLibrary(dbtype='episode', tvshowid=self.dbid, logging=False).get_info(
            info=info, season=season, episode=episode)

    def get_seasons(self):
        self.seasons = self.details.get('seasons', [])
        self.s_total = len(self.seasons)
        return self.seasons

    def get_episodes(self, season):
        self.e_total = 0
        self.season_details = TMDb().get_request('tv', self.tmdb_id, 'season', season, cache_refresh=True)
        if not self.season_details:
            return []
        self.episodes = [i for i in self.season_details.get('episodes', []) if i.get('episode_number', 0) != 0]
        self.e_total = len(self.episodes)
        return self.episodes

    def make_nfo(self):
        create_nfo('tv', self.tmdb_id, self.name, basedir=BASEDIR_TV)

    def set_next(self):
        self._cache.create_new_cache(self.details.get('name', ''))
        self._cache.set_next_check(
            next_aired=self.details.get('next_episode_to_air', {}),
            last_aired=self.details.get('last_episode_to_air', {}),
            status=self.details.get('status'))
예제 #4
0
def _get_language_details(tmdb_type, tmdb_id, season=None, episode=None, language=None):
    details = TMDb().get_request_lc(tmdb_type, tmdb_id, 'translations')
    if not details or not details.get('translations'):
        return

    item = {}
    for i in details['translations']:
        if i.get('iso_639_1') == language:
            item['title'] = i.get('data', {}).get('title') or i.get('data', {}).get('name')
            item['plot'] = i.get('data', {}).get('overview')
            return item
def _get_genre(tmdb_type, method):
    data_list = TMDb().get_request_lc('genre', tmdb_type, 'list')
    if data_list and data_list.get('genres'):
        return _select_properties(data_list['genres'],
                                  method,
                                  header=ADDON.getLocalizedString(32112))