def build_add_to_remove_from_list(meta='', media_type='', orig_mode='', from_search=''): from urlparse import parse_qsl import json from resources.lib.modules.nav_utils import build_url from resources.lib.modules.settings import watched_indicators params = dict(parse_qsl(sys.argv[2].replace('?',''))) media_type = params.get('media_type', '') orig_mode = params.get('orig_mode', '') from_search = params.get('from_search', '') meta = json.loads(params.get('meta', None)) main_listing = [('Add to...', 'add'), ('Remove from...', 'remove')] mlc = selection_dialog([i[0] for i in main_listing], [i[1] for i in main_listing], 'Choose Add to or Remove from...') if mlc == None: return string = "Choose Selection to Add Item To" if mlc == 'add' else "Choose Selection to Remove Item From" heading = 'Add to ' if mlc == 'add' else 'Remove from ' listing = [(heading + 'Trakt List', 'trakt'), (heading + 'Fen Favourites', 'favourites'), (heading + 'Fen Subscriptions', 'subscriptions')] if media_type == 'tvshow' and watched_indicators() == 0: listing.append((heading + 'Fen Next Episode', 'unwatched_next_episode')) if mlc == 'remove': listing.append((heading + 'Cache (Re-cache %s Info)' % ('Movie' if media_type == 'movie' else 'TV Show'), 'refresh')) if mlc == 'remove' and watched_indicators() == 1: listing.append(('Remove Fen/Trakt Watched Sync (ReSync Watched Info)', 'resync')) choice = selection_dialog([i[0] for i in listing], [i[1] for i in listing], string) if choice == None: return elif choice == 'trakt': url = {'mode': ('trakt.trakt_add_to_list' if mlc == 'add' else 'trakt.trakt_remove_from_list'), 'tmdb_id': meta["tmdb_id"], 'imdb_id': meta["imdb_id"], 'db_type': media_type} elif choice == 'favourites': url = {'mode': ('add_to_favourites' if mlc == 'add' else 'remove_from_favourites'), 'db_type': media_type, 'tmdb_id': meta["tmdb_id"], 'title': meta['title']} elif choice == 'subscriptions': url = {'mode': 'subscriptions_add_remove', 'action': mlc, 'db_type': media_type, 'tmdb_id': meta["tmdb_id"], 'orig_mode': orig_mode} elif choice == 'unwatched_next_episode': url = {'mode': 'add_next_episode_unwatched', 'action': mlc, 'title': meta["title"], 'tmdb_id': meta["tmdb_id"], 'imdb_id': meta["imdb_id"]} elif choice == 'refresh': url = {'mode': 'refresh_cached_data', 'db_type': media_type, 'id_type': 'tmdb_id', 'media_id': meta['tmdb_id']} elif choice == 'resync': url = {'mode': 'trakt_sync_watched_to_fen', 'refresh': True} xbmc.executebuiltin('XBMC.RunPlugin(%s)' % build_url(url))
def next_episode_context_choice(): from urlparse import parse_qsl from resources.lib.modules.utils import selection_dialog from resources.lib.modules.nav_utils import toggle_setting, build_url import settings params = dict(parse_qsl(sys.argv[2].replace('?',''))) content_settings = settings.nextep_content_settings() display_settings = settings.nextep_display_settings() force_display_status = str(display_settings['force_display']) toggle_force_display_SETTING = ('nextep.force_display', ('true' if force_display_status == 'False' else 'false')) airdate_replacement = [('%d-%m-%Y', 'Day-Month-Year'), ('%Y-%m-%d', 'Year-Month-Day'), ('%m-%d-%Y', 'Month-Day-Year')] sort_type_status = ('Recently Watched', 'Airdate', 'Title')[content_settings['sort_type']] sort_order_status = ('Descending', 'Ascending')[content_settings['sort_order']] toggle_sort_order_SETTING = ('nextep.sort_order', ('0' if sort_order_status == 'Ascending' else '1')) unaired_status = str(content_settings['include_unaired']) toggle_unaired_SETTING = ('nextep.include_unaired', ('true' if unaired_status == 'False' else 'false')) unwatched_status = str(content_settings['include_unwatched']) toggle_unwatched_SETTING = ('nextep.include_unwatched', ('true' if unwatched_status == 'False' else 'false')) airdate_status = str(display_settings['include_airdate']) toggle_airdate_SETTING = ('nextep.include_airdate', ('true' if airdate_status == 'False' else 'false')) airdate_format = settings.nextep_airdate_format() airdate_format_status = [airdate_format.replace(i[0], i[1]) for i in airdate_replacement if i[0] == airdate_format][0] airdate_highlight = display_settings['airdate_colour'].capitalize() unaired_highlight = display_settings['unaired_colour'].capitalize() unwatched_highlight = display_settings['unwatched_colour'].capitalize() choices = [ ('MANAGE IN PROGRESS SHOWS', 'manage_in_progress'), ('SORT TYPE: [I]Currently [B]%s[/B][/I]' % sort_type_status, 'Sort Type'), ('SORT ORDER: [I]Currently [B]%s[/B][/I]' % sort_order_status, 'toggle_sort_order'), ('INCLUDE UNAIRED EPISODES: [I]Currently [B]%s[/B][/I]' % unaired_status, 'toggle_unaired'), ('INCLUDE WATCHLIST/UNWATCHED TV: [I]Currently [B]%s[/B][/I]' % unwatched_status, 'toggle_unwatched'), ('INCLUDE AIRDATE: [I]Currently [B]%s[/B][/I]' % airdate_status, 'toggle_airdate'), ('ATTEMPT TO MAKE SKIN HONOR FULL LABEL: [I]Currently [B]%s[/B][/I]' % force_display_status, 'toggle_force_display'), ('AIRDATE FORMAT: [I]Currently [B]%s[/B][/I]' % airdate_format_status, 'Airdate Format'), ('AIRDATE HIGHLIGHT: [I]Currently [B]%s[/B][/I]' % airdate_highlight, 'Airdate'), ('UNAIRED HIGHLIGHT: [I]Currently [B]%s[/B][/I]' % unaired_highlight, 'Unaired'), ('UNWATCHED HIGHLIGHT: [I]Currently [B]%s[/B][/I]' % unwatched_highlight, 'Unwatched')] if settings.watched_indicators() == 0: choices.append(('MANAGE UNWATCHED TV SHOWS', 'manage_unwatched')) if settings.watched_indicators() in (1,2): choices.append(('CLEAR TRAKT CACHE', 'clear_cache')) string = 'Next Episode Manager' dialog_list = [i[0] for i in choices] function_list = [i[1] for i in choices] choice = selection_dialog(dialog_list, function_list, string) if not choice: return if choice in ('toggle_sort_order', 'toggle_unaired', 'toggle_unwatched', 'toggle_airdate', 'toggle_force_display'): setting = eval(choice + '_SETTING') toggle_setting(setting[0], setting[1]) elif choice == 'clear_cache': from resources.lib.modules.nav_utils import clear_cache clear_cache('trakt') else: if choice in ('manage_in_progress', 'manage_unwatched'): xbmc.executebuiltin('XBMC.Container.Update(%s)' % build_url({'mode': 'build_next_episode_manager', 'action': choice})); return elif choice in ('Airdate','Unaired', 'Unwatched'): function = next_episode_color_choice else: function = next_episode_options_choice function(choice) xbmc.executebuiltin("Container.Refresh") xbmc.executebuiltin('RunPlugin(%s)' % build_url({'mode': 'next_episode_context_choice'}))
def playback_menu(from_results=False, suggestion=None): from urlparse import parse_qsl from resources.lib.modules.nav_utils import toggle_setting, build_url, open_settings, clear_cache from resources.lib.modules import settings content = xbmc.getInfoLabel('Container.Content') params = dict(parse_qsl(sys.argv[2].replace('?',''))) from_results = params.get('from_results', from_results) suggestion = params.get('suggestion', suggestion) autoplay_status, autoplay_toggle, filter_setting = ('On', 'false', 'autoplay_quality') if settings.auto_play() else ('Off', 'true', 'results_quality') autoplay_next_status, autoplay_next_toggle = ('On', 'false') if settings.autoplay_next_episode() else ('Off', 'true') results_display_status, results_display_toggle = ('Dialog', '0') if settings.use_dialog() else ('Directory', '1') prefer_hevc_status, prefer_hevc_toggle = ('On', 'false') if settings.prefer_hevc() else ('Off', 'true') auto_resolve_status, auto_resolve_toggle = ('On', 'false') if settings.auto_resolve() else ('Off', 'true') active_scrapers = settings.active_scrapers() current_scrapers_status = ', '.join([i.capitalize() for i in active_scrapers]) if len(active_scrapers) >= 1 else 'None Active' current_filter_status = ', '.join(settings.quality_filter(filter_setting)) indicators_status, indicators_toggle = ('Trakt', '0') if settings.watched_indicators() in (1, 2) else ('Fen', '1') string = 'Please choose Fen Setting to Change...' listing = [('AUTOPLAY: [I]Currently [B]%s[/B][/I]' % autoplay_status, 'toggle_autoplay')] if autoplay_status == 'On': listing += [('PREFER HEVC IN AUTOPLAY: [I]Currently [B]%s[/B][/I]' % prefer_hevc_status, 'toggle_prefer_hevc')] listing += [('AUTOPLAY NEXT EPISODE: [I]Currently [B]%s[/B][/I]' % autoplay_next_status, 'toggle_autoplay_next')] listing += [('ENABLE SCRAPERS: [I]Currently [B]%s[/B][/I]' % current_scrapers_status, 'enable_scrapers')] if autoplay_status == 'Off': listing += [('DISPLAY RESULTS: [I]Currently [B]%s[/B][/I]' % results_display_status, 'toggle_display_results')] listing += [('AUTO RESOLVE FURK PACKS: [I]Currently [B]%s[/B][/I]' % auto_resolve_status, 'toggle_auto_resolve')] listing += [('QUALITY FILTERS: [I]Currently [B]%s[/B][/I]' % current_filter_status, 'set_filters')] listing += [('SWITCH INDICATOR PROVIDER: [I]Currently [B]%s[/B][/I]' % indicators_status, 'toggle_indicators')] if settings.watched_indicators() in (1,2): listing += [('CLEAR TRAKT CACHE', 'clear_trakt_cache')] if content in ('movies', 'episodes'): listing += [('FURK/EASYNEWS SEARCH: [B][I]%s[/I][/B]' % params.get('suggestion', ''), 'search_directly')] listing += [('OPEN EXTERNAL SCRAPER SETTINGS', 'open_scraper_settings')] listing += [('OPEN FEN SETTINGS', 'open_fen_settings')] listing += [('[B]SAVE SETTINGS AND EXIT[/B]', 'save_and_exit')] xbmc.sleep(500) choice = selection_dialog([i[0] for i in listing], [i[1] for i in listing], string) if choice == 'toggle_autoplay': toggle_setting('auto_play', autoplay_toggle) elif choice == 'toggle_prefer_hevc': toggle_setting('prefer_hevc', prefer_hevc_toggle) elif choice == 'toggle_autoplay_next': toggle_setting('autoplay_next_episode', autoplay_next_toggle) elif choice == 'enable_scrapers': enable_scrapers() elif choice == 'toggle_display_results': toggle_setting('use_dialog', results_display_toggle) elif choice == 'toggle_auto_resolve': toggle_setting('auto_resolve', auto_resolve_toggle) elif choice == 'set_filters': set_autoplay_quality(action=True) if autoplay_status == 'On' else set_results_quality(action=True) elif choice == 'toggle_indicators': toggle_setting('watched_indicators', indicators_toggle) elif choice == 'clear_trakt_cache': clear_cache('trakt') elif choice == 'search_directly': furk_easynews_direct_search_choice(suggestion, from_results) elif choice == 'open_scraper_settings': xbmc.executebuiltin('Addon.OpenSettings(%s)' % 'script.module.tikiscrapers') elif choice == 'open_fen_settings': open_settings('0.0') if choice in ('toggle_indicators', 'clear_trakt_cache') and content in ('movies', 'tvshows', 'seasons', 'episodes'): xbmc.executebuiltin('Container.Refresh') if choice in (None, 'save_and_exit', 'toggle_indicators', 'clear_trakt_cache', 'search_directly', 'open_scraper_settings', 'open_fen_settings'): return xbmc.executebuiltin('RunPlugin(%s)' % build_url({'mode': 'playback_menu', 'from_results': from_results, 'suggestion': suggestion}))
def get_watched_status(db_type, media_id, season='', episode=''): try: if settings.watched_indicators() in (1, 2): if db_type == 'movie': from resources.lib.modules.trakt import trakt_indicators_movies watched = [i[0] for i in trakt_indicators_movies()] if media_id in watched: return 1, 7 return 0, 6 else: from resources.lib.modules.trakt import trakt_indicators_tv watched = trakt_indicators_tv() watched = [i[2] for i in watched if i[0] == media_id] if watched: watched = [ i for i in watched[0] if i[0] == season and i[1] == episode ] if watched: return 1, 7 return 0, 6 else: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute( "SELECT * FROM watched_status WHERE (db_type = ? and media_id = ? and season = ? and episode = ?)", (db_type, media_id, season, episode)) watched = dbcur.fetchone() dbcon.close() if watched: return 1, 7 else: return 0, 6 except: return 0, 6
def process_eps(item, ne_settings, ne_display): meta = make_fresh_tvshow_meta('tmdb_id', item['tmdb_id']) include_unaired = ne_settings['include_unaired'] try: if settings.watched_indicators() in (1, 2): resformat = "%Y-%m-%dT%H:%M:%S.%fZ" unwatched = item.get('unwatched', False) curr_last_played = item.get('last_played', '2000-01-01T00:00:00.000Z') season = item['season'] episode = item['episode'] season_info = [i for i in meta['season_data'] if i['season_number'] == item['season']][0] season = season if episode < season_info['episode_count'] else season_info['season_number'] + 1 episode = episode + 1 if episode < season_info['episode_count'] else 1 else: resformat = "%Y-%m-%d %H:%M:%S" unwatched = item.get('unwatched', False) curr_last_played = item.get('last_played', '2000-01-01 00:00:00') season_info = [i for i in meta['season_data'] if i['season_number'] == item['season']][0] season = item['season'] if item['episode'] < season_info['episode_count'] else season_info['season_number'] + 1 episode = item['episode'] + 1 if item['episode'] < season_info['episode_count'] else 1 try: datetime_object = datetime.strptime(curr_last_played, resformat) except TypeError: datetime_object = datetime(*(time.strptime(curr_last_played, resformat)[0:6])) result.append(build_episode({"season": season, "episode": episode, "meta": meta, "curr_last_played_parsed": datetime_object, "action": "next_episode", "unwatched": unwatched, "ne_display": ne_display, 'include_unaired': include_unaired})) except: pass
def worker(self): threads = [] self.watched_indicators = settings.watched_indicators() self.all_trailers = settings.all_trailers() for item_position, item in enumerate(self.list): threads.append(workers.Thread(self.set_info, item_position, item)) [i.start() for i in threads] [i.join() for i in threads] self.build_movie_content()
def get_watched_status_tvshow(media_id, aired_eps): playcount, overlay = 0, 6 watched, unwatched = 0, aired_eps def get_playcount_overlay(use_trakt): try: if use_trakt: watched = [ i for i in watched_info if i[0] == media_id and i[1] == len(i[2]) ] if watched: playcount, overlay = 1, 7 else: if watched_info == aired_eps and not aired_eps == 0: playcount, overlay = 1, 7 except: pass return playcount, overlay def get_watched_episode_totals(use_trakt): try: if use_trakt: watched = len([i[2] for i in watched_info if i[0] == media_id][0]) unwatched = aired_eps - watched else: watched = watched_info unwatched = aired_eps - watched except: pass return watched, unwatched try: if settings.watched_indicators() in (1, 2): from resources.lib.modules.trakt import trakt_indicators_tv use_trakt = True watched_info = trakt_indicators_tv() else: use_trakt = False settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute( "SELECT * FROM watched_status WHERE (db_type = ? and media_id = ?)", ('episode', media_id)) watched_info = len(dbcur.fetchall()) dbcon.close() watched, unwatched = get_watched_episode_totals(use_trakt) playcount, overlay = get_playcount_overlay(use_trakt) except: pass return playcount, overlay, watched, unwatched
def get_unwatched_next_episodes(): try: if settings.watched_indicators() in (1, 2): from resources.lib.modules.trakt import call_trakt, get_trakt_tvshow_id data = call_trakt("sync/watchlist/shows?extended=full", method='sort_by_headers') return [{"tmdb_id": get_trakt_tvshow_id(i), "season": 1, "episode": 0, "unwatched": True} for i in data] else: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute('''SELECT media_id FROM unwatched_next_episode''') unwatched = dbcur.fetchall() return [{"tmdb_id": i[0], "season": 1, "episode": 0, "unwatched": True} for i in unwatched] except: return []
def build_next_episode(): sync_watched_trakt_to_fen() try: threads = [] seen = set() ep_list = [] ne_settings = settings.nextep_content_settings() ne_display = settings.nextep_display_settings() if ne_settings['include_unwatched']: for i in get_unwatched_next_episodes(): ep_list.append(i) if settings.watched_indicators() in (1, 2): from resources.lib.modules.trakt import trakt_get_next_episodes info = trakt_get_next_episodes() for item in info: try: ep_list.append({"tmdb_id": get_trakt_tvshow_id(item), "season": item['season'], "episode": item['number'], "last_played": item['show']['last_watched_at']}) except: pass else: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute('''SELECT media_id, season, episode, last_played FROM watched_status WHERE db_type=?''', ('episode',)) rows = dbcur.fetchall() rows = sorted(rows, key = lambda x: (x[0], x[1], x[2]), reverse=True) [ep_list.append({"tmdb_id": a, "season": int(b), "episode": int(c), "last_played": d}) for a, b, c, d in rows if not (a in seen or seen.add(a))] ep_list = [x for x in ep_list if x['tmdb_id'] not in check_for_next_episode_excludes()] ep_list = [i for i in ep_list if not i['tmdb_id'] == None] for item in ep_list: threads.append(Thread(process_eps, item, ne_settings, ne_display)) [i.start() for i in threads] [i.join() for i in threads] r = [i for i in result if i is not None] r = sort_next_eps(r, ne_settings) listitems = [i['listitem'] for i in r] xbmcplugin.addDirectoryItems(__handle__, listitems, len(listitems)) xbmcplugin.setContent(__handle__, 'episodes') xbmcplugin.endOfDirectory(__handle__) setView('view.progress_next_episode') except: from resources.lib.modules.nav_utils import notification notification('Error getting Next Episode Info', time=3500) pass
def mark_movie_as_watched_unwatched(params=None): params = dict(parse_qsl(sys.argv[2].replace('?', ''))) if not params else params action = params.get('action') db_type = 'movie' media_id = params.get('media_id') title = params.get('title') year = params.get('year') from_search = params.get('from_search', 'false') watched_indicators = settings.watched_indicators() if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'movies', media_id) clear_trakt_watched_data(db_type) erase_bookmark(db_type, media_id) if watched_indicators in (0, 1): mark_as_watched_unwatched(db_type, media_id, action, title=title) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library(db_type, action, title, year) refresh_container(from_search)
def mark_episode_as_watched_unwatched(params=None): from resources.lib.modules.next_episode import add_next_episode_unwatched params = dict(parse_qsl(sys.argv[2].replace('?', ''))) if not params else params action = 'mark_as_watched' if params.get( 'action') == 'mark_as_watched' else 'mark_as_unwatched' media_id = params.get('media_id') tvdb_id = int(params.get('tvdb_id', '0')) imdb_id = params.get('imdb_id') season = int(params.get('season')) episode = int(params.get('episode')) title = params.get('title') year = params.get('year') from_search = params.get('from_search', 'false') watched_indicators = settings.watched_indicators() if season == 0: from resources.lib.modules.nav_utils import notification notification( 'Specials cannot be marked as %s' % ('Watched' if action == 'mark_as_watched' else 'Unwatched'), time=5000) return if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'episode', imdb_id, tvdb_id, season, episode) clear_trakt_watched_data('tvshow', imdb_id) erase_bookmark('episode', media_id, season, episode) if watched_indicators in (0, 1): mark_as_watched_unwatched('episode', media_id, action, season, episode, title) if action == 'mark_as_watched': add_next_episode_unwatched('remove', media_id, silent=True) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library('episode', action, title, year, season, episode) refresh_container(from_search)
def build_season_list(): params = dict(parse_qsl(sys.argv[2].replace('?', ''))) meta = json.loads( params.get('meta')) if 'meta' in params else tikimeta.tvshow_meta( 'tmdb_id', params.get('tmdb_id')) show_specials = settings.show_specials() use_season_title = settings.use_season_title() season_data = [i for i in meta['season_data'] if i['season_number'] > 0 ] if not show_specials else meta['season_data'] watched_indicators = settings.watched_indicators() for item in season_data: try: cm = [] plot = item['overview'] if item['overview'] != '' else meta['plot'] title = item['name'] if use_season_title else 'Season %s' % str( item['season_number']) season_poster = "http://image.tmdb.org/t/p/original%s" % item[ 'poster_path'] if item['poster_path'] is not None else meta[ 'poster'] aired_episodes = aired_episode_number_season( meta, item['season_number']) playcount, overlay, watched, unwatched = get_watched_status_season( meta['tmdb_id'], item['season_number'], aired_episodes) watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen" watched_params = { "mode": "mark_season_as_watched_unwatched", "action": 'mark_as_watched', "title": meta['title'], "year": meta['year'], "media_id": meta['tmdb_id'], "imdb_id": meta["imdb_id"], "tvdb_id": meta["tvdb_id"], "season": item['season_number'] } unwatched_params = { "mode": "mark_season_as_watched_unwatched", "action": 'mark_as_unwatched', "title": meta['title'], "year": meta['year'], "media_id": meta['tmdb_id'], "imdb_id": meta["imdb_id"], "tvdb_id": meta["tvdb_id"], "season": item['season_number'] } playback_menu_params = {'mode': 'playback_menu'} cm.append(("[B]Mark Watched %s[/B]" % watched_title, 'XBMC.RunPlugin(%s)' % build_url(watched_params))) cm.append(("[B]Mark Unwatched %s[/B]" % watched_title, 'XBMC.RunPlugin(%s)' % build_url(unwatched_params))) cm.append(("[B]Options[/B]", 'XBMC.RunPlugin(%s)' % build_url(playback_menu_params))) cm.append( ("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % meta['tmdb_id'])) url_params = { 'mode': 'build_episode_list', 'tmdb_id': meta['tmdb_id'], 'season': str(item['season_number']), 'season_id': item['id'] } url = build_url(url_params) listitem = xbmcgui.ListItem(title) listitem.setProperty('watchedepisodes', str(watched)) listitem.setProperty('unwatchedepisodes', str(unwatched)) listitem.setProperty('totalepisodes', str(item['episode_count'])) listitem.addContextMenuItems(cm) listitem.setArt({ 'poster': season_poster, 'fanart': meta['fanart'], 'banner': meta['banner'], 'clearlogo': meta['clearlogo'], 'landscape': meta['landscape'] }) listitem.setCast(meta['cast']) listitem.setInfo( 'video', { 'mediatype': 'tvshow', 'trailer': str(meta['trailer']), 'title': meta.get('title'), 'size': '0', 'duration': meta.get('episode_run_time'), 'plot': plot, 'rating': meta.get('rating'), 'premiered': meta.get('premiered'), 'studio': meta.get('studio'), 'year': meta.get('year'), 'genre': meta.get('genre'), 'code': meta.get('imdb_id'), 'tvshowtitle': meta.get('title'), 'imdbnumber': meta.get('imdb_id'), 'votes': meta.get('votes'), 'episode': str(item['episode_count']), 'playcount': playcount, 'overlay': overlay }) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'seasons') xbmcplugin.endOfDirectory(__handle__) setView('view.seasons') window.setProperty('fen_media_meta', json.dumps(meta))
def build_next_episode_manager(): from urlparse import parse_qsl from resources.lib.indexers.tvshows import aired_episode_number_tvshow from resources.lib.modules.nav_utils import add_dir from resources.lib.modules.indicators_bookmarks import get_watched_status_tvshow params = dict(parse_qsl(sys.argv[2].replace('?',''))) NEXT_EP_UNWATCHED = __addon__.getSetting('nextep.unwatched_colour') if not NEXT_EP_UNWATCHED or NEXT_EP_UNWATCHED == '': NEXT_EP_UNWATCHED = 'red' VIEW_NEM = __addon__.getSetting('view.main') sorted_list = [] action = params['action'] if action == 'manage_unwatched': tmdb_list = [i['tmdb_id'] for i in get_unwatched_next_episodes()] heading = 'Select Show to remove from Fen Next Episode:' elif settings.watched_indicators() in (1, 2): from resources.lib.modules.trakt import trakt_get_next_episodes tmdb_list, exclude_list = trakt_get_next_episodes(include_hidden=True) heading = 'Select Show to Hide/Unhide from Trakt Progress:' else: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute('''SELECT media_id FROM watched_status WHERE db_type=? GROUP BY media_id''', ('episode',)) rows = dbcur.fetchall() tmdb_list = [row[0] for row in rows] exclude_list = check_for_next_episode_excludes() heading = 'Select Show to Include/Exclude in Fen Next Episode:' add_dir({'mode': 'nill'}, '[I][COLOR=grey][B]INFO:[/B][/COLOR] [COLOR=grey2]%s[/COLOR][/I]' % heading, iconImage='settings.png') if not tmdb_list: from resources.lib.modules.nav_utils import notification notification('No Shows Present', time=5000) else: for tmdb_id in tmdb_list: try: meta = make_fresh_tvshow_meta('tmdb_id', tmdb_id) if action == 'manage_unwatched': action, display = 'remove', '[COLOR=%s][UNWATCHED][/COLOR] %s' % (NEXT_EP_UNWATCHED, meta['title']) url_params = {'mode': 'add_next_episode_unwatched', 'action': 'remove', 'tmdb_id': meta['tmdb_id'], 'title': meta['title']} elif settings.watched_indicators() in (1, 2): action, display = 'unhide' if str(meta['tmdb_id']) in exclude_list else 'hide', '[COLOR=red][EXCLUDED][/COLOR] %s' % meta['title'] if str(meta['tmdb_id']) in exclude_list else '[COLOR=green][INCLUDED][/COLOR] %s' % meta['title'] url_params = {"mode": "hide_unhide_trakt_items", "action": action, "media_type": "shows", "media_id": meta['imdb_id'], "section": "progress_watched"} else: action, display = 'remove' if str(meta['tmdb_id']) in exclude_list else 'add', '[COLOR=red][EXCLUDED][/COLOR] %s' % meta['title'] if str(meta['tmdb_id']) in exclude_list else '[COLOR=green][INCLUDED][/COLOR] %s' % meta['title'] url_params = {'mode': 'add_to_remove_from_next_episode_excludes', 'action': action, 'title': meta['title'], 'media_id': meta['tmdb_id']} sorted_list.append({'tmdb_id': tmdb_id, 'display': display, 'url_params': url_params, 'meta': json.dumps(meta)}) except: pass sorted_items = sorted(sorted_list, key=lambda k: k['display']) for i in sorted_items: try: cm = [] meta = json.loads(i['meta']) rootname = meta['title'] + " (" + str(meta['year']) + ")" meta['rootname'] = rootname aired_episodes = aired_episode_number_tvshow(meta) playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(meta['tmdb_id'], aired_episodes) url = build_url(i['url_params']) browse_url = build_url({'mode': 'build_season_list', 'meta': i['meta']}) cm.append(("[B]Browse...[/B]",'XBMC.Container.Update(%s)' % browse_url)) listitem = xbmcgui.ListItem(i['display']) listitem.setProperty('watchedepisodes', str(total_watched)) listitem.setProperty('unwatchedepisodes', str(total_unwatched)) listitem.setProperty('totalepisodes', str(aired_episodes)) listitem.setProperty('totalseasons', str(meta['number_of_seasons'])) listitem.addContextMenuItems(cm) listitem.setArt({'poster': meta['poster'], 'fanart': meta['fanart'], 'banner': meta['banner'], 'clearart': meta['clearart'], 'clearlogo': meta['clearlogo'], 'landscape': meta['landscape']}) listitem.setCast(meta['cast']) listitem.setInfo( 'video', { 'title': meta['title'], 'size': '0', 'duration': meta['duration'], 'plot': meta['plot'], 'rating': meta['rating'], 'premiered': meta['premiered'], 'studio': meta['studio'],'year': meta['year'], 'genre': meta['genre'],'imdbnumber': meta['imdb_id'], 'votes': meta['votes'], 'playcount': playcount, 'overlay': overlay}) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'tvshows') xbmcplugin.endOfDirectory(__handle__, cacheToDisc=False) setView(VIEW_NEM)
def mark_season_as_watched_unwatched(): from resources.lib.modules.next_episode import add_next_episode_unwatched params = dict(parse_qsl(sys.argv[2].replace('?', ''))) action = 'mark_as_watched' if params.get( 'action') == 'mark_as_watched' else 'mark_as_unwatched' season = int(params.get('season')) title = params.get('title') year = params.get('year') media_id = params.get('media_id') tvdb_id = int(params.get('tvdb_id', '0')) imdb_id = params.get('imdb_id') watched_indicators = settings.watched_indicators() if season == 0: from resources.lib.modules.nav_utils import notification notification( 'Specials cannot be marked as %s' % ('Watched' if action == 'mark_as_watched' else 'Unwatched'), time=5000) return if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'season', imdb_id, tvdb_id, season) clear_trakt_watched_data('tvshow', imdb_id) if watched_indicators in (0, 1): import tikimeta bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', '') infoLabels = tikimeta.season_episodes_meta(media_id, season) ep_data = infoLabels['episodes'] count = 1 se_list = [] for item in ep_data: season_number = item['season_number'] ep_number = item['episode_number'] season_ep = '%.2d<>%.2d' % (season_number, ep_number) display = 'Updating - S%.2dE%.2d' % (season_number, ep_number) try: first_aired = item['air_date'] d = first_aired.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) except: episode_date = date(2100, 10, 24) if not settings.adjusted_datetime() > episode_date: continue display = 'Updating - S%.2dE%.2d' % (season_number, ep_number) bg_dialog.update(int(float(count) / float(len(ep_data)) * 100), 'Please Wait', '%s' % display) count += 1 mark_as_watched_unwatched('episode', media_id, action, season_number, ep_number, title) se_list.append(season_ep) bg_dialog.close() if action == 'mark_as_watched': add_next_episode_unwatched('remove', media_id, silent=True) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import get_library_video, batch_mark_episodes_as_watched_unwatched_kodi_library in_library = get_library_video('tvshow', title, year) if not in_library: xbmc.executebuiltin("Container.Refresh") return ep_dict = { 'action': action, 'tvshowid': in_library['tvshowid'], 'season_ep_list': se_list } if batch_mark_episodes_as_watched_unwatched_kodi_library( in_library, ep_dict): from resources.lib.modules.nav_utils import notification notification('Kodi Library Sync Complete', time=5000) refresh_container()
def build_movie_content(self): watched_indicators = settings.watched_indicators() all_trailers = settings.all_trailers() for i in sorted(self.items, key=lambda k: k['item_no']): try: cm = [] if not 'rootname' in i: i['rootname'] = '{0} ({1})'.format(i['title'], i['year']) meta_json = json.dumps(i) url_params = { 'mode': 'play_media', 'vid_type': 'movie', 'query': i['rootname'], 'tmdb_id': i['tmdb_id'], 'meta': meta_json } url = build_url(url_params) from_search = 'true' if self.action in ( 'tmdb_movies_search', 'tmdb_movies_people_search') else 'false' playback_params = { 'mode': 'playback_menu', 'suggestion': i['rootname'] } hide_recommended_params = { 'mode': 'trakt.hide_recommendations', 'db_type': 'movies', 'imdb_id': i['imdb_id'] } watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen" (state, action) = ('Watched', 'mark_as_watched') if i['playcount'] == 0 else ( 'Unwatched', 'mark_as_unwatched') (state2, action2) = ('Watched', 'mark_as_watched') if state == 'Unwatched' else ( 'Unwatched', 'mark_as_unwatched') watched_unwatched_params = { "mode": "mark_movie_as_watched_unwatched", "action": action, "media_id": i['tmdb_id'], "from_search": from_search, "title": i['title'], "year": i['year'] } add_remove_params = { "mode": "build_add_to_remove_from_list", "meta": meta_json, "media_type": "movie", "from_search": from_search, "orig_mode": self.action } sim_rel_params = { "mode": "similar_related_choice", "db_type": "movies", "tmdb_id": i['tmdb_id'], "imdb_id": i['imdb_id'], "from_search": from_search } (trailer_params, trailer_title) = ( { 'mode': 'play_trailer', 'url': i['trailer'], 'all_trailers': json.dumps(i['all_trailers']) }, 'Choose Trailer') if (all_trailers and i.get( 'all_trailers', False)) else ({ 'mode': 'play_trailer', 'url': i['trailer'] }, 'Trailer') exit_list_params = { "mode": "navigator.main", "action": "MovieList" } listitem = xbmcgui.ListItem(i['title']) listitem.setProperty("resumetime", get_resumetime('movie', i['tmdb_id'])) cm.append(("[B]Mark %s %s[/B]" % (state, watched_title), "XBMC.RunPlugin(%s)" % build_url(watched_unwatched_params))) if listitem.getProperty("resumetime") != '0.000000': cm.append(("[B]Mark %s %s[/B]" % (state2, watched_title), 'XBMC.RunPlugin(%s)' % build_url({ "mode": "mark_movie_as_watched_unwatched", "action": action2, "media_id": i['tmdb_id'], "from_search": from_search, "title": i['title'], "year": i['year'] }))) cm.append(("[B]Options[/B]", "XBMC.RunPlugin(%s)" % build_url(playback_params))) cm.append( ("[B]Add/Remove[/B]", "XBMC.RunPlugin(%s)" % build_url(add_remove_params))) cm.append(("[B]Similar/Related[/B]", "XBMC.RunPlugin(%s)" % build_url(sim_rel_params))) if i['trailer']: cm.append( ("[B]%s[/B]" % trailer_title, "XBMC.RunPlugin(%s)" % build_url(trailer_params))) if self.action == 'trakt_recommendations': cm.append(("[B]Hide from Recommendations[/B]", "XBMC.RunPlugin(%s)" % build_url(hide_recommended_params))) cm.append( ("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedinfo,id=%s)' % i['tmdb_id'])) cm.append( ("[B]Exit Movie List[/B]", "XBMC.Container.Refresh(%s)" % build_url(exit_list_params))) listitem.addContextMenuItems(cm) listitem.setCast(i['cast']) listitem.setArt({ 'poster': i['poster'], 'fanart': i['fanart'], 'banner': i['banner'], 'clearlogo': i['clearlogo'], 'landscape': i['landscape'] }) listitem.setInfo('Video', remove_unwanted_info_keys(i)) if not not_widget: listitem.setProperty("fen_widget", 'true') listitem.setProperty("fen_playcount", str(i['playcount'])) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=False) except: pass
def build_episode(item): from resources.lib.modules.utils import make_day def check_for_unaired(): try: d = first_aired.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) except: episode_date = None current_adjusted_date = settings.adjusted_datetime() unaired = False if not episode_date or current_adjusted_date < episode_date: unaired = True return unaired def build_display(): if display_info: display_first_aired = make_day(first_aired) airdate = '[[COLOR=%s]%s[/COLOR]] ' % ( display_info['airdate_colour'], display_first_aired) if display_info['include_airdate'] else '' highlight_color = display_info['unwatched_colour'] if item.get( 'unwatched', False) else display_info['unaired_colour'] if unaired else '' italics_open, italics_close = ('[I]', '[/I]') if highlight_color else ('', '') episode_info = '%s[COLOR=%s]%dx%.2d - %s[/COLOR]%s' % ( italics_open, highlight_color, info['season_number'], info['episode_number'], info['name'], italics_close) display = '%s%s: %s' % (airdate, meta['title'], episode_info) tvshow_display = display if display_info[ 'force_display'] else meta['title'] else: display = '%s: %dx%.2d - %s' % (meta['title'].upper( ), info['season_number'], info['episode_number'], info['name']) tvshow_display = meta['title'] return display, tvshow_display try: display_info = item.get('ne_display', None) thumb_path = 'http://image.tmdb.org/t/p/original%s' cm = [] watched_indicators = settings.watched_indicators() action = item.get('action', '') meta = item['meta'] info = [ i for i in tikimeta.season_episodes_meta( meta['tmdb_id'], item['season'])['episodes'] if i['episode_number'] == item['episode'] ][0] first_aired = info['air_date'] unaired = check_for_unaired() if unaired and not item.get('include_unaired', False): return guest_stars = get_guest_stars(info['guest_stars']) writer = ', '.join( [i['name'] for i in info['crew'] if i['job'] == 'Writer']) director = ', '.join( [i['name'] for i in info['crew'] if i['job'] == 'Director']) thumb = thumb_path % info['still_path'] if info.get( 'still_path', None) != None else meta['fanart'] playcount, overlay = get_watched_status('episode', meta['tmdb_id'], info['season_number'], info['episode_number']) query = meta['title'] + ' S%.2dE%.2d' % (info['season_number'], info['episode_number']) display, tvshow_display = build_display() listitem = xbmcgui.ListItem(display) listitem.setProperty( "resumetime", get_resumetime('episode', meta['tmdb_id'], info['season_number'], info['episode_number'])) rootname = '{0} ({1})'.format(meta['title'], meta['year']) meta.update({ 'vid_type': 'episode', 'rootname': rootname, 'season': info['season_number'], 'episode': info['episode_number'], 'premiered': first_aired, 'ep_name': info['name'], 'plot': info['overview'] }) meta_json = json.dumps(meta) url_params = { 'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': meta['tmdb_id'], 'query': query, 'tvshowtitle': meta['rootname'], 'season': info['season_number'], 'episode': info['episode_number'], 'meta': meta_json } url = build_url(url_params) browse_url = build_url({ 'mode': 'build_season_list', 'meta': meta_json }) playback_menu_params = {'mode': 'playback_menu', 'suggestion': query} watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen" watched_params = { "mode": "mark_episode_as_watched_unwatched", "action": "mark_as_watched", "media_id": meta['tmdb_id'], "imdb_id": meta["imdb_id"], "tvdb_id": meta["tvdb_id"], "season": info['season_number'], "episode": info['episode_number'], "title": meta['title'], "year": meta['year'] } if action == 'next_episode': nextep_manage_params = {"mode": "next_episode_context_choice"} cm.append(("[B]Mark Watched %s[/B]" % watched_title, 'XBMC.RunPlugin(%s)' % build_url(watched_params))) if listitem.getProperty("resumetime") != '0.000000': cm.append(("[B]Mark Unwatched %s[/B]" % watched_title, 'XBMC.RunPlugin(%s)' % build_url({ "mode": "mark_episode_as_watched_unwatched", "action": "mark_as_unwatched", "media_id": meta['tmdb_id'], "imdb_id": meta["imdb_id"], "season": info['season_number'], "episode": info['episode_number'], "title": meta['title'], "year": meta['year'] }))) if action == 'next_episode': cm.append(("[B]Next Episode Manager[/B]", 'XBMC.RunPlugin(%s)' % build_url(nextep_manage_params))) cm.append(("[B]Refresh List[/B]", 'XBMC.Container.Refresh()')) cm.append( ("[B]Browse...[/B]", 'XBMC.Container.Update(%s)' % browse_url)) cm.append(("[B]Options[/B]", 'XBMC.RunPlugin(%s)' % build_url(playback_menu_params))) cm.append(("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % meta['tmdb_id'])) listitem.setArt({ 'poster': meta['poster'], 'fanart': meta['fanart'], 'thumb': thumb, 'banner': meta['banner'], 'clearlogo': meta['clearlogo'], 'landscape': meta['landscape'] }) listitem.addContextMenuItems(cm) listitem.setCast(meta['cast'] + guest_stars) listitem.setInfo( 'video', { 'mediatype': 'episode', 'trailer': str(meta.get('trailer')), 'title': info['name'], 'tvshowtitle': tvshow_display, 'size': '0', 'plot': info['overview'], 'premiered': first_aired, 'writer': writer, 'director': director, 'season': info['season_number'], 'genre': meta.get('genre'), 'episode': info['episode_number'], 'rating': info['vote_average'], 'votes': info['vote_count'], 'duration': meta.get('episode_run_time'), 'playcount': playcount, 'overlay': overlay }) if not not_widget: listitem.setProperty("fen_widget", 'true') listitem.setProperty("fen_playcount", str(playcount)) return { 'listitem': (url, listitem, False), 'curr_last_played_parsed': item.get('curr_last_played_parsed', ''), 'order': item.get('order', ''), 'name': query, 'first_aired': first_aired } except: pass
def build_episode_list(): UNAIRED_EPISODE_COLOUR = settings.unaired_episode_colour() if not UNAIRED_EPISODE_COLOUR or UNAIRED_EPISODE_COLOUR == '': UNAIRED_EPISODE_COLOUR = 'red' params = dict(parse_qsl(sys.argv[2].replace('?', ''))) try: meta = json.loads(window.getProperty('fen_media_meta')) except: meta = tikimeta.tvshow_meta('tmdb_id', params.get('tmdb_id')) thumb_path = 'http://image.tmdb.org/t/p/original%s' cast = [] infoLabels = tikimeta.season_episodes_meta(meta['tmdb_id'], params.get('season')) watched_indicators = settings.watched_indicators() try: for item in infoLabels['credits']['cast']: cast_thumb = "http://image.tmdb.org/t/p/original%s" % item[ "profile_path"] if 'profile_path' in item else '' cast.append({ "name": item["name"], "role": item["character"], "thumbnail": cast_thumb }) except: pass for i in infoLabels['episodes']: try: cm = [] guest_stars = get_guest_stars(i['guest_stars']) first_aired = i['air_date'] if 'air_date' in i else None writer = ', '.join( [c['name'] for c in i['crew'] if c['job'] == 'Writer']) director = ', '.join( [c['name'] for c in i['crew'] if c['job'] == 'Director']) thumb = thumb_path % i['still_path'] if i.get( 'still_path', None) != None else meta['fanart'] playcount, overlay = get_watched_status('episode', meta['tmdb_id'], i['season_number'], i['episode_number']) query = meta['title'] + ' S%.2dE%.2d' % (int( i['season_number']), int(i['episode_number'])) display_name = '%s - %dx%.2d' % (meta['title'], int(i['season_number']), int(i['episode_number'])) meta.update({ 'vid_type': 'episode', 'rootname': display_name, 'season': i['season_number'], 'episode': i['episode_number'], 'premiered': first_aired, 'ep_name': i['name'], 'plot': i['overview'] }) meta_json = json.dumps(meta) url_params = { 'mode': 'play_media', 'vid_type': 'episode', 'tmdb_id': meta['tmdb_id'], 'query': query, 'tvshowtitle': meta['rootname'], 'season': i['season_number'], 'episode': i['episode_number'], 'meta': meta_json } url = build_url(url_params) try: d = first_aired.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) except: episode_date = date(2000, 01, 01) if i['season_number'] == 0 else None current_adjusted_date = settings.adjusted_datetime() display = '%dx%.2d - %s' % (i['season_number'], i['episode_number'], i['name']) cad = True if not episode_date or current_adjusted_date < episode_date: cad = False display = '[I][COLOR={}]{}[/COLOR][/I]'.format( UNAIRED_EPISODE_COLOUR, display) listitem = xbmcgui.ListItem(display) listitem.setProperty( "resumetime", get_resumetime('episode', meta['tmdb_id'], i['season_number'], i['episode_number'])) (state, action) = ('Watched', 'mark_as_watched') if playcount == 0 else ( 'Unwatched', 'mark_as_unwatched') (state2, action2) = ('Watched', 'mark_as_watched') if state == 'Unwatched' else ( 'Unwatched', 'mark_as_unwatched') playback_menu_params = { 'mode': 'playback_menu', 'suggestion': query } watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen" watched_unwatched_params = { "mode": "mark_episode_as_watched_unwatched", "action": action, "media_id": meta['tmdb_id'], "imdb_id": meta["imdb_id"], "tvdb_id": meta["tvdb_id"], "season": i['season_number'], "episode": i['episode_number'], "title": meta['title'], "year": meta['year'] } if cad: cm.append(("[B]Mark %s %s[/B]" % (state, watched_title), 'XBMC.RunPlugin(%s)' % build_url(watched_unwatched_params))) if cad and listitem.getProperty("resumetime") != '0.000000': cm.append(("[B]Mark %s %s[/B]" % (state2, watched_title), 'XBMC.RunPlugin(%s)' % build_url({ "mode": "mark_episode_as_watched_unwatched", "action": action2, "media_id": meta['tmdb_id'], "imdb_id": meta["imdb_id"], "season": i['season_number'], "episode": i['episode_number'], "title": meta['title'], "year": meta['year'] }))) cm.append(("[B]Options[/B]", 'XBMC.RunPlugin(%s)' % build_url(playback_menu_params))) cm.append( ("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % meta['tmdb_id'])) listitem.addContextMenuItems(cm) listitem.setArt({ 'poster': meta['poster'], 'fanart': meta['fanart'], 'thumb': thumb, 'banner': meta['banner'], 'clearlogo': meta['clearlogo'], 'landscape': meta['landscape'] }) listitem.setCast(cast + guest_stars) listitem.setInfo( 'video', { 'mediatype': 'episode', 'trailer': str(meta.get('trailer')), 'title': i['name'], 'tvshowtitle': meta.get('title'), 'size': '0', 'plot': i['overview'], 'premiered': first_aired, 'genre': meta.get('genre'), 'season': i['season_number'], 'episode': i['episode_number'], 'duration': meta.get('episode_run_time'), 'rating': i['vote_average'], 'votes': i['vote_count'], 'writer': writer, 'director': director, 'playcount': playcount, 'overlay': overlay }) if not not_widget: listitem.setProperty("fen_widget", 'true') listitem.setProperty("fen_playcount", str(playcount)) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=False) except:
def get_watched_items(db_type, page_no, letter, passed_list=[]): import ast from resources.lib.modules.nav_utils import paginate_list from resources.lib.modules.utils import title_key, to_utf8 watched_indicators = settings.watched_indicators() limit = 40 if db_type == 'tvshow': from resources.lib.indexers.tvshows import aired_episode_number_tvshow if watched_indicators in (1, 2): if not passed_list: from resources.lib.modules.trakt import trakt_indicators_tv data = trakt_indicators_tv() data = sorted(data, key=lambda tup: title_key(tup[3])) original_list = [{ 'media_id': i[0], 'title': i[3] } for i in data if i[1] == len(i[2])] else: original_list = ast.literal_eval(passed_list) else: if not passed_list: from resources.lib.indexers.tvshows import make_fresh_tvshow_meta settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute( "SELECT media_id, title FROM watched_status WHERE db_type = ?", ('episode', )) rows = dbcur.fetchall() dbcon.close() watched_list = list(set(to_utf8([(i[0], i[1]) for i in rows]))) data = [] for item in watched_list: watched = get_watched_status_tvshow( item[0], aired_episode_number_tvshow( make_fresh_tvshow_meta('tmdb_id', item[0]))) if watched[0] == 1: data.append(item) else: pass data = sorted(data, key=lambda tup: title_key(tup[1])) original_list = [{ 'media_id': i[0], 'title': i[1] } for i in data] else: original_list = ast.literal_eval(passed_list) else: if watched_indicators in (1, 2): if not passed_list: from resources.lib.modules.trakt import trakt_indicators_movies data = trakt_indicators_movies() data = sorted(data, key=lambda tup: title_key(tup[1])) original_list = [{ 'media_id': i[0], 'title': i[1] } for i in data] else: original_list = ast.literal_eval(passed_list) else: if not passed_list: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute( "SELECT media_id, title FROM watched_status WHERE db_type = ?", (db_type, )) rows = dbcur.fetchall() dbcon.close() data = to_utf8([(i[0], i[1]) for i in rows]) data = sorted(data, key=lambda tup: title_key(tup[1])) original_list = [{ 'media_id': i[0], 'title': i[1] } for i in data] else: original_list = ast.literal_eval(passed_list) paginated_list, total_pages = paginate_list(original_list, page_no, letter, limit) return paginated_list, original_list, total_pages, limit
def build_tvshow_content(self): watched_indicators = settings.watched_indicators() all_trailers = settings.all_trailers() for i in sorted(self.items, key=lambda k: k['item_no']): try: cm = [] item_no = i['item_no'] if not 'rootname' in i: i['rootname'] = '{0} ({1})'.format(i['title'], i['year']) meta = i['meta'] del i['meta'] meta_json = json.dumps(meta) url_params = { 'mode': 'build_season_list', 'meta': meta_json, 'tmdb_id': i['tmdb_id'] } url = build_url(url_params) from_search = 'true' if self.action in ( 'tmdb_tv_search', 'tmdb_tv_people_search') else 'false' hide_recommended_params = { 'mode': 'trakt.hide_recommendations', 'db_type': 'shows', 'imdb_id': i['imdb_id'] } playback_menu_params = {'mode': 'playback_menu'} watched_title = 'Trakt' if watched_indicators in (1, 2) else "Fen" watched_params = { "mode": "mark_tv_show_as_watched_unwatched", "action": 'mark_as_watched', "title": i['title'], "year": i['year'], "media_id": i['tmdb_id'], "imdb_id": i["imdb_id"], "tvdb_id": meta["tvdb_id"], "from_search": from_search } unwatched_params = { "mode": "mark_tv_show_as_watched_unwatched", "action": 'mark_as_unwatched', "title": i['title'], "year": i['year'], "media_id": i['tmdb_id'], "imdb_id": i["imdb_id"], "tvdb_id": meta["tvdb_id"], "from_search": from_search } add_remove_params = { "mode": "build_add_to_remove_from_list", "media_type": "tvshow", "meta": meta_json, "from_search": from_search, "orig_mode": self.action } sim_rel_params = { 'mode': 'similar_related_choice', 'db_type': 'tv', 'tmdb_id': i['tmdb_id'], 'imdb_id': i['imdb_id'], 'from_search': from_search } exit_list_params = { "mode": "navigator.main", "action": "TVShowList" } (trailer_params, trailer_title) = ( { 'mode': 'play_trailer', 'url': i['trailer'], 'all_trailers': json.dumps(i['all_trailers']) }, 'Choose Trailer') if (all_trailers and i.get( 'all_trailers', False)) else ({ 'mode': 'play_trailer', 'url': i['trailer'] }, 'Trailer') cm.append(("[B]Mark Watched %s[/B]" % watched_title, "XBMC.RunPlugin(%s)" % build_url(watched_params))) cm.append(("[B]Mark Unwatched %s[/B]" % watched_title, "XBMC.RunPlugin(%s)" % build_url(unwatched_params))) cm.append( ("[B]Add/Remove[/B]", "XBMC.RunPlugin(%s)" % build_url(add_remove_params))) cm.append(("[B]Similar/Related[/B]", "XBMC.RunPlugin(%s)" % build_url(sim_rel_params))) if self.action == 'trakt_recommendations': cm.append(("[B]Hide from Recommendations[/B]", "XBMC.RunPlugin(%s)" % build_url(hide_recommended_params))) cm.append( ("[B]Options[/B]", 'XBMC.RunPlugin(%s)' % build_url(playback_menu_params))) if i['trailer']: cm.append( ("[B]%s[/B]" % trailer_title, "XBMC.RunPlugin(%s)" % build_url(trailer_params))) cm.append( ("[B]Extended Info[/B]", 'RunScript(script.extendedinfo,info=extendedtvinfo,id=%s)' % i['tmdb_id'])) cm.append( ("[B]Exit TV Show List[/B]", "XBMC.Container.Refresh(%s)" % build_url(exit_list_params))) listitem = xbmcgui.ListItem(i['title']) listitem.setProperty('watchedepisodes', i['total_watched']) listitem.setProperty('unwatchedepisodes', i['total_unwatched']) listitem.setProperty('totalepisodes', i['total_episodes']) listitem.setProperty('totalseasons', i['total_seasons']) listitem.addContextMenuItems(cm) listitem.setCast(i['cast']) listitem.setArt({ 'poster': i['poster'], 'fanart': i['fanart'], 'banner': i['banner'], 'clearlogo': i['clearlogo'], 'landscape': i['landscape'] }) listitem.setInfo('video', remove_unwanted_info_keys(i)) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass
def mark_tv_show_as_watched_unwatched(): from resources.lib.modules.next_episode import add_next_episode_unwatched params = dict(parse_qsl(sys.argv[2].replace('?', ''))) action = 'mark_as_watched' if params.get( 'action') == 'mark_as_watched' else 'mark_as_unwatched' media_id = params.get('media_id') tvdb_id = int(params.get('tvdb_id', '0')) imdb_id = params.get('imdb_id') from_search = params.get('from_search', 'false') watched_indicators = settings.watched_indicators() if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'shows', imdb_id, tvdb_id) clear_trakt_watched_data('tvshow', imdb_id) if watched_indicators in (0, 1): import tikimeta from resources.lib.indexers.tvshows import make_fresh_tvshow_meta title = params.get('title', '') year = params.get('year', '') bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', '') se_list = [] count = 1 s_data = make_fresh_tvshow_meta('tmdb_id', media_id) season_data = s_data['season_data'] total = sum([ i['episode_count'] for i in season_data if i['season_number'] > 0 ]) for item in season_data: season_number = int(item['season_number']) if season_number <= 0: continue season_id = item['id'] infoLabels = tikimeta.season_episodes_meta(media_id, season_number) ep_data = infoLabels['episodes'] for item in ep_data: season_number = item['season_number'] ep_number = item['episode_number'] season_ep = '%.2d<>%.2d' % (int(season_number), int(ep_number)) display = 'Updating - S%.2dE%.2d' % (int(season_number), int(ep_number)) bg_dialog.update(int(float(count) / float(total) * 100), 'Please Wait', '%s' % display) count += 1 try: first_aired = item['air_date'] d = first_aired.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) except: episode_date = date(2100, 10, 24) if not settings.adjusted_datetime() > episode_date: continue mark_as_watched_unwatched('episode', media_id, action, season_number, ep_number, title) se_list.append(season_ep) bg_dialog.close() if action == 'mark_as_watched': add_next_episode_unwatched('remove', media_id, silent=True) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import get_library_video, batch_mark_episodes_as_watched_unwatched_kodi_library in_library = get_library_video('tvshow', title, year) if not in_library: refresh_container(from_search) return from resources.lib.modules.nav_utils import notification notification('Browse back to Kodi Home Screen!!', time=7000) xbmc.sleep(8500) ep_dict = { 'action': action, 'tvshowid': in_library['tvshowid'], 'season_ep_list': se_list } if batch_mark_episodes_as_watched_unwatched_kodi_library( in_library, ep_dict): notification('Kodi Library Sync Complete', time=5000) refresh_container(from_search)