def get_trakt_watched(self, trakt_watched=None):
        if not trakt_watched:
            return

        key = 'movie' if self.infolabels.get(
            'mediatype') == 'movie' else 'show'
        item = utils.get_dict_in_list(trakt_watched, 'tmdb',
                                      utils.try_parse_int(self.tmdb_id),
                                      [key, 'ids'])
        if not item:
            return

        if self.infolabels.get('mediatype') == 'episode':
            found_ep = None
            for s in item.get('seasons', []):
                if s.get('number', -2) == utils.try_parse_int(
                        self.infolabels.get('season', -1)):
                    for ep in s.get('episodes', []):
                        if ep.get('number', -2) == utils.try_parse_int(
                                self.infolabels.get('episode', -1)):
                            found_ep = item = ep
                            break
                    break
            if not found_ep:
                return

        lastplayed = utils.convert_timestamp(item.get('last_watched_at'))
        self.infolabels['lastplayed'] = lastplayed.strftime(
            '%Y-%m-%d %H:%M:%S') if lastplayed else None
        self.infolabels['playcount'] = item.get('plays', 0)
        self.infolabels['overlay'] = 5 if item.get('plays') else 4
Ejemplo n.º 2
0
    def get_unwatched_count(self,
                            tmdb_id=None,
                            imdb_id=None,
                            season=None,
                            request=None,
                            check_sync=True,
                            only_inprogress=True):
        if not tmdb_id and not imdb_id and not request:
            return -1

        request = request or self.get_unwatched_progress(
            tmdb_id=tmdb_id, imdb_id=imdb_id, check_sync=check_sync)

        if not request:
            return -1

        request = utils.get_dict_in_list(
            request.get('seasons', []), 'number',
            utils.try_parse_int(season)) if season else request

        if not request or not request.get('aired'):
            return -1

        if not utils.try_parse_int(request.get('completed', 0)):
            return -1

        return utils.try_parse_int(request.get('aired')) - utils.try_parse_int(
            request.get('completed', 0))