def sort_progress(episodes, sort_order): if sort_order == TRAKT_SORT.TITLE: return sorted(episodes, key=lambda x: title_key(x['show']['title'])) elif sort_order == TRAKT_SORT.RECENT_ACTIVITY: return sorted(episodes, key=lambda x: utils.iso_2_utc(x['last_watched_at']), reverse=True) elif sort_order == TRAKT_SORT.LEAST_COMPLETED: return sorted(episodes, key=lambda x: (x['percent_completed'], x['completed'])) elif sort_order == TRAKT_SORT.MOST_COMPLETED: return sorted(episodes, key=lambda x: (x['percent_completed'], x['completed']), reverse=True) elif sort_order == TRAKT_SORT.PREVIOUSLY_AIRED: return sorted( episodes, key=lambda x: utils.iso_2_utc(x['episode']['first_aired'])) elif sort_order == TRAKT_SORT.RECENTLY_AIRED: return sorted( episodes, key=lambda x: utils.iso_2_utc(x['episode']['first_aired']), reverse=True) elif sort_order == TRAKT_SORT.PAST_ACTIVITY: return sorted(episodes, key=lambda x: utils.iso_2_utc(x['last_watched_at'])) else: # default sort set to activity return sorted(episodes, key=lambda x: x['last_watched_at'], reverse=True)
def __get_cache_limit(self, media, activity, cached): if cached: activity = self.get_last_activity(media, activity) cache_limit = (time.time() - utils.iso_2_utc(activity)) logger.log( 'Now: %s Last: %s Last TS: %s Cache Limit: %.2fs (%.2fh)' % (time.time(), utils.iso_2_utc(activity), activity, cache_limit, cache_limit / 60 / 60), log_utils.LOGDEBUG) cache_limit = cache_limit / 60 / 60 else: cache_limit = 0 return cache_limit
def make_air_date(first_aired): utc_air_time = utils.iso_2_utc(first_aired) try: air_date = time.strftime('%Y-%m-%d', time.localtime(utc_air_time)) except ValueError: # windows throws a ValueError on negative values to localtime d = datetime.datetime.fromtimestamp(0) + datetime.timedelta(seconds=utc_air_time) air_date = d.strftime('%Y-%m-%d') return air_date
def show_next_up(last_label, sf_begin): token = kodi.get_setting('trakt_oauth_token') if token and xbmc.getInfoLabel('Container.PluginName') == kodi.get_id() and xbmc.getInfoLabel('Container.Content') == 'tvshows': if xbmc.getInfoLabel('ListItem.label') != last_label: sf_begin = time.time() last_label = xbmc.getInfoLabel('ListItem.label') if sf_begin and (time.time() - sf_begin) >= int(kodi.get_setting('next_up_delay')): liz_url = xbmc.getInfoLabel('ListItem.FileNameAndPath') queries = kodi.parse_query(liz_url[liz_url.find('?'):]) if 'trakt_id' in queries: try: list_size = int(kodi.get_setting('list_size')) except: list_size = 30 try: trakt_timeout = int(kodi.get_setting('trakt_timeout')) except: trakt_timeout = 20 trakt_api = Trakt_API(token, kodi.get_setting('use_https') == 'true', list_size, trakt_timeout, kodi.get_setting('trakt_offline') == 'true') progress = trakt_api.get_show_progress(queries['trakt_id'], full=True) if 'next_episode' in progress and progress['next_episode']: if progress['completed'] or kodi.get_setting('next_unwatched') == 'true': next_episode = progress['next_episode'] date = utils2.make_day(utils2.make_air_date(next_episode['first_aired'])) if kodi.get_setting('next_time') != '0': date_time = '%s@%s' % (date, utils2.make_time(utils.iso_2_utc(next_episode['first_aired']), 'next_time')) else: date_time = date msg = '[[COLOR deeppink]%s[/COLOR]] - %sx%s' % (date_time, next_episode['season'], next_episode['number']) if next_episode['title']: msg += ' - %s' % (next_episode['title']) duration = int(kodi.get_setting('next_up_duration')) * 1000 kodi.notify(header=i18n('next_episode'), msg=msg, duration=duration) sf_begin = 0 else: last_label = '' return last_label, sf_begin
def sort_progress(episodes, sort_order): if sort_order == TRAKT_SORT.TITLE: return sorted(episodes, key=lambda x: title_key(x['show']['title'])) elif sort_order == TRAKT_SORT.RECENT_ACTIVITY: return sorted(episodes, key=lambda x: utils.iso_2_utc(x['last_watched_at']), reverse=True) elif sort_order == TRAKT_SORT.LEAST_COMPLETED: return sorted(episodes, key=lambda x: (x['percent_completed'], x['completed'])) elif sort_order == TRAKT_SORT.MOST_COMPLETED: return sorted(episodes, key=lambda x: (x['percent_completed'], x['completed']), reverse=True) elif sort_order == TRAKT_SORT.PREVIOUSLY_AIRED: return sorted(episodes, key=lambda x: utils.iso_2_utc(x['episode']['first_aired'])) elif sort_order == TRAKT_SORT.RECENTLY_AIRED: return sorted(episodes, key=lambda x: utils.iso_2_utc(x['episode']['first_aired']), reverse=True) elif sort_order == TRAKT_SORT.PAST_ACTIVITY: return sorted(episodes, key=lambda x: utils.iso_2_utc(x['last_watched_at'])) else: # default sort set to activity return sorted(episodes, key=lambda x: x['last_watched_at'], reverse=True)
def __get_cache_limit(self, media, activity, cached): if cached: activity = self.get_last_activity(media, activity) cache_limit = (time.time() - utils.iso_2_utc(activity)) logger.log('Now: %s Last: %s Last TS: %s Cache Limit: %.2fs (%.2fh)' % (time.time(), utils.iso_2_utc(activity), activity, cache_limit, cache_limit / 60 / 60), log_utils.LOGDEBUG) cache_limit = cache_limit / 60 / 60 else: cache_limit = 0 return cache_limit
def __too_old(self, post): filter_days = datetime.timedelta(days=int(kodi.get_setting('%s-filter' % (self.get_name())))) post_date = dom_parser2.parse_dom(post, 'time', {'class': 'updated'}, req='datetime') if filter_days and post_date: try: today = datetime.date.today() post_date = datetime.date.fromtimestamp(utils.iso_2_utc(post_date[0].attrs['datetime'])) if today - post_date > filter_days: return True except ValueError: return False return False
def __too_old(self, post): filter_days = datetime.timedelta(days=int(kodi.get_setting('%s-filter' % (self.get_name())))) post_date = dom_parser2.parse_dom(post, 'time', {'class': 'entry-date'}, req='datetime') if filter_days and post_date: today = datetime.date.today() try: post_date = datetime.date.fromtimestamp(utils.iso_2_utc(post_date[0].content)) if today - post_date > filter_days: return True except ValueError: return False return False
def auth_torba(self): html = self._http_get(OAUTH_GET_URL, cache_limit=0) js_data = scraper_utils.parse_json(html, OAUTH_GET_URL) line1 = i18n('verification_url') % (js_data['verification_short_url']) line2 = i18n('login_prompt') countdown = int(utils.iso_2_utc(js_data['expires_in']) - time.time()) interval = js_data['interval'] / 1000 with kodi.CountdownDialog(i18n('torba_acct_auth'), line1=line1, line2=line2, countdown=countdown, interval=interval) as cd: result = cd.start(self.check_oauth, [js_data['device_code']]) # cancelled if result is None: return return self.__get_token(result['client_id'], result['client_secret'], js_data['device_code'])