def trakt_play_episode(id, season, episode, mode): from trakt import trakt id = int(id) season = int(season) episode = int(episode) show = None preason = None prepisode = None dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None show = trakt.get_show(id) if 'name' in show: show_title = show['name'] elif 'title' in show: show_title = show['title'] if show: if show['first_aired']: year = show['first_aired'][:4] else: year = None trakt_ids = get_trakt_ids("trakt", id, show_title, "show", year) preason = trakt.get_season(id, season) if preason: prepisode = trakt.get_episode(id, season, episode) elif not preason and season > 1900: seasons = trakt.get_seasons(id) for item in seasons: if item['first_aired'] != None: if int(item['first_aired'][:4]) == season: season_number = item['number'] preason = trakt.get_season(id, season_number) if not prepisode or not preason or not show: return tvmaze_play_episode(show_title, season, episode, mode) show_info = get_tvshow_metadata_trakt(show) season_info = get_season_metadata_trakt(show_info, preason) episode_info = get_episode_metadata_trakt(season_info, prepisode) title = show_info['name'] if show_info['poster'] != None and show_info['poster'] != "": show_poster = show_info['poster'] else: show_poster = "" if show_info['fanart'] != None and show_info['fanart'] != "": show_fanart = show_info['fanart'] else: show_fanart = "" items = [] if mode == 'select': play_plugin = ADDON_SELECTOR.id elif mode == 'context': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_CONTEXT, unicode) elif mode == 'library': play_plugin = get_tv_player_plugin_from_library(id) if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode) elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER, unicode) else: play_plugin = mode if mode == 'default' or mode == 'select': players = active_players("tvshows") else: players = get_players("tvshows") players = [p for p in players if p.id == play_plugin] or players if not players: return xbmc.executebuiltin( "Action(Info)") params = {} for lang in get_needed_langs(players): if show['name'] is None: continue episode_parameters = get_trakt_episode_parameters(show, preason, prepisode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "" and tried != "tmdb": tried = "tmdb" return tvdb_play_episode(trakt_ids["tvdb"], season, episode, mode) elif tried == "tmdb": msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode) dialogs.ok(_("%s not found") % _("Episode information"), msg) return else: msg = "{0} {1} - S{2}E{3}".format(_("No TMDb information found for"), show_info['name'], season, episode) dialogs.ok(_("%s not found") % _("Episode information"), msg) return if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = to_unicode(params[lang]) link = on_play_video(mode, players, params, trakt_ids) if link: set_property("data", json.dumps({'dbid': dbid, 'trakt': id, 'season': season, 'episode': episode})) episode_metadata = get_episode_metadata_trakt(season_info, prepisode) action_play({ 'label': episode_info['title'], 'path': link, 'info': episode_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'properties' : {'fanart_image' : str(show_info['fanart'])}, })