def _update_season_fanart(self, db_object):
     if (self.fanarttv_api.fanart_support
             and (self._fanart_needs_update(db_object)
                  or self._force_update(db_object))
             and self._tvdb_show_id_valid(db_object)):
         tools.smart_merge_dictionary(
             db_object,
             self.fanarttv_api.get_season(
                 db_object.get("tvdb_show_id"),
                 tools.safe_dict_get(db_object, "trakt_object", "info",
                                     "season"),
             ),
         )
示例#2
0
 def _update_movie_tmdb(self, db_object):
     if ((self.metadata_location == 1
          or self.movies_preferred_art_source == 1)
             and (self._tmdb_needs_update(db_object)
                  or self._force_update(db_object))
             and self._tmdb_id_valid(db_object)):
         if self.metadata_location == 1:
             tools.smart_merge_dictionary(
                 db_object, self.tmdb_api.get_movie(db_object["tmdb_id"]))
         elif self.movies_preferred_art_source == 1:
             tools.smart_merge_dictionary(
                 db_object,
                 self.tmdb_api.get_movie_art(db_object["tmdb_id"]))
示例#3
0
 def _update_tvshow_tvdb(self, db_object):
     if ((self.metadata_location == 2
          or self.tvshows_preferred_art_source == 2)
             and (self._tvdb_needs_update(db_object)
                  or self._force_update(db_object))
             and self._tvdb_id_valid(db_object)):
         if self.metadata_location == 2:
             tools.smart_merge_dictionary(
                 db_object, self.tvdb_api.get_show(db_object["tvdb_id"]))
         elif self.tvshows_preferred_art_source == 2:
             tools.smart_merge_dictionary(
                 db_object,
                 self.tvdb_api.get_show_art(db_object["tvdb_id"]))
示例#4
0
 def _update_movie_fanart(self, db_object):
     if self.fanarttv_api.fanart_support and (
             self._fanart_needs_update(db_object)
             or self._force_update(db_object)):
         if self._tmdb_id_valid(db_object):
             tools.smart_merge_dictionary(
                 db_object,
                 self.fanarttv_api.get_movie(db_object.get("tmdb_id")))
         if self._imdb_id_valid(db_object) and self._fanart_needs_update(
                 db_object):
             tools.smart_merge_dictionary(
                 db_object,
                 self.fanarttv_api.get_movie(db_object.get("imdb_id")))
示例#5
0
 def _update_tvshow_rating(self, db_object):
     if not tools.safe_dict_get(
         db_object, "tmdb_object", "info"
     ) and self._tmdb_id_valid(db_object):
         tools.smart_merge_dictionary(
             db_object, self.tmdb_api.get_show_rating(db_object["tmdb_id"])
         )
     if not tools.safe_dict_get(
         db_object, "tvdb_object", "info"
     ) and self._tvdb_id_valid(db_object):
         tools.smart_merge_dictionary(
             db_object, self.tvdb_api.get_show_rating(db_object["tvdb_id"])
         )
 def _update_tvshow_cast(self, db_object):
     if (not tools.safe_dict_get(db_object, "tmdb_object", "cast")
             and self._tmdb_id_valid(db_object)
             and not tools.safe_dict_get(db_object, "tvdb_object", "cast")
             and self.metadata_location != META_TVDB):
         tools.smart_merge_dictionary(
             db_object, self.tmdb_api.get_show_cast(db_object["tmdb_id"]))
     if (not tools.safe_dict_get(db_object, "tvdb_object", "cast")
             and self._tvdb_id_valid(db_object)
             and not tools.safe_dict_get(db_object, "tmdb_object", "cast")
             and self.metadata_location != META_TMDB):
         tools.smart_merge_dictionary(
             db_object, self.tvdb_api.get_show_cast(db_object["tvdb_id"]))
