def get_show_list(self, trakt_list, **params): """ Takes in a list of shows from a Trakt endpoint, updates meta where required and returns the formatted list :param trakt_list: List of shows to retrieve :type trakt_list: list :return: List of updated shows with full meta :rtype: list """ g.log("Fetching show list from sync database", "debug") trakt_list = [i for i in trakt_list if i.get("trakt_id")] self.insert_trakt_shows( self.filter_trakt_items_that_needs_updating(trakt_list, "shows") ) self._update_mill_format_shows(trakt_list, False) g.log("Show list update and milling compelete", "debug") statement = """SELECT s.trakt_id, s.info, s.cast, s.art, s.args, s.watched_episodes, s.unwatched_episodes, s.episode_count, s.season_count FROM shows as s WHERE s.trakt_id in ({}) """.format( ",".join((str(i.get("trakt_id")) for i in trakt_list)) ) if params.pop("hide_unaired", self.hide_unaired): statement += " AND Datetime(s.air_date) < Datetime('now')" if params.pop("hide_watched", self.hide_watched): statement += " AND s.watched_episodes < s.episode_count" return MetadataHandler.sort_list_items( self.execute_sql(statement).fetchall(), trakt_list )
def get_mixed_episode_list(self, trakt_items, **params): """ Returns a list of mixed episodes from different or same show :param trakt_items: List of show & episodes object pairs :type trakt_items: list :return: List of episode objects with full meta :rtype: list """ g.log("Fetching mixed episode list from sync database", "debug") self._try_update_mixed_episodes(trakt_items) in_predicate = ",".join([ str(i["trakt_id"]) for i in trakt_items if i["trakt_id"] is not None ]) if g.get_bool_setting("general.showRemainingUnwatched"): query = """SELECT e.trakt_id, e.info, e.cast, e.art, e.args, e.watched as play_count, b.resume_time as resume_time, b.percent_played as percent_played, se.watched_episodes, se.unwatched_episodes, se.episode_count FROM episodes as e INNER JOIN seasons se on e.trakt_season_id = se.trakt_id LEFT JOIN bookmarks as b on e.Trakt_id = b.Trakt_id WHERE e.trakt_id in ({})""".format( in_predicate) else: query = """SELECT e.trakt_id, e.info, e.cast, e.art, e.args, e.watched as play_count, b.resume_time as resume_time, b.percent_played as percent_played FROM episodes as e LEFT JOIN bookmarks as b on e.Trakt_id = b.Trakt_id WHERE e.trakt_id in ({})""".format(in_predicate) if params.pop("hide_unaired", self.hide_unaired): query += " AND Datetime(e.air_date) < Datetime('now') " if params.pop("hide_specials", self.hide_specials): query += " AND e.season != 0" if params.pop("hide_watched", self.hide_watched): query += " AND e.watched = 0" return MetadataHandler.sort_list_items( self.execute_sql(query).fetchall(), trakt_items)
def get_movie_list(self, trakt_list, **params): self._update_movies(trakt_list) query = """SELECT m.trakt_id, m.info, m.art, m.cast, m.args, b.resume_time, b.percent_played, m.watched as play_count FROM movies as m left join bookmarks as b on m.trakt_id = b.trakt_id WHERE m.trakt_id in ({})""".format( ",".join((str(i.get("trakt_id")) for i in trakt_list))) if params.get("hide_unaired", self.hide_unaired): query += " AND Datetime(air_date) < Datetime('now')" if params.get("hide_watched", self.hide_watched): query += " AND watched = 0" return MetadataHandler.sort_list_items(self.fetchall(query), trakt_list)