def tv_add_to_library(id): import_tvdb() show = tvdb[int(id)] # get active players players = active_players("tvshows", filters={'network': show.get('network')}) # add default and selector options players.insert(0, ADDON_SELECTOR) players.insert(0, ADDON_DEFAULT) # let the user select one player selection = dialogs.select(_("Play with..."), [p.title for p in players]) if selection == -1: return # get selected player player = players[selection] # setup library folder library_folder = setup_library( plugin.get_setting(SETTING_TV_LIBRARY_FOLDER)) # add to library if add_tvshow_to_library(library_folder, show, player.id): set_property("clean_library", 1) # start scan scan_library()
def on_play_video(mode, players, params, trakt_ids=None): assert players # Cancel resolve action_cancel() # Get video link use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, bool) is_extended = not (use_simple_selector or len(players) == 1) if not is_extended: xbmc.executebuiltin("ActivateWindow(busydialog)") try: selection = get_video_link(players, params, mode, use_simple_selector) finally: if not is_extended: xbmc.executebuiltin("Dialog.Close(busydialog)") if not selection: return # Get selection details link = selection['path'] action = selection.get('action', '') plugin.log.info('Playing url: %s' % to_utf8(link)) # Activate link if action == "ACTIVATE": action_activate(link) elif action == "RUN": action_run(link) elif action == "DEBLOCK": action_deblock(link) else: if trakt_ids: set_property('script.trakt.ids', json.dumps(trakt_ids)) return link return None
def update_library(): import_tvdb() folder_path = plugin.get_setting(SETTING_TV_LIBRARY_FOLDER) if not xbmcvfs.exists(folder_path): return # get library folder library_folder = setup_library(folder_path) # get shows in library try: shows = xbmcvfs.listdir(library_folder)[0] except: shows = [] # update each show clean_needed = False updated = 0 for id in shows: id = int(id) # add to library with tvdb.session.cache_disabled(): if add_tvshow_to_library(library_folder, tvdb[id]): clean_needed = True updated += 1 if clean_needed: set_property("clean_library", 1) # start scan if updated > 0: scan_library()
def tv_add_to_library(id): import_tvdb() show = tvdb[int(id)] # get active players players = active_players("tvshows", filters = {'network': show.get('network')}) # add default and selector options players.insert(0, ADDON_SELECTOR) players.insert(0, ADDON_DEFAULT) # let the user select one player selection = dialogs.select(_("Play with..."), [p.title for p in players]) if selection == -1: return # get selected player player = players[selection] # setup library folder library_folder = setup_library(plugin.get_setting(SETTING_TV_LIBRARY_FOLDER)) # add to library if add_tvshow_to_library(library_folder, show, player.id): set_property("clean_library", 1) # start scan scan_library()
def update_library(): is_updating = get_property("updating_library") is_syncing = get_property("syncing_library") now = time.time() if is_syncing and now - int(is_syncing) < plugin.get_setting(SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60: plugin.log.info("Skipping library sync") else: if plugin.get_setting(SETTING_LIBRARY_SYNC_COLLECTION, bool) == True or plugin.get_setting( SETTING_LIBRARY_SYNC_WATCHLIST, bool) == True: try: set_property("syncing_library", int(now)) if plugin.get_setting(SETTING_LIBRARY_SYNC_COLLECTION, bool) == True: meta.library.tvshows.sync_trakt_collection() meta.library.movies.sync_trakt_collection() if plugin.get_setting(SETTING_LIBRARY_SYNC_WATCHLIST, bool) == True: meta.library.tvshows.sync_trakt_watchlist() meta.library.movies.sync_trakt_watchlist() except: plugin.log.info("something went wrong") finally: clear_property("syncing_library") else: clear_property("syncing_library") if is_updating and now - int(is_updating) < 120: plugin.log.debug("Skipping library update") return if plugin.get_setting(SETTING_LIBRARY_UPDATES, bool) == True: try: set_property("updating_library", int(now)) meta.library.tvshows.update_library() meta.library.movies.update_library() meta.library.music.update_library() finally: clear_property("updating_library") else: clear_property("updating_library")
def update_library(): import_tvdb() folder_path = plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(folder_path): return # get library folder library_folder = setup_library(folder_path) # get shows in library try: shows = xbmcvfs.listdir(library_folder)[0] except: shows = [] # update each show clean_needed = False updated = 0 for id in shows: id = int(id) # add to library with tvdb.session.cache_disabled(): if add_tvshow_to_library(library_folder, tvdb[id]): clean_needed = True updated += 1 if clean_needed: set_property("clean_library", 1) # start scan if updated > 0: scan_library(type="video", path=plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode))
def on_play_video(mode, players, params, trakt_ids=None): assert players # Cancel resolve action_cancel() # Get video link use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, converter=bool) is_extended = not (use_simple_selector or len(players) == 1) if not is_extended: xbmc.executebuiltin("ActivateWindow(busydialog)") try: selection = get_video_link(players, params, mode, use_simple_selector) finally: if not is_extended: xbmc.executebuiltin("Dialog.Close(busydialog)") if not selection: return # Get selection details link = selection["path"] action = selection.get("action", "") plugin.log.info("Playing url: %s" % to_utf8(link)) # Activate link if action == "ACTIVATE": action_activate(link) else: if trakt_ids: set_property("script.trakt.ids", json.dumps(trakt_ids)) return link return None
def tv_add_to_library(id): import_tvdb() library_folder = setup_library(plugin.get_setting(SETTING_TV_LIBRARY_FOLDER)) show = tvdb[int(id)] imdb = show['imdb_id'] # get active players players = active_players("tvshows", filters = {'network': show.get('network')}) # get selected player if plugin.get_setting(SETTING_TV_DEFAULT_AUTO_ADD, bool) == True: player = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode) else: players.insert(0, ADDON_SELECTOR) players.insert(0, ADDON_DEFAULT) selection = dialogs.select(_("Play with..."), [p.title for p in players]) if selection == -1: return player = players[selection] # setup library folder library_folder = setup_library(plugin.get_setting(SETTING_TV_LIBRARY_FOLDER)) # add to library if plugin.get_setting('tv_default_auto_add', bool): if add_tvshow_to_library(library_folder, show, player): set_property("clean_library", 1) else: if add_tvshow_to_library(library_folder, show, player.id): set_property("clean_library", 1) # start scan scan_library(type="video")
def update_library(): # setup library folder library_folder = plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(library_folder): return if int(time.time()) - int( get_property("updating_library")) < plugin.get_setting( SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60: scan_library(type="video") set_property("updating_library", int(time.time()))
def update_library(): is_updating = get_property("updating_library") now = time.time() if is_updating and now - int(is_updating) < 120: plugin.log.debug("Skipping library update") return if plugin.get_setting(SETTING_LIBRARY_UPDATES, bool) == True: try: set_property("updating_library", int(now)) meta.library.tvshows.update_library() meta.library.movies.update_library() meta.library.music.update_library() finally: clear_property("updating_library") else: clear_property("updating_library")
def update_library(): is_updating = get_property("updating_library") now = time.time() if is_updating and now - int(is_updating) < 120: plugin.log.debug("Skipping library update") return try: set_property("updating_library", int(now)) meta.library.tvshows.update_library() meta.library.movies.update_library() finally: clear_property("updating_library")
def remove_unlisted_movie(movie_delete_list): msg_str = str(len(movie_delete_list)) + ' movies not in list' dialogs.notify(msg=msg_str, title='Deleting unlisted movies', delay=3000, image=get_icon_path("metalliq")) # Remove unlisted movies and series clean_needed = False movies_library_folder = setup_library( plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) for id in movie_delete_list: movie_folder = os.path.join(movies_library_folder, str(id) + '/') if os.path.exists(movie_folder): shutil.rmtree(movie_folder) clean_needed = True if clean_needed: set_property("clean_library", 1)
def update_library(): is_updating = get_property("updating_library") now = time.time() if is_updating and now - int(is_updating) < 120: plugin.log.debug("Skipping library update") return if plugin.get_setting(SETTING_LIBRARY_UPDATES, converter=bool) == True: #plugin.notify(msg=_('Library'), title=_('Updating'), delay=5000, image=get_icon_path("metalliq")) try: set_property("updating_library", int(now)) meta.library.tvshows.update_library() meta.library.movies.update_library() meta.library.music.update_library() finally: clear_property("updating_library") else: #plugin.notify(msg=_('Library'), title=_('Not updating'), delay=5000, image=get_icon_path("metalliq")) clear_property("updating_library")
def update_library(): is_updating = get_property("updating_library") now = time.time() if is_updating and now - int(is_updating) < 120: plugin.log.debug("Skipping library update") return if plugin.get_setting(SETTING_LIBRARY_UPDATES, converter=bool) == True: # plugin.notify(msg=_('Library'), title=_('Updating'), delay=5000, image=get_icon_path("metalliq")) try: set_property("updating_library", int(now)) meta.library.tvshows.update_library() meta.library.movies.update_library() meta.library.music.update_library() finally: clear_property("updating_library") else: # plugin.notify(msg=_('Library'), title=_('Not updating'), delay=5000, image=get_icon_path("metalliq")) clear_property("updating_library")
def tv_add_all_to_library(items): import_tvdb() # setup library folder library_folder = setup_library(plugin.get_setting(SETTING_TV_LIBRARY_FOLDER)) # add to library for item in items: ids = item["show"]["ids"] tvdb_id = ids.get('tvdb') if not tvdb_id: continue show = tvdb[int(tvdb_id)] if add_tvshow_to_library(library_folder, show, ADDON_DEFAULT.id): set_property("clean_library", 1) # start scan scan_library()
def tv_add_all_to_library(items): import_tvdb() # setup library folder library_folder = setup_library(plugin.get_setting(SETTING_TV_LIBRARY_FOLDER)) # add to library for item in items: ids = item["show"]["ids"] tvdb_id = ids.get('tvdb') if not tvdb_id: continue show = tvdb[int(tvdb_id)] if plugin.get_setting(SETTING_TV_DEFAULT_AUTO_ADD, bool) == True: if add_tvshow_to_library(library_folder, show, plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY, unicode)): set_property("clean_library", 1) else: if add_tvshow_to_library(library_folder, show, ADDON_DEFAULT.id): set_property("clean_library", 1) # start scan scan_library(type="video")
def update_library(): is_updating = get_property("updating_library") is_syncing = get_property("syncing_library") now = time.time() if is_syncing and now - int(is_syncing) < plugin.get_setting( SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60: plugin.log.info("Skipping library sync") else: if plugin.get_setting(SETTING_LIBRARY_SYNC_COLLECTION, bool) == True or plugin.get_setting( SETTING_LIBRARY_SYNC_WATCHLIST, bool) == True: try: set_property("syncing_library", int(now)) if plugin.get_setting(SETTING_LIBRARY_SYNC_COLLECTION, bool) == True: meta.library.tvshows.sync_trakt_collection() meta.library.movies.sync_trakt_collection() if plugin.get_setting(SETTING_LIBRARY_SYNC_WATCHLIST, bool) == True: meta.library.tvshows.sync_trakt_watchlist() meta.library.movies.sync_trakt_watchlist() except: plugin.log.info("something went wrong") finally: clear_property("syncing_library") else: clear_property("syncing_library") if is_updating and now - int(is_updating) < 120: plugin.log.debug("Skipping library update") return if plugin.get_setting(SETTING_LIBRARY_UPDATES, bool) == True: try: set_property("updating_library", int(now)) meta.library.tvshows.update_library() meta.library.movies.update_library() meta.library.music.update_library() finally: clear_property("updating_library") else: clear_property("updating_library")
def main(): set_property( "syncing_library", int((time.time() - plugin.get_setting(SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60))) set_property( "updating_library", int((time.time() - plugin.get_setting(SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60))) set_property( "updating_library_music", int((time.time() - plugin.get_setting(SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60))) go_idle(15) if plugin.get_setting(SETTING_TOTAL_SETUP_DONE, bool) == False: xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.chappaai/setup/total)') plugin.set_setting(SETTING_TOTAL_SETUP_DONE, "true") if plugin.get_setting(SETTING_AUTOPATCH, bool) == True: patch("auto") xbmc.executebuiltin( "RunPlugin(plugin://plugin.video.chappaai/movies/batch_add_to_library)" ) next_update = future(0) while not xbmc.abortRequested: if next_update <= future(0): next_update = future( plugin.get_setting(SETTING_UPDATE_LIBRARY_INTERVAL, int) * 60 * 60) update_library() go_idle(30 * 60)
def tvmaze_play_episode(id, season, episode, mode, title=None): title = "" try: id = int(id) except: title = id if title and title != "": url = "http://api.tvmaze.com/search/shows?q=%s" % id response = urllib.urlopen(url) shows = json.loads(response.read()) if len(shows) > 0: show = shows[0] id = show['show']['id'] url = "http://api.tvmaze.com/shows/%d?embed[]=seasons&embed[]=episodes" % int(id) response = urllib.urlopen(url) show = json.loads(response.read()) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None if show['externals']: if show['externals']['thetvdb']: trakt_ids = get_trakt_ids("tvdb", show['externals']['thetvdb'], show['name'], "show", show['premiered'][:4]) elif show['externals']['imdb']: trakt_ids = get_trakt_ids("imdb", show['externals']['imdb'], show['name'], "show", show['premiered'][:4]) else: trakt_ids = get_trakt_ids(query=show['name'], type="show", year=show['premiered'][:4]) else: trakt_ids = get_trakt_ids(query=show['name'], type="show", year=show['premiered'][:4]) show_info = get_tvshow_metadata_tvmaze(show) preasons = show['_embedded']['seasons'] for item in preasons: if item['number'] == season: preason = item season = preasons.index(item) + 1 elif item['premiereDate'] and item['endDate']: if int(item['premiereDate'][:4]) <= season and int(item['endDate'][:4]) >= season: preason = item season = preasons.index(item) + 1 prepisodes = show['_embedded']['episodes'] for item in prepisodes: if item['number'] == episode: prepisode = item season_info = get_season_metadata_tvmaze(show_info, preason) episode_info = get_episode_metadata_tvmaze(season_info, prepisode) 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_tvmaze_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, 'tvdb': trakt_ids['tvdb'], 'season': season, 'episode': episode})) episode_metadata = get_episode_metadata_tvmaze(season_info, prepisode) action_play({ 'label': episode_info['title'], 'path': link, 'info': [], 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'properties' : {'fanart_image' : str(show_info['fanart'])}, })
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'])}, })
def play_episode(id, season, episode, mode): import_tvdb() id = int(id) season = int(season) episode = int(episode) # Get database id dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None # Get show data from TVDB show = tvdb[id] show_info = get_tvshow_metadata_tvdb(show, banners=False) # Get players to use 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", filters = {'network': show.get('network')}) else: players = get_players("tvshows", filters = {'network': show.get('network')}) players = [p for p in players if p.id == play_plugin] or players if not players: return xbmc.executebuiltin( "Action(Info)") # Get show ids from Trakt trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0)) # Get parameters params = {} for lang in get_needed_langs(players): if lang == LANG: tvdb_data = show else: tvdb_data = create_tvdb(lang)[id] if tvdb_data['seriesname'] is None: continue episode_parameters = get_episode_parameters(tvdb_data, season, episode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids["tmdb"] != None and trakt_ids["tmdb"] != "": return tmdb_play_episode(trakt_ids["tmdb"], season, episode, mode) elif trakt_ids["tvdb"] == None or trakt_ids["tvdb"] == "": msg = "{0} {1} - S{2}E{3}".format(_("No TVDb information found for"), show_info['name'], season, episode) return dialogs.ok(_("%s not found") % _("Episode information"), msg) else: msg = "{0} {1} - S{2}E{3}".format(_("No TVDb or TMDb information found for"), show_info['name'], season, episode) return dialogs.ok(_("%s not found") % _("Episode information"), msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = to_unicode(params[lang]) # Go for it link = on_play_video(mode, players, params, trakt_ids) if link: # set properties set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode})) # Play season_info = get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = get_episode_metadata_tvdb(season_info, show[season][episode]) 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' : episode_info['fanart']}, })
def tmdb_play_episode(id, season, episode, mode): tried = "tvdb" import_tmdb() id = int(id) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None show = tmdb.TV(id).info(language=LANG, append_to_response="external_ids,images,similar,videos") if 'first_air_date' in show and show['first_air_date'] != None: year = show['first_air_date'][:4] else: year = None trakt_ids = get_trakt_ids("tmdb", id) if "status_code" in show: return trakt_play_episode(trakt_ids["trakt"], season, episode, mode) if 'name' in show: title = show['name'] else: title = None show_info = get_tvshow_metadata_tmdb(show) title = show_info['name'] preason = tmdb.TV_Seasons(id, season).info(language=LANG, append_to_response="external_ids,images,similar,videos") if "The resource you requested could not be found" in str(preason): return trakt_play_episode(trakt_ids["trakt"], season, episode, mode) season_info = get_season_metadata_tmdb(show_info, preason) prepisode = tmdb.TV_Episodes(id, season, episode).info(language=LANG, append_to_response="external_ids,images,similar,videos") if prepisode == "{u'status_code': 34, u'status_message': u'The resource you requested could not be found.'}": return trakt_play_episode(trakt_ids["tmdb"], season, episode, mode) episode_info = get_episode_metadata_tmdb(season_info, prepisode) 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 = "" episodes = preason['episodes'] 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)") trakt_ids = get_trakt_ids("tmdb", id, show_info['name'], "show", show['first_air_date'][:4]) params = {} for lang in get_needed_langs(players): if show['name'] is None: continue episode_parameters = get_tmdb_episode_parameters(show, preason, prepisode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids["trakt"] != None and trakt_ids["trakt"] != "": return trakt_play_episode(trakt_ids["trakt"], season, episode, mode) 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, 'tmdb': id, 'season': season, 'episode': episode})) episode_metadata = get_episode_metadata_tmdb(season_info, prepisode) action_play({ 'label': episode_info['title'], 'path': link, 'info': [], 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'properties' : {'fanart_image' : str(show_info['fanart'])}, })
def play_movie(tmdb_id, mode): import_tmdb() # Get active players players = active_players("movies") if not players: xbmc.executebuiltin( "Action(Info)") action_cancel() return # Get player to use if mode == 'select': play_plugin = ADDON_SELECTOR.id elif mode == 'library': play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY) else: play_plugin = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER) # Use just selected player if exists (selectors excluded) players = [p for p in players if p.id == play_plugin] or players # Get movie data from TMDB movie = tmdb.Movies(tmdb_id).info(language=LANG) movie_info = get_movie_metadata(movie) # Get movie ids from Trakt trakt_ids = get_trakt_ids("tmdb", tmdb_id, movie['original_title'], "movie", parse_year(movie['release_date'])) # Preload params params = {} for lang in get_needed_langs(players): if lang == LANG: tmdb_data = movie else: tmdb_data = tmdb.Movies(tmdb_id).info(language=lang) params[lang] = get_movie_parameters(tmdb_data) params[lang].update(trakt_ids) params[lang]['info'] = movie_info params[lang] = to_unicode(params[lang]) # BETA action_cancel() # Get single video selection use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, converter=bool) selection = get_video_link(players, params, mode, use_simple_selector) if not selection: #action_cancel() return # Get selection details link = selection['path'] action = selection.get('action', '') plugin.log.info('Playing url: %s' % link.encode('utf-8')) # Activate link if action == "ACTIVATE": action_activate(link) else: movie = tmdb.Movies(tmdb_id).info(language=LANG) listitem = { 'label': movie_info['title'], 'path': link, 'info': movie_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': movie_info['poster'], 'poster': movie_info['poster'], 'properties' : {'fanart_image' : movie_info['fanart']}, } if trakt_ids: set_property('script.trakt.ids', json.dumps(trakt_ids)) if action == "PLAY": action_play(listitem) else: action_resolve(listitem)
def play_episode(id, season, episode, mode): import_tvdb() id = int(id) season = int(season) episode = int(episode) # Get database id dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None # Get show data from TVDB show = tvdb[id] show_info = get_tvshow_metadata_tvdb(show, banners=False) # Get active players players = active_players("tvshows", filters = {'network': show.get('network')}) if not players: xbmc.executebuiltin( "Action(Info)") action_cancel() return # Get player to use if mode == 'select': play_plugin = ADDON_SELECTOR.id elif mode == 'library': play_plugin = get_player_plugin_from_library(id) if not play_plugin: play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY) else: play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER) # Use just selected player if exists (selectors excluded) players = [p for p in players if p.id == play_plugin] or players # Get show ids from Trakt trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0)) # Preload params params = {} for lang in get_needed_langs(players): if lang == LANG: tvdb_data = show else: tvdb_data = create_tvdb(lang)[id] if tvdb_data['seriesname'] is None: continue params[lang] = get_episode_parameters(tvdb_data, season, episode) params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = to_unicode(params[lang]) # BETA action_cancel() # Get single video selection use_simple_selector = plugin.get_setting(SETTING_USE_SIMPLE_SELECTOR, converter=bool) selection = get_video_link(players, params, mode, use_simple_selector) if not selection: #action_cancel() return # Get selection details link = selection['path'] action = selection.get('action', '') plugin.log.info('Playing url: %s' % link.encode('utf-8')) # Activate link if action == "ACTIVATE": action_activate(link) else: # Build list item (needed just for playback from widgets) season_info = get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = get_episode_metadata_tvdb(season_info, show[season][episode]) listitem = { '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' : episode_info['fanart']}, } # set properties if trakt_ids: set_property('script.trakt.ids', json.dumps(trakt_ids)) set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode})) # Play if action == "PLAY": action_play(listitem) else: action_resolve(listitem)
def play_episode_from_guide(id, season, episode, mode): import_tvdb() id = int(id) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None show = tvdb[id] show_info = get_tvshow_metadata_tvdb(show, banners=False) if mode == 'select': play_plugin = ADDON_PICKER.id elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_CHANNELER) else: play_plugin = mode channelers = active_channelers("tvshows", filters = {'network': show.get('network')}) channelers = [p for p in channelers if p.id == play_plugin] or channelers if not channelers: xbmc.executebuiltin( "Action(Info)") action_cancel() return trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0)) params = {} for lang in get_needed_langs(channelers): if lang == LANG: tvdb_data = show else: tvdb_data = create_tvdb(lang)[id] if tvdb_data['seriesname'] is None: continue episode_parameters = get_episode_parameters(tvdb_data, season, episode) if episode_parameters is not None: params[lang] = episode_parameters else: msg = "{0} {1} - S{1}E{2}".format(_("No tvdb information found for"), show['seriesname'], season, episode) dialogs.ok(_("Episode info not found"), 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, channelers, params, trakt_ids) if link: set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode})) season_info = get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = get_episode_metadata_tvdb(season_info, show[season][episode]) 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' : episode_info['fanart']}, })
def play_episode_from_guide(id, season, episode, mode): import_tvdb() id = int(id) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None show = tvdb[id] show_info = get_tvshow_metadata_tvdb(show, banners=False) if mode == 'select': play_plugin = ADDON_PICKER.id elif mode == 'default': play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_CHANNELER, unicode) else: play_plugin = mode channelers = active_channelers("tvshows", filters = {'network': show.get('network')}) channelers = [p for p in channelers if p.id == play_plugin] or channelers if not channelers: xbmc.executebuiltin( "Action(Info)") action_cancel() return trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0)) params = {} for lang in get_needed_langs(channelers): if lang == LANG: tvdb_data = show else: tvdb_data = create_tvdb(lang)[id] if tvdb_data['seriesname'] is None: continue episode_parameters = get_episode_parameters(tvdb_data, season, episode) if episode_parameters is not None: params[lang] = episode_parameters else: msg = "{0} {1} - S{1}E{2}".format(_("No tvdb information found for"), show['seriesname'], 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, channelers, params, trakt_ids) if link: set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode})) season_info = get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = get_episode_metadata_tvdb(season_info, show[season][episode]) 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' : episode_info['fanart']}, })
def play_episode(id, season, episode, mode): import_tvdb() id = int(id) season = int(season) episode = int(episode) # Get database id dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None # Get show data from TVDB show = tvdb[id] show_info = get_tvshow_metadata_tvdb(show, banners=False) # Get players to use if mode == 'select': play_plugin = ADDON_SELECTOR.id elif mode == 'library': play_plugin = get_player_plugin_from_library(id) if not play_plugin or play_plugin == "default": play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY) else: play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER) players = active_players("tvshows", filters = {'network': show.get('network')}) players = [p for p in players if p.id == play_plugin] or players if not players: xbmc.executebuiltin( "Action(Info)") action_cancel() return # Get show ids from Trakt trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0)) # Get parameters params = {} for lang in get_needed_langs(players): if lang == LANG: tvdb_data = show else: tvdb_data = create_tvdb(lang)[id] if tvdb_data['seriesname'] is None: continue episode_parameters = get_episode_parameters(tvdb_data, season, episode) if episode_parameters is not None: params[lang] = episode_parameters else: msg = "{0} {1} - S{1}E{2}".format(_("No tvdb information found for"), show['seriesname'], season, episode) dialogs.ok(_("Episode info not found"), msg) return params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = to_unicode(params[lang]) # Go for it link = on_play_video(mode, players, params, trakt_ids) if link: # set properties set_property("data", json.dumps({'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode})) # Play season_info = get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = get_episode_metadata_tvdb(season_info, show[season][episode]) 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' : episode_info['fanart']}, })
def play_episode(id, season, episode, mode): import_tvdb() id = int(id) season = int(season) episode = int(episode) # Get database id dbid = xbmc.getInfoLabel("ListItem.DBID") try: dbid = int(dbid) except: dbid = None # Get show data from TVDB show = tvdb[id] show_info = get_tvshow_metadata_tvdb(show, banners=False) # Get players to use if mode == 'select': play_plugin = ADDON_SELECTOR.id elif mode == 'library': play_plugin = get_player_plugin_from_library(id) if not play_plugin: play_plugin = plugin.get_setting( SETTING_TV_DEFAULT_PLAYER_FROM_LIBRARY) else: play_plugin = plugin.get_setting(SETTING_TV_DEFAULT_PLAYER) players = active_players("tvshows", filters={'network': show.get('network')}) players = [p for p in players if p.id == play_plugin] or players if not players: xbmc.executebuiltin("Action(Info)") action_cancel() return # Get show ids from Trakt trakt_ids = get_trakt_ids("tvdb", id, show['seriesname'], "show", show.get('year', 0)) # Get parameters params = {} for lang in get_needed_langs(players): if lang == LANG: tvdb_data = show else: tvdb_data = create_tvdb(lang)[id] if tvdb_data['seriesname'] is None: continue params[lang] = get_episode_parameters(tvdb_data, season, episode) params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = to_unicode(params[lang]) # Go for it link = on_play_video(mode, players, params, trakt_ids) if link: # set properties set_property( "data", json.dumps({ 'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode })) # Play season_info = get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = get_episode_metadata_tvdb(season_info, show[season][episode]) 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': episode_info['fanart'] }, })