示例#7
0
 def _update_movie_fallback(self, db_object):
     if (
         self.movies_preferred_art_source == 0
         and not self._fanart_meta_up_to_par("movie", db_object)
         and self._tmdb_id_valid(db_object)
     ):
         tools.smart_merge_dictionary(
             db_object, self.tmdb_api.get_movie_art(db_object["tmdb_id"])
         )
     if self.movies_preferred_art_source == 1 and not self._tmdb_meta_up_to_par(
         "movie", db_object
     ):
         self._update_movie_fanart(db_object)
 def _update_season_tvdb(self, db_object):
     if ((self.tvshows_preferred_art_source == 2
          or not self._tmdb_meta_up_to_par("season", db_object))
             and (self._tvdb_needs_update(db_object)
                  or self._force_update(db_object))
             and self._tvdb_show_id_valid(db_object)):
         tools.smart_merge_dictionary(
             db_object,
             self.tvdb_api.get_season_art(
                 db_object["tvdb_show_id"],
                 tools.safe_dict_get(db_object, "trakt_object", "info",
                                     "season"),
             ),
         )
    def _update_tvshow_fallback(self, db_object):
        if self._tvdb_id_valid(db_object):
            if (self.metadata_location == 1 and
                    not tools.safe_dict_get(db_object, "tmdb_object", "info")
                    and
                    not tools.safe_dict_get(db_object, "tvdb_object", "info")):
                tools.smart_merge_dictionary(
                    db_object, self.tvdb_api.get_show(db_object["tvdb_id"]))
            if (self.tvshows_preferred_art_source != 2
                    and not self._tmdb_meta_up_to_par("tvshow", db_object)
                    and not self._tvdb_meta_up_to_par("tvshow", db_object)):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tvdb_api.get_show_art(db_object["tvdb_id"]))

        if self._tmdb_id_valid(db_object):
            if (self.metadata_location == 2 and
                    not tools.safe_dict_get(db_object, "tmdb_object", "info")
                    and
                    not tools.safe_dict_get(db_object, "tvdb_object", "info")):
                tools.smart_merge_dictionary(
                    db_object, self.tmdb_api.get_show(db_object["tmdb_id"]))
            if (self.tvshows_preferred_art_source != 1
                    and not self._tmdb_meta_up_to_par("tvshow", db_object)
                    and not self._tvdb_meta_up_to_par("tvshow", db_object)):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tmdb_api.get_show_art(db_object["tmdb_id"]))
示例#10
0
 def _update_episode_tvdb(self, db_object):
     if (
         (self.metadata_location == 2 or self.tvshows_preferred_art_source == 2)
         and (self._tvdb_needs_update(db_object) or self._force_update(db_object))
         and self._tvdb_show_id_valid(db_object)
     ):
         tools.smart_merge_dictionary(
             db_object,
             self.tvdb_api.get_episode(
                 db_object["tvdb_show_id"],
                 tools.safe_dict_get(db_object, "trakt_object", "info", "season"),
                 tools.safe_dict_get(db_object, "trakt_object", "info", "episode"),
             ),
         )
示例#11
0
    def _apply_best_fit_art(self, result, tmdb_object, tvdb_object,
                            fanart_object, media_type):
        if tmdb_object:
            result["art"] = tools.smart_merge_dictionary(
                result.get("art", {}), tmdb_object.get("art", {}),
                not self._is_tmdb_artwork_selected(media_type), False)

        if tvdb_object:
            result["art"] = tools.smart_merge_dictionary(
                result.get("art", {}), tvdb_object.get("art", {}),
                not self._is_tvdb_artwork_selected(media_type), False)

        if fanart_object:
            result["art"] = tools.smart_merge_dictionary(
                result.get("art", {}), fanart_object.get("art", {}),
                not self._is_fanart_artwork_selected(media_type), False)

        result["art"] = self._handle_art(media_type, result.get("art", {}))
示例#12
0
 def get_episode(self, tvdb_id, season, episode):
     item = {}
     thread_pool = ThreadPool()
     for language in self.languages:
         thread_pool.put(self._get_episode_info, tvdb_id, season, episode,
                         language)
         item = tools.smart_merge_dictionary(item,
                                             thread_pool.wait_completion())
     if not item or len(item.keys()) == 0:
         return None
     return item
示例#13
0
 def get_show_info(self, tvdb_id):
     item = {}
     thread_pool = ThreadPool()
     thread_pool.put(self._get_series_cast, tvdb_id)
     for language in self.languages:
         thread_pool.put(self._get_show_info, tvdb_id, language)
         item = tools.smart_merge_dictionary(item,
                                             thread_pool.wait_completion())
     if not item or len(item.keys()) == 0:
         return None
     return item
