def get_episode_info(): meta_user_info = metadata.retrieve_user_info() watched_indicators = settings.watched_indicators() watched_info = indicators.get_watched_info_tv(watched_indicators) show_unaired = settings.show_unaired() thumb_fanart = settings.thumb_fanart() is_widget = kodi_utils.external_browse() current_date = get_datetime() adjust_hours = settings.date_offset() bookmarks = indicators.get_bookmarks('episode', watched_indicators) return meta_user_info, watched_indicators, watched_info, show_unaired, thumb_fanart, is_widget, current_date, adjust_hours, bookmarks
def mark_as_watched_unwatched_tvshow(params): action = params.get('action') tmdb_id = params.get('tmdb_id') try: tvdb_id = int(params.get('tvdb_id', '0')) except: tvdb_id = 0 watched_indicators = settings.watched_indicators() kodi_utils.progressDialogBG.create(ls(32577), '') if watched_indicators == 1: if not trakt_watched_unwatched(action, 'shows', tmdb_id, tvdb_id): return kodi_utils.notification(32574) clear_trakt_collection_watchlist_data('watchlist', 'tvshow') data_base = TRAKT_DB else: data_base = WATCHED_DB title = params.get('title', '') year = params.get('year', '') meta_user_info = metadata.retrieve_user_info() adjust_hours = settings.date_offset() current_date = get_datetime() insert_list = [] insert_append = insert_list.append meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info) season_data = meta['season_data'] season_data = [i for i in season_data if i['season_number'] > 0] total = len(season_data) last_played = get_last_played_value(data_base) for count, item in enumerate(season_data, 1): season_number = item['season_number'] ep_data = metadata.season_episodes_meta(season_number, meta, meta_user_info) for ep in ep_data: season_number = ep['season'] ep_number = ep['episode'] display = 'S%.2dE%.2d' % (int(season_number), int(ep_number)) kodi_utils.progressDialogBG.update( int(float(count) / float(total) * 100), ls(32577), '%s' % display) episode_date, premiered = adjust_premiered_date( ep['premiered'], adjust_hours) if not episode_date or current_date < episode_date: continue insert_append( make_batch_insert(action, 'episode', tmdb_id, season_number, ep_number, last_played, title)) batch_mark_as_watched_unwatched(insert_list, action, data_base) batch_erase_bookmark(insert_list, action, watched_indicators) kodi_utils.progressDialogBG.close() if settings.sync_kodi_library_watchstatus(): batch_mark_kodi_library(action, insert_list, title, year) refresh_container()
def get_expiry_hours(self): try: current_date = get_datetime() if self.db_type == 'movie': premiered = jsondate_to_datetime(self.premiered, '%Y-%m-%d', remove_time=True) difference = (current_date - premiered).days if difference == 0: self.single_expiry = int(24 * 0.125) elif difference <= 10: self.single_expiry = 24 * 1 elif difference <= 14: self.single_expiry = 24 * 3 elif difference <= 180: self.single_expiry = 24 * 180 else: self.single_expiry = 24 * 365 else: extra_info = self.meta['extra_info'] ended = extra_info['status'].lower() in ('ended', 'canceled') premiered = adjust_premiered_date(self.premiered, date_offset())[0] difference = (current_date - premiered).days last_episode_to_air = jsondate_to_datetime( extra_info['last_episode_to_air']['air_date'], '%Y-%m-%d', remove_time=True) last_ep_difference = (current_date - last_episode_to_air).days if ended: if last_ep_difference <= 30: recently_ended = True else: recently_ended = False if not ended or recently_ended: if difference == 0: self.single_expiry = int(24 * 0.125) elif difference <= 3: self.single_expiry = 24 * 1 elif difference <= 7: self.single_expiry = 24 * 3 elif difference <= 14: self.single_expiry = 24 * 14 elif difference <= 28: self.single_expiry = 24 * 180 else: self.single_expiry = 24 * 365 if self.meta[ 'total_seasons'] == self.season and last_ep_difference <= 21: self.season_expiry = 24 * 10 else: self.season_expiry = 24 * 365 self.show_expiry = 24 * 10 else: self.single_expiry = 24 * 365 self.season_expiry = 24 * 365 self.show_expiry = 24 * 365 except: self.single_expiry, self.season_expiry, self.show_expiry = 24, 336, 336
def play_fetch_random(tmdb_id): meta_user_info = metadata.retrieve_user_info() meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info) adjust_hours = date_offset() current_date = get_datetime() episodes_data = metadata.all_episodes_meta(meta, meta_user_info) episodes_data = [ i for i in episodes_data if not i['season'] == 0 and adjust_premiered_date(i['premiered'], adjust_hours)[0] <= current_date ] if not episodes_data: return {'pass': True} chosen_episode = choice(episodes_data) title = meta['title'] season = int(chosen_episode['season']) episode = int(chosen_episode['episode']) query = title + ' S%.2dE%.2d' % (season, episode) display_name = '%s - %dx%.2d' % (title, season, episode) ep_name = chosen_episode['title'] plot = chosen_episode['plot'] try: premiered = adjust_premiered_date(chosen_episode['premiered'], adjust_hours)[1] except: premiered = chosen_episode['premiered'] meta.update({ 'vid_type': 'episode', 'rootname': display_name, 'season': season, 'episode': episode, 'premiered': premiered, 'ep_name': ep_name, 'plot': plot, 'random': 'true' }) url_params = { 'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': meta['tmdb_id'], 'query': query, 'tvshowtitle': meta['rootname'], 'season': season, 'episode': episode, 'autoplay': 'True' } return execute_builtin('RunPlugin(%s)' % build_url(url_params))
def pack_enable_check(meta, season, episode): try: extra_info = meta['extra_info'] status = extra_info['status'].lower() if status in ('ended', 'canceled'): return True, True from metadata import season_episodes_meta, retrieve_user_info from modules.utils import adjust_premiered_date, get_datetime adjust_hours = date_offset() current_date = get_datetime() meta_user_info = retrieve_user_info() episodes_data = season_episodes_meta(season, meta, meta_user_info) unaired_episodes = [ adjust_premiered_date(i['premiered'], adjust_hours)[0] for i in episodes_data ] if None in unaired_episodes or any(i > current_date for i in unaired_episodes): return False, False else: return True, False except: pass return False, False