def update_library(): folder_path = plugin.get_setting('tv_library_folder', unicode) if not xbmcvfs.exists(folder_path): return library_folder = setup_library(folder_path) try: shows = xbmcvfs.listdir(library_folder)[0] except: shows = [] clean_needed = False updated = 0 for id in shows: try: id = int(id) with TVDB.session.cache_disabled(): if add_tvshow_to_library(library_folder, TVDB[id]): clean_needed = True except: continue updated += 1 if clean_needed: plugin.setProperty('plugin.video.openmeta.clean_library', 'true') if updated > 0: tools.scan_library( path=plugin.get_setting('tv_library_folder', unicode))
def update_library(): now = time.time() is_syncing = plugin.getProperty('openmeta_syncing_library') is_updating = plugin.getProperty('openmeta_updating_library') if is_syncing and now - int(is_syncing) < 120: plugin.log.debug('Skipping library sync') else: if plugin.get_setting('library_sync_collection', bool) == True: try: plugin.setProperty('openmeta_syncing_library', int(now)) plugin.notify('OpenMeta', 'Syncing library', plugin.get_addon_icon(), 1000) lib_tvshows.sync_trakt_collection() lib_movies.sync_trakt_collection() finally: plugin.clearProperty('openmeta_syncing_library') if is_updating and now - int(is_updating) < 120: plugin.log.debug('Skipping library update') return else: if plugin.get_setting('library_updates', bool) == True: try: plugin.setProperty('openmeta_updating_library', int(now)) plugin.notify('OpenMeta', 'Updating library', plugin.get_addon_icon(), 1000) lib_tvshows.update_library() finally: plugin.clearProperty('openmeta_updating_library')
def tv_add_to_library(id): library_folder = lib_tvshows.setup_library(plugin.get_setting('tv_library_folder', unicode)) show = TVDB[int(id)] imdb = show['imdb_id'] library_folder = lib_tvshows.setup_library(plugin.get_setting('tv_library_folder', unicode)) if lib_tvshows.add_tvshow_to_library(library_folder, show): plugin.setProperty('plugin.video.openmeta.clean_library', 'true') tools.scan_library(path=plugin.get_setting('tv_library_folder', unicode))
def update_library_from_settings(): now = time.time() if plugin.yesno('OpenMeta', 'Would you like to update the library now?'): try: plugin.setProperty('openmeta_updating_library', int(now)) plugin.notify('OpenMeta', 'Updating library', plugin.get_addon_icon(), 500) lib_tvshows.update_library() finally: plugin.clearProperty('openmeta_updating_library')
def silent_setup(): plugin.setProperty('totalopenmeta', 'true') movielibraryfolder = plugin.get_setting('movies_library_folder', unicode) tvlibraryfolder = plugin.get_setting('tv_library_folder', unicode) try: lib_movies.auto_movie_setup(movielibraryfolder) lib_tvshows.auto_tvshows_setup(tvlibraryfolder) except: pass plugin.clearProperty('totalopenmeta')
def tv_add_to_library_parsed(id, player): if id.startswith('tt'): try: id = TVDB.search_by_imdb(id) except: plugin.ok('TV show not found', 'no show information found for %s in TheTVDB' % id) library_folder = lib_tvshows.setup_library(plugin.get_setting('tv_library_folder', unicode)) show = TVDB[int(id)] imdb = show['imdb_id'] library_folder = lib_tvshows.setup_library(plugin.get_setting('tv_library_folder', unicode)) if lib_tvshows.add_tvshow_to_library(library_folder, show, player): plugin.setProperty('plugin.video.openmeta.clean_library', 'true') tools.scan_library(path=plugin.get_setting('tv_library_folder', unicode))
def players_setup(): plugin.setProperty('openmeta_players_setup', 'true') url = plugin.get_setting('players_update_url', unicode) if url == '': if plugin.yesno('OpenMeta players setup', 'Would you like to set a URL for players now?'): plugin.open_settings() else: plugin.notify('OpenMeta players setup', 'Failed', plugin.get_addon_icon(), 3000) elif updater.update_players(url): plugin.notify('OpenMeta players setup', 'Done', plugin.get_addon_icon(), 3000) else: plugin.notify('OpenMeta players setup', 'Failed', plugin.get_addon_icon(), 3000) plugin.clearProperty('openmeta_players_setup') return True
def on_play_video(players, params, trakt_ids=None): assert players action_cancel() selection = get_video_link(players, params) if not selection: return link = selection['path'] if link.startswith('videodb://'): return xbmc.executebuiltin('ActivateWindow(10025,"%s")' % link) elif link.endswith('.strm'): return action_playmedia(link) else: if trakt_ids: plugin.setProperty('script.trakt.ids', json.dumps(trakt_ids)) return link return None
def tmdb_play_episode(id, season, episode): from resources.lib.TheMovieDB import TV, TV_Seasons, TV_Episodes tried = 'tvdb' id = int(id) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel('ListItem.DBID') try: dbid = int(dbid) except: dbid = None show = TV(id).info(language='en', append_to_response='external_ids,images') if 'first_air_date' in show and show['first_air_date'] != None: year = show['first_air_date'][:4] else: year = None trakt_ids = play_base.get_trakt_ids('tmdb', id) if 'status_code' in show: return trakt_play_episode(trakt_ids['trakt'], season, episode) if 'name' in show: title = show['name'] else: title = None show_info = meta_info.get_tvshow_metadata_tmdb(show) title = show_info['name'] preason = TV_Seasons(id, season).info(language='en', append_to_response='external_ids,images') if 'The resource you requested could not be found' in str(preason): return trakt_play_episode(trakt_ids['trakt'], season, episode) season_info = meta_info.get_season_metadata_tmdb(show_info, preason) prepisode = TV_Episodes(id, season, episode).info(language='en', append_to_response='external_ids,images') 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) episode_info = meta_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 = [] play_plugin = meta_players.ADDON_SELECTOR.id players = meta_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 = play_base.get_trakt_ids('tmdb', id, show_info['name'], 'show', show['first_air_date'][:4]) params = {} for lang in meta_players.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) else: msg = 'No TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'tmdb': id, 'season': season, 'episode': episode })) episode_metadata = meta_info.get_episode_metadata_tmdb(season_info, prepisode) play_base.action_play( { 'label': episode_info['title'], 'path': link, 'info': [], 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': str(show_info['fanart']) })
def tvmaze_play_episode(id, season, episode, title=None): title = '' try: id = int(id) except: title = id if title and title != '': url = 'https://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 = 'https://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 = play_base.get_trakt_ids('tvdb', show['externals']['thetvdb'], show['name'], 'show', show['premiered'][:4]) elif show['externals']['imdb']: trakt_ids = play_base.get_trakt_ids('imdb', show['externals']['imdb'], show['name'], 'show', show['premiered'][:4]) else: trakt_ids = play_base.get_trakt_ids(query=show['name'], type='show', year=show['premiered'][:4]) else: trakt_ids = play_base.get_trakt_ids(query=show['name'], type='show', year=show['premiered'][:4]) show_info = meta_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 = meta_info.get_season_metadata_tvmaze(show_info, preason) episode_info = meta_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 = [] play_plugin = meta_players.ADDON_SELECTOR.id players = meta_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 meta_players.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) elif tried == 'tmdb': msg = 'No TVDb or TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) else: msg = 'No TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'tvdb': trakt_ids['tvdb'], 'season': season, 'episode': episode })) episode_metadata = meta_info.get_episode_metadata_tvmaze(season_info, prepisode) play_base.action_play( { 'label': episode_info['title'], 'path': link, 'info': [], 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': str(show_info['fanart']) })
def trakt_play_episode(id, season, episode): from resources.lib.Trakt import get_show, get_season, get_seasons, get_episode 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 = 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 = play_base.get_trakt_ids('trakt', id, show_title, 'show', year) preason = get_season(id, season) if preason: prepisode = get_episode(id, season, episode) elif not preason and season > 1900: seasons = get_seasons(id) for item in seasons: if item['first_aired'] != None: if int(item['first_aired'][:4]) == season: season_number = item['number'] preason = get_season(id, season_number) if not prepisode or not preason or not show: return tvmaze_play_episode(show_title, season, episode) show_info = meta_info.get_tvshow_metadata_trakt(show) season_info = meta_info.get_season_metadata_trakt(show_info, preason) episode_info = meta_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 = [] play_plugin = meta_players.ADDON_SELECTOR.id players = meta_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 meta_players.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) elif tried == 'tmdb': msg = 'No TVDb or TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) else: msg = 'No TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'trakt': id, 'season': season, 'episode': episode })) episode_metadata = meta_info.get_episode_metadata_trakt(season_info, prepisode) play_base.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'], 'fanart': str(show_info['fanart']) })
def play_episode(id, season, episode): from resources.lib.TheTVDB 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 = meta_info.get_tvshow_metadata_tvdb(show, banners=False) play_plugin = meta_players.ADDON_SELECTOR.id PLAYERS = meta_players.get_players('tvshows') players = [p for p in PLAYERS if p.id == play_plugin] or PLAYERS if not players or len(players) == 0: xbmc.executebuiltin('Action(Info)') play_base.action_cancel() return trakt_ids = play_base.get_trakt_ids('tvdb', id, show['seriesname'], 'show', show.get('year', 0)) params = {} for lang in meta_players.get_needed_langs(players): tvdb_data = show 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) elif trakt_ids['tvdb'] == None or trakt_ids['tvdb'] == '': plugin.ok('Information not found for:', '%s - S%sE%s' % (show_info['name'], season, episode)) else: plugin.ok('Information not found for:', '%s - S%sE%s' % (show_info['name'], season, episode)) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode })) season_info = meta_info.get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = meta_info.get_episode_metadata_tvdb(season_info, show[season][episode]) play_base.action_play( { 'label': episode_info['name'], 'path': link, 'info': episode_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': episode_info['fanart'] })