示例#14
0
 def _handle_result(self, result):
     self.result_threading_lock.acquire()
     try:
         if result is not None:
             if isinstance(result, dict):
                 if self.results is None:
                     self.results = {}
                 tools.smart_merge_dictionary(self.results, result)
             elif isinstance(result, (list, set)):
                 if self.results is None:
                     self.results = []
                 if isinstance(result, list):
                     self.results.extend(result)
                 else:
                     self.results.append(result)
             else:
                 if self.results is None:
                     self.results = []
                 self.results.append(result)
     finally:
         self.result_threading_lock.release()
示例#15
0
 def _update_episode_rating(self, db_object):
     if not tools.safe_dict_get(
         db_object, "tmdb_object", "info"
     ) and self._tmdb_show_id_valid(db_object):
         tools.smart_merge_dictionary(
             db_object,
             self.tmdb_api.get_episode_rating(
                 db_object["tmdb_show_id"],
                 tools.safe_dict_get(db_object, "trakt_object", "info", "season"),
                 tools.safe_dict_get(db_object, "trakt_object", "info", "episode"),
             ),
         )
     if not tools.safe_dict_get(
         db_object, "tvdb_object", "info"
     ) and self._tvdb_show_id_valid(db_object):
         tools.smart_merge_dictionary(
             db_object,
             self.tvdb_api.get_episode_rating(
                 db_object["tvdb_show_id"],
                 tools.safe_dict_get(db_object, "trakt_object", "info", "season"),
                 tools.safe_dict_get(db_object, "trakt_object", "info", "episode"),
             ),
         )
示例#16
0
    def _show_season_art_fallback(data, season_art, show_art):
        show_season_art_mixin = {}

        MetadataHandler._thumb_fallback(data["art"], data["art"])

        if season_art:
            show_season_art_mixin = tools.smart_merge_dictionary(
                show_season_art_mixin,
                tools.filter_dictionary(season_art, "poster", "fanart", "clearlogo"),
                True,
            )
            MetadataHandler._thumb_fallback(data["art"], season_art)
        if show_art:
            show_season_art_mixin = tools.smart_merge_dictionary(
                show_season_art_mixin,
                tools.filter_dictionary(show_art, "poster", "fanart", "clearlogo"),
                True,
            )
            MetadataHandler._thumb_fallback(data["art"], show_art)

        data["art"] = tools.smart_merge_dictionary(
            data["art"], show_season_art_mixin, True
        )
示例#17
0
    def _create_list_menu(self, trakt_lists, **params):
        trakt_object = MetadataHandler.trakt_object
        get = MetadataHandler.get_trakt_info
        if not trakt_lists:
            trakt_lists = []

        self.builder.lists_menu_builder([
            tools.smart_merge_dictionary(
                trakt_object(trakt_list), {
                    'args': {
                        'trakt_id': get(trakt_list, 'trakt_id'),
                        'username': get(trakt_list, 'username')
                    }
                }) for trakt_list in trakt_lists
        ], **params)
 def _update_season_tmdb(self, db_object):
     if ((self.metadata_location == 1
          or self.tvshows_preferred_art_source == 1)
             and (self._tmdb_needs_update(db_object)
                  or self._force_update(db_object))
             and self._tmdb_show_id_valid(db_object)):
         if self.metadata_location == 1:
             tools.smart_merge_dictionary(
                 db_object,
                 self.tmdb_api.get_season(
                     db_object["tmdb_show_id"],
                     tools.safe_dict_get(db_object, "trakt_object", "info",
                                         "season"),
                 ),
             )
         elif self.tvshows_preferred_art_source == 1:
             tools.smart_merge_dictionary(
                 db_object,
                 self.tmdb_api.get_season_art(
                     db_object["tmdb_show_id"],
                     tools.safe_dict_get(db_object, "trakt_object", "info",
                                         "season"),
                 ),
             )
示例#19
0
 def get_season_art(self, tvdb_id, season):
     item = {}
     art_types = self._get_show_art_types(tvdb_id)
     if not art_types:
         return None
     art_types = [i for i in art_types if i.startswith("season")]
     thread_pool = ThreadPool()
     for language in self.languages:
         for art_type in art_types:
             thread_pool.put(self._get_season_art, tvdb_id, art_type,
                             season, language)
         item = tools.smart_merge_dictionary(item,
                                             thread_pool.wait_completion())
     if not item or len(item.keys()) == 0:
         return None
     return item
