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 nextep_playback_info(meta): def _build_next_episode_play(): ep_data = season_episodes_meta(season, meta, meta_user_info) if not ep_data: return 'no_next_episode' ep_data = [i for i in ep_data if i['episode'] == episode][0] airdate = ep_data['premiered'] d = airdate.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) if current_date < episode_date: return 'no_next_episode' custom_title = meta_get('custom_title', None) title = custom_title or meta_get('title') display_name = '%s - %dx%.2d' % (title, int(season), int(episode)) meta.update({ 'vid_type': 'episode', 'rootname': display_name, 'season': season, 'ep_name': ep_data['title'], 'episode': episode, 'premiered': airdate, 'plot': ep_data['plot'] }) url_params = { 'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': tmdb_id, 'tvshowtitle': meta_get('rootname'), 'season': season, 'episode': episode, 'background': 'true' } if custom_title: url_params['custom_title'] = custom_title return url_params meta_get = meta.get meta_user_info = retrieve_user_info() tmdb_id, current_season, current_episode = meta_get('tmdb_id'), int( meta_get('season')), int(meta_get('episode')) try: current_date = get_datetime() season_data = meta_get('season_data') curr_season_data = [ i for i in season_data if i['season_number'] == current_season ][0] season = current_season if current_episode < curr_season_data[ 'episode_count'] else current_season + 1 episode = current_episode + 1 if current_episode < curr_season_data[ 'episode_count'] else 1 nextep_info = _build_next_episode_play() except: nextep_info = 'error' return meta, nextep_info
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_trakt_my_calendar(params): current_date = get_datetime() recently_aired = params.get('recently_aired', None) data = trakt_get_my_calendar(recently_aired, current_date) if recently_aired: list_type = 'trakt_recently_aired' data = data[:20] reverse = True else: list_type = 'trakt_calendar' data.sort(key=lambda k: k['sort_title'], reverse=False) reverse = calendar_sort_order() == 0 data.sort(key=lambda k: k['first_aired'], reverse=reverse) build_single_episode(list_type, data)
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
def build_season_list(params): def _process(): running_ep_count = total_aired_eps def _unaired_status(): if episode_count == 0: return True season_date_start = adjust_premiered_date(air_date, 0)[0] if not season_date_start or current_date < season_date_start: return True return False for item in season_data: try: listitem = make_listitem() set_property = listitem.setProperty cm = [] cm_append = cm.append item_get = item.get overview = item_get('overview') name = item_get('name') poster_path = item_get('poster_path') air_date = item_get('air_date') season_number = item_get('season_number') episode_count = item_get('episode_count') season_poster = 'https://image.tmdb.org/t/p/%s%s' % ( image_resolution, poster_path) if poster_path is not None else show_poster if season_number == 0: unaired = False else: unaired = _unaired_status() if unaired: if not show_unaired: return episode_count = 0 else: running_ep_count -= episode_count if running_ep_count < 0: episode_count = running_ep_count + episode_count try: year = air_date.split('-')[0] except: year = show_year plot = overview if overview != '' else show_plot title = name if use_season_title and name != '' else '%s %s' % ( season_str, string(season_number)) if unaired: title = unaired_label % title playcount, overlay, watched, unwatched = get_watched_status_season( watched_info, string(tmdb_id), season_number, episode_count) url_params = build_url({ 'mode': 'build_episode_list', 'tmdb_id': tmdb_id, 'season': season_number }) extras_params = build_url({ 'mode': 'extras_menu_choice', 'tmdb_id': tmdb_id, 'db_type': 'tvshow', 'is_widget': is_widget }) options_params = build_url({ 'mode': 'options_menu_choice', 'content': 'season', 'tmdb_id': tmdb_id }) cm_append((extras_str, run_plugin % extras_params)) cm_append((options_str, run_plugin % options_params)) if not playcount: watched_params = build_url({ 'mode': 'mark_as_watched_unwatched_season', 'action': 'mark_as_watched', 'title': show_title, 'year': show_year, 'tmdb_id': tmdb_id, 'tvdb_id': tvdb_id, 'season': season_number }) cm_append((watched_str % watched_title, run_plugin % watched_params)) if watched: unwatched_params = build_url({ 'mode': 'mark_as_watched_unwatched_season', 'action': 'mark_as_unwatched', 'title': show_title, 'year': show_year, 'tmdb_id': tmdb_id, 'tvdb_id': tvdb_id, 'season': season_number }) cm_append((unwatched_str % watched_title, run_plugin % unwatched_params)) listitem.setLabel(title) listitem.setContentLookup(False) listitem.addContextMenuItems(cm) listitem.setArt({ 'poster': season_poster, 'icon': season_poster, 'thumb': season_poster, 'fanart': fanart, 'banner': banner, 'clearart': clearart, 'clearlogo': clearlogo, 'landscape': landscape, 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.landscape': landscape, 'tvshow.banner': banner }) listitem.setCast(cast) listitem.setUniqueIDs({ 'imdb': imdb_id, 'tmdb': string(tmdb_id), 'tvdb': string(tvdb_id) }) listitem.setInfo( 'video', { 'mediatype': 'season', 'trailer': trailer, 'title': title, 'size': '0', 'duration': episode_run_time, 'plot': plot, 'rating': rating, 'premiered': premiered, 'studio': studio, 'year': year, 'genre': genre, 'mpaa': mpaa, 'tvshowtitle': show_title, 'imdbnumber': imdb_id, 'votes': votes, 'season': season_number, 'playcount': playcount, 'overlay': overlay }) set_property('watchedepisodes', string(watched)) set_property('unwatchedepisodes', string(unwatched)) set_property('totalepisodes', string(episode_count)) if is_widget: set_property('fen_widget', 'true') set_property('fen_playcount', string(playcount)) set_property('fen_extras_menu_params', extras_params) set_property('fen_options_menu_params', options_params) else: set_property('fen_widget', 'false') yield (url_params, listitem, True) except: pass __handle__ = int(argv[1]) meta_user_info = metadata.retrieve_user_info() watched_indicators = settings.watched_indicators() watched_info = get_watched_info_tv(watched_indicators) show_unaired = settings.show_unaired() is_widget = kodi_utils.external_browse() current_date = get_datetime() image_resolution = meta_user_info['image_resolution']['poster'] poster_main, poster_backup, fanart_main, fanart_backup = settings.get_art_provider( ) meta = metadata.tvshow_meta('tmdb_id', params['tmdb_id'], meta_user_info) meta_get = meta.get season_data = meta_get('season_data') if not season_data: return tmdb_id, tvdb_id, imdb_id = meta_get('tmdb_id'), meta_get( 'tvdb_id'), meta_get('imdb_id') show_title, show_year, show_plot, banner = meta_get('title'), meta_get( 'year'), meta_get('plot'), meta_get('banner') show_poster = meta_get(poster_main) or meta_get( poster_backup) or poster_empty fanart = meta_get(fanart_main) or meta_get(fanart_backup) or fanart_empty clearlogo, clearart, landscape = meta_get('clearlogo'), meta_get( 'clearart'), meta_get('landscape') cast, mpaa, votes = meta_get('cast'), meta_get('mpaa'), meta_get('votes') trailer, genre, studio = string( meta_get('trailer')), meta_get('genre'), meta_get('studio') episode_run_time, rating, premiered = meta_get( 'episode_run_time'), meta_get('rating'), meta_get('premiered') total_seasons = meta_get('total_seasons') total_aired_eps = meta_get('total_aired_eps') if not settings.show_specials(): season_data = [i for i in season_data if not i['season_number'] == 0] season_data.sort(key=lambda k: k['season_number']) use_season_title = settings.use_season_title() watched_title = 'Trakt' if watched_indicators == 1 else 'Fen' kodi_utils.add_items(__handle__, list(_process())) kodi_utils.set_content(__handle__, 'seasons') kodi_utils.end_directory(__handle__) kodi_utils.set_view_mode('view.seasons', 'seasons')