示例#20
0
    def _update_episode_fallback(self, db_object):
        if self._tvdb_show_id_valid(db_object):
            if (
                self.metadata_location == 1
                and not tools.safe_dict_get(db_object, "tmdb_object", "info")
                and not tools.safe_dict_get(db_object, "tvdb_object", "info")
            ):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tvdb_api.get_episode(
                        db_object["tvdb_show_id"],
                        tools.safe_dict_get(
                            db_object, "trakt_object", "info", "season"
                        ),
                        tools.safe_dict_get(
                            db_object, "trakt_object", "info", "episode"
                        ),
                    ),
                )

        if self._tmdb_show_id_valid(db_object):
            if (
                self.metadata_location == 2
                and not tools.safe_dict_get(db_object, "tmdb_object", "info")
                and not tools.safe_dict_get(db_object, "tvdb_object", "info")
            ):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tmdb_api.get_episode(
                        db_object["tmdb_show_id"],
                        tools.safe_dict_get(
                            db_object, "trakt_object", "info", "season"
                        ),
                        tools.safe_dict_get(db_object, "trakt_object", "info", "e"),
                    ),
                )
            if (
                self.tvshows_preferred_art_source != 1
                and not self._tmdb_meta_up_to_par("episode", db_object)
                and not self._tvdb_meta_up_to_par("episode", db_object)
            ):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tmdb_api.get_episode_art(
                        db_object["tmdb_show_id"],
                        tools.safe_dict_get(
                            db_object, "trakt_object", "info", "season"
                        ),
                        tools.safe_dict_get(
                            db_object, "trakt_object", "info", "episode"
                        ),
                    ),
                )
示例#21
0
    def get_show(self, tvdb_id):
        item = {}

        art_types = self._get_show_art_types(tvdb_id)
        if art_types:
            art_types = [i for i in art_types if not i.startswith("season")]

        else:
            art_types = []

        thread_pool = ThreadPool()
        thread_pool.put(self._get_series_cast, tvdb_id)
        for language in self.languages:
            thread_pool.put(self._get_show_info, tvdb_id, language)
            for art_type in art_types:
                thread_pool.put(self._get_show_art, tvdb_id, art_type,
                                language)
            item = tools.smart_merge_dictionary(item,
                                                thread_pool.wait_completion())
        if not item or len(item.keys()) == 0:
            return None
        return item
    def _update_season_fallback(self, db_object):
        if self._tmdb_show_id_valid(db_object):
            if (self.metadata_location == META_TVDB and
                    not tools.safe_dict_get(db_object, "tmdb_object", "info")
                    and
                    not tools.safe_dict_get(db_object, "tvdb_object", "info")):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tmdb_api.get_season(
                        db_object["tmdb_show_id"],
                        tools.safe_dict_get(db_object, "trakt_object", "info",
                                            "season"),
                    ),
                )
            if (self.tvshows_preferred_art_source != ART_TMDB
                    and self.metadata_location != META_TMDB
                    and not self._tmdb_meta_up_to_par("season", db_object)
                    and not self._tvdb_meta_up_to_par("season", db_object)):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tvdb_api.get_season_art(
                        db_object["tmdb_show_id"],
                        tools.safe_dict_get(db_object, "trakt_object", "info",
                                            "season"),
                    ),
                )

        if self._tvdb_show_id_valid(db_object):
            if (self.tvshows_preferred_art_source != ART_TVDB
                    and self.metadata_location != META_TVDB
                    and not self._tmdb_meta_up_to_par("season", db_object)
                    and not self._tvdb_meta_up_to_par("season", db_object)):
                tools.smart_merge_dictionary(
                    db_object,
                    self.tvdb_api.get_season_art(
                        db_object["tvdb_show_id"],
                        tools.safe_dict_get(db_object, "trakt_object", "info",
                                            "season"),
                    ),
                )
示例#23
0
    def mill_seasons(self,
                     trakt_collection,
                     queue_wrapper,
                     mill_episodes=False):
        with SyncLock(
                "mill_seasons_episodes_{}".format(mill_episodes),
            {
                show.get("trakt_show_id", show.get("trakt_id"))
                for show in trakt_collection
            },
        ) as sync_lock:
            get = MetadataHandler.get_trakt_info
            queue_wrapper(self._pull_show_seasons,
                          [(i, mill_episodes) for i in sync_lock.running_ids])
            results = self.mill_task_queue.wait_completion()

            seasons = []
            episodes = []
            trakt_info = MetadataHandler.trakt_info

            for show in trakt_collection:
                extended_seasons = get(show, "seasons", [])
                for season in results.get(show.get("trakt_id"), []):
                    if self.hide_specials and get(season, "season") == 0:
                        continue

                    trakt_info(season).update(
                        {"trakt_show_id": get(show, "trakt_id")})
                    trakt_info(season).update(
                        {"tmdb_show_id": get(show, "tmdb_id")})
                    trakt_info(season).update(
                        {"tvdb_show_id": get(show, "tvdb_id")})

                    season.update({"trakt_show_id": show.get("trakt_id")})
                    season.update({"tmdb_show_id": show.get("tmdb_id")})
                    season.update({"tvdb_show_id": show.get("tvdb_id")})

                    trakt_info(season).update(
                        {"dateadded": get(show, "dateadded")})
                    trakt_info(season).update(
                        {"tvshowtitle": get(show, "title")})

                    if not get(season, "season") == 0:
                        show.update(
                            {"season_count": show.get("season_count", 0) + 1})
                        show.update({
                            'episode_count':
                            show.get("episode_count", 0) +
                            get(season, "aired_episodes", 0)
                        })
                    for episode in get(season, "episodes", []):
                        trakt_info(episode).update(
                            {"trakt_show_id": get(show, "trakt_id")})
                        trakt_info(episode).update(
                            {"tmdb_show_id": get(show, "tmdb_id")})
                        trakt_info(episode).update(
                            {"tvdb_show_id": get(show, "tvdb_id")})
                        trakt_info(episode).update(
                            {"trakt_season_id": get(season, "trakt_id")})

                        episode.update({"trakt_show_id": show.get("trakt_id")})
                        episode.update({"tmdb_show_id": show.get("tmdb_id")})
                        episode.update({"tvdb_show_id": show.get("tvdb_id")})
                        episode.update(
                            {"trakt_season_id": season.get("trakt_id")})

                        trakt_info(episode).update(
                            {"tvshowtitle": get(show, "title")})
                        for extended_season in (
                                x for x in extended_seasons
                                if get(x, "season") == get(season, "season")):
                            [
                                tools.smart_merge_dictionary(
                                    episode, extended_episode)
                                for extended_episode in
                                (x
                                 for x in get(extended_season, "episodes", [])
                                 if get(x, "episode") == get(
                                     episode, "episode"))
                            ]
                            tools.smart_merge_dictionary(
                                season, extended_season)
                        episodes.append(episode)
                    seasons.append(season)

            self.insert_trakt_seasons(
                self.filter_trakt_items_that_needs_updating(
                    seasons, "seasons"))
            self.insert_trakt_episodes(
                self.filter_trakt_items_that_needs_updating(
                    episodes, "episodes"))

            self.execute_sql(
                "UPDATE shows SET episode_count=?, season_count=? WHERE trakt_id=? ",
                [(i.get("episode_count", 0), i.get("season_count",
                                                   0), i["trakt_id"])
                 for i in trakt_collection])

            self.update_shows_statistics({"trakt_id": i}
                                         for i in sync_lock.running_ids)

            if mill_episodes:
                self.update_season_statistics({"trakt_id": i}
                                              for i in sync_lock.running_ids)
 def _update_movie_cast(self, db_object):
     if self._tmdb_id_valid(db_object) \
             and self.metadata_location != META_TMDB:
         tools.smart_merge_dictionary(
             db_object, self.tmdb_api.get_movie_cast(db_object["tmdb_id"]))
 def _update_movie_cast(self, db_object):
     if not tools.safe_dict_get(db_object, "tmdb_object",
                                "cast") and self._tmdb_id_valid(db_object):
         tools.smart_merge_dictionary(
             db_object, self.tmdb_api.get_movie_cast(db_object["tmdb_id"]))
 def _add_omdb(self, db_object):
     if (self.omdb_api.omdb_support and self._imdb_id_valid(db_object)
             and (self._omdb_needs_update(db_object)
                  or self._force_update(db_object))):
         tools.smart_merge_dictionary(
             db_object, self.omdb_api.get_json(i=db_object.get("imdb_id")))