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 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 find_last_version(self, name): dirs, files = xbmcvfs.listdir(self.BASE_PATH) matched_files = [f for f in files if f.startswith(name)] versions = [int(os.path.splitext(f[len(name):])[0]) for f in matched_files] if not versions: return 0 return max(versions)
def export_tv_library(): folder_path = plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(folder_path): return dialogs.notify(msg='TVShows folder', title='Absent', delay=5000, image=get_icon_path("tv")) ids = "" shows = xbmcvfs.listdir(folder_path)[0] if len(shows) < 1: return dialogs.notify(msg='TVShows folder', title='Empty', delay=5000, image=get_icon_path("tv")) else: for show in shows: ids = ids + str(show) + '\n' shows_backup_file_path = "special://profile/addon_data/plugin.video.metalliq/shows_to_add.bak" if xbmcvfs.exists(shows_backup_file_path): os.remove(xbmc.translatePath(shows_backup_file_path)) if not xbmcvfs.exists(shows_backup_file_path): batch_add_file = xbmcvfs.File(shows_backup_file_path, 'w') batch_add_file.write(ids) batch_add_file.close() dialogs.notify(msg="TVShows", title="Backed up", delay=5000, image=get_icon_path("tv"))
def get_players(media, filters = {}): assert media in ("tvshows", "movies") players = [] players_path = "special://profile/addon_data/{0}/players/".format(plugin.id) files = [x for x in xbmcvfs.listdir(players_path)[1] if x.endswith(EXTENSION)] for file in files: path = players_path + file try: f = xbmcvfs.File(path) try: content = f.read() meta = json.loads(content) finally: f.close() player = AddonPlayer(file, media, meta) if not player.is_empty(): players.append(player) except Exception, e: plugin.log.error(repr(e)) msg = "player %s is invalid" % file xbmcgui.Dialog().ok('Invalid player', msg) raise
def get_players(media, filters={}): assert media in ("tvshows", "movies", "musicvideos", "music", "live") players = [] players_path = "special://home/userdata/addon_data/{0}/players/".format( plugin.id) files = [ x for x in xbmcvfs.listdir(players_path)[1] if x.endswith(EXTENSION) ] for file in files: path = players_path + file try: f = xbmcvfs.File(path) try: content = f.read() meta = json.loads(content) finally: f.close() player = AddonPlayer(file, media, meta) if not player.is_empty(): players.append(player) except Exception, e: plugin.log.error(repr(e)) msg = "player %s is invalid" % file xbmcgui.Dialog().ok('Invalid player', msg) raise
def export_movies_library(): folder_path = plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(folder_path): return dialogs.notify(msg='Movies folder', title='Absent', delay=5000, image=get_icon_path("movies")) ids = "" movies = xbmcvfs.listdir(folder_path)[0] if len(movies) < 1: return dialogs.notify(msg='Movies folder', title='Empty', delay=5000, image=get_icon_path("movies")) else: for movie in movies: ids = ids + str(movie) + '\n' movies_backup_file_path = "special://profile/addon_data/plugin.video.metalliq/movies_to_add.bak" if xbmcvfs.exists(movies_backup_file_path): os.remove(xbmc.translatePath(movies_backup_file_path)) if not xbmcvfs.exists(movies_backup_file_path): batch_add_file = xbmcvfs.File(movies_backup_file_path, 'w') batch_add_file.write(ids) batch_add_file.close() dialogs.notify(msg="Movies", title="Backed up", delay=5000, image=get_icon_path("movies"))
def get_library_channels(): folder_path = plugin.get_setting(SETTING_LIVE_LIBRARY_FOLDER, unicode) library_folder = setup_library(folder_path) # get channels in library try: library_channels = xbmcvfs.listdir(folder_path)[0] except: library_channels = [] return library_channels
def dirwalk(top, topdown=True): dirs, nondirs = xbmcvfs.listdir(top) if topdown: yield top, dirs, nondirs for name in dirs: new_path = os.path.join(top, name) for x in dirwalk(new_path, topdown): yield x if not topdown: yield top, dirs, nondirs
def list_library(): while not xbmc.abortRequested and \ (xbmc.getCondVisibility('Library.IsScanning') or \ xbmc.getCondVisibility('Window.IsActive(progressdialog)') or \ xbmc.getCondVisibility('Window.IsActive(extendedprogressdialog)')): xbmc.sleep(100) xbmc.sleep(5000) library = {} medias = ["movies", "tvshows"] # medias = ["movies", "tvshows", "musicvideos", "music", "live"] for m in medias: if m == "movies": lib = plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode) prite = RPC.videolibrary.get_movies(properties=[ "title", "year", "playcount", "fanart", "originaltitle", "imdbnumber", "thumbnail", "file" ]) if "movies" in prite: ite = prite["movies"] else: ite = [] elif m == "tvshows": lib = plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode) prite = RPC.videolibrary.get_tvshows(properties=[ "title", "year", "playcount", "fanart", "originaltitle", "imdbnumber", "thumbnail", "file" ]) if "tvshows" in prite: ite = prite["tvshows"] else: ite = [] # elif m == "musicvideos": # lib = plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode) # ite = RPC.videolibrary.get_tvshows(properties=["title","year","playcount","fanart","originaltitle","imdbnumber","thumbnail","file"])["tvshows"] else: continue liq = xbmcvfs.listdir(lib)[0] for i in ite: try: f = xbmcvfs.File( os.path.join(lib, i["imdbnumber"], "player.info")) i["player"] = f.read() f.close() except: i["player"] = "na" f = xbmcvfs.File("{0}library.nfo".format(lib), 'w') f.write(str(ite)) f.close() if len(ite) > 0: players = dict(zip(ite[0], zip(*[d.values() for d in ite])))["player"] else: players = "()" f = xbmcvfs.File("{0}players.nfo".format(lib), 'w') f.write(str(players)) f.close()
def get_current_movie_players_from_library(): library_folder = plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(library_folder): return folders = xbmcvfs.listdir(library_folder)[0] players_info = "" for folder in folders: player_file = xbmcvfs.File(os.path.join(library_folder, str(folder), "player.info")) content = player_file.read() players_info = players_info + "{0}|{1}".format(folder, content) + '\n' player_file.close() lib_players_file = xbmcvfs.File(library_folder + "players.info", 'w') lib_players_file.write(players_info) lib_players_file.close()
def dirwalk(top, topdown=True): from xbmcswift2 import xbmcvfs dirs, nondirs = xbmcvfs.listdir(top) dirs = [ensure_unicode(d) for d in dirs] nondirs = [ensure_unicode(d) for d in nondirs] if topdown: yield top, dirs, nondirs for name in dirs: new_path = join_path(top, name) for x in dirwalk(new_path, topdown): yield x if not topdown: yield top, dirs, nondirs
def library_tv_remove_strm(show, folder, id, season, episode): enc_season = ('Season %s' % season).translate(None, '\/:*?"<>|').strip('.') enc_name = 'S%02dE%02d' % (season, episode) season_folder = os.path.join(folder, enc_season) stream_file = os.path.join(season_folder, enc_name + "%s" % plugin.get_setting(SETTING_LIBRARY_TAGS, unicode) + '.strm') if xbmcvfs.exists(stream_file): xbmcvfs.delete(stream_file) while not xbmc.abortRequested and xbmcvfs.exists(stream_file): xbmc.sleep(1000) a,b = xbmcvfs.listdir(season_folder) if not a and not b: xbmcvfs.rmdir(season_folder) return True return False
def update_library(): folder_path = plugin.get_setting(SETTING_LIVE_LIBRARY_FOLDER) if not xbmcvfs.exists(folder_path): return # get library folder library_folder = setup_library(folder_path) # get shows in library try: channels = xbmcvfs.listdir(library_folder)[0] except: channels = [] # update each show clean_needed = False updated = 0
def update_library(): folder_path = plugin.get_setting(SETTING_LIVE_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(folder_path): return # get library folder library_folder = setup_library(folder_path) # get shows in library try: channels = xbmcvfs.listdir(library_folder)[0] except: channels = [] # update each show clean_needed = False updated = 0
def export_movies_library(): folder_path = plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(folder_path): return dialogs.notify(msg='Movies folder', title='Absent', delay=5000, image=get_icon_path("movies")) ids = "" movies = xbmcvfs.listdir(folder_path)[0] if len(movies) < 1: return dialogs.notify(msg='Movies folder', title='Empty', delay=5000, image=get_icon_path("movies")) else : for movie in movies: ids = ids + str(movie) + '\n' movies_backup_file_path = "special://profile/addon_data/plugin.video.metalliq/movies_to_add.bak" if xbmcvfs.exists(movies_backup_file_path): os.remove(xbmc.translatePath(movies_backup_file_path)) if not xbmcvfs.exists(movies_backup_file_path): batch_add_file = xbmcvfs.File(movies_backup_file_path, 'w') batch_add_file.write(ids) batch_add_file.close() dialogs.notify(msg="Movies", title="Backed up", delay=5000, image=get_icon_path("movies"))
def export_tv_library(): folder_path = plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(folder_path): return dialogs.notify(msg='TVShows folder', title='Absent', delay=5000, image=get_icon_path("tv")) ids = "" shows = xbmcvfs.listdir(folder_path)[0] if len(shows) < 1: return dialogs.notify(msg='TVShows folder', title='Empty', delay=5000, image=get_icon_path("tv")) else : for show in shows: ids = ids + str(show) + '\n' shows_backup_file_path = "special://profile/addon_data/plugin.video.metalliq/shows_to_add.bak" if xbmcvfs.exists(shows_backup_file_path): os.remove(xbmc.translatePath(shows_backup_file_path)) if not xbmcvfs.exists(shows_backup_file_path): batch_add_file = xbmcvfs.File(shows_backup_file_path, 'w') batch_add_file.write(ids) batch_add_file.close() dialogs.notify(msg="TVShows", title="Backed up", delay=5000, image=get_icon_path("tv"))
def remove_folder(self, folder_id): if folder_id not in self.storage: return media_path = self.storage[folder_id][1] del self.storage[folder_id] if not direxists(media_path): return self.log.info("Removing from library folder: %s", media_path) files = xbmcvfs.listdir(media_path)[1] count_deleted = 0 for f in files: if f.endswith("[%d].strm" % folder_id): path = os.path.join(media_path, f) self.log.info("Removing file: %s", path) xbmcvfs.delete(path) count_deleted += 1 if len(files) == count_deleted: self.log.info("All files deleted, removing folder: %s", media_path) xbmcvfs.rmdir(media_path)
def get_players(media, filters = {}): assert media in ("tvshows", "movies") players = [] players_path = "special://profile/addon_data/{0}/players/".format(plugin.id) files = [x for x in xbmcvfs.listdir(players_path)[1] if x.endswith(EXTENSION)] for file in files: path = xbmc.translatePath(players_path + "/" + file) try: with open(path, "r") as f: meta = json.loads(f.read()) player = AddonPlayer(file, media, meta) if not player.is_empty(): players.append(player) except Exception, e: plugin.log.error(repr(e)) msg = "player %s is invalid" % file xbmcgui.Dialog().ok('Invalid player', msg) raise
def sync_trakt_watchlist_del(): from trakt import trakt library_folder = setup_library( plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) shows = xbmcvfs.listdir(library_folder)[0] items = trakt.trakt_get_watchlist("movies") # Convert watchlist items to ids list if "results" in items: ids = [str(r["id"]) for r in items["results"]] else: vals = [ i["movie"]["ids"]["imdb"] if i["movie"]["ids"]["imdb"] != None and i["movie"]["ids"]["imdb"] != "" else i["movie"]["ids"]["tmdb"] for i in items ] ids = [str(ii) for ii in vals] ## Make list of local shows not in watchlist del_list = [x for x in shows if x not in ids] plugin.log.debug("del_list_movie: " + str(del_list)) if del_list: remove_unlisted_movie(del_list)
def add_tvshow_to_library(library_folder, show, play_plugin = None): clean_needed = False id = show['id'] showname = to_utf8(show['seriesname']) ## Create show folder enc_show = showname.translate(None, '\/:*?"<>|').strip('.') show_folder = os.path.join(library_folder, str(id)+'/') if not xbmcvfs.exists(show_folder): try: xbmcvfs.mkdir(show_folder) except: pass # Create play with file if play_plugin is not None: player_filepath = os.path.join(show_folder, 'player.info') player_file = xbmcvfs.File(player_filepath, 'w') content = "{0}".format(play_plugin) player_file.write(content) player_file.close() # Create nfo file nfo_filepath = os.path.join(show_folder, 'tvshow.nfo') if not xbmcvfs.exists(nfo_filepath): nfo_file = xbmcvfs.File(nfo_filepath, 'w') content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id) nfo_file.write(content) nfo_file.close() ## Get existing items in library # get all ids of the show ids = [id, show.get('imdb_id', None)] # TODO: add tmdb! ids = [x for x in ids if x] # get show episodes in library try: # if not plugin.get_setting(SETTING_CHECK_LIBRARY_DUPS, converter=bool): # raise Exception() # get tvshow from library libshows = RPC.VideoLibrary.GetTVShows(properties=["imdbnumber", "title", "year"])['tvshows'] libshows = [i for i in libshows if str(i['imdbnumber']) in ids or (str(i['year']) == str(show.get('year', 0)) and equals(show['seriesname'], i['title']))] libshow = libshows[0] # get existing (non strm) episodes in library libepisodes = RPC.VideoLibrary.GetEpisodes(filter={"and": [ {"field": "tvshow", "operator": "is", "value": to_utf8(libshow['title'])}]}, properties=["season", "episode", "file"])['episodes'] libepisodes = [(int(i['season']), int(i['episode'])) for i in libepisodes if not i['file'].endswith(".strm")] except: libepisodes = [] ## Create content strm files for (season_num,season) in show.items(): if season_num == 0: # or not season.has_aired(): continue for (episode_num, episode) in season.items(): if episode_num == 0: continue delete = False if not episode.has_aired(flexible=True): delete = True #break if delete or (season_num, episode_num) in libepisodes: if library_tv_remove_strm(show, show_folder, id, season_num, episode_num): clean_needed = True else: library_tv_strm(show, show_folder, id, season_num, episode_num) files, dirs = xbmcvfs.listdir(show_folder) if not dirs: shutil.rmtree(show_folder) clean_needed = True return clean_needed
def add_tvshow_to_library(library_folder, show, play_plugin=None): clean_needed = False id = show['id'] showname = to_utf8(show['seriesname']) if showname == "None" or showname == None: show_folder = os.path.join(library_folder, str(id) + '/') if os.path.isdir(show_folder): return shutil.rmtree(show_folder) playlist_folder = plugin.get_setting(SETTING_TV_PLAYLIST_FOLDER, unicode) if not xbmcvfs.exists(playlist_folder): try: xbmcvfs.mkdir(playlist_folder) except: dialogs.notify(msg=_( 'Creation of [COLOR limegreen]M[/COLOR]etalli[COLOR limegreen]Q[/COLOR] 4[COLOR limegreen]Q[/COLOR]ed Playlist Folder' ), title=_('Failed'), delay=5000, image=get_icon_path("lists")) playlist_file = os.path.join(playlist_folder, id + ".xsp") if not xbmcvfs.exists(playlist_file): playlist_file = xbmcvfs.File(playlist_file, 'w') content = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><smartplaylist type="tvshows"><name>%s</name><match>all</match><rule field="path" operator="contains"><value>%s%s</value></rule><rule field="playcount" operator="is"><value>0</value></rule><order direction="ascending">numepisodes</order></smartplaylist>' % ( showname, plugin.get_setting( SETTING_TV_LIBRARY_FOLDER, str).replace( 'special://profile', ''), str(id)) playlist_file.write(str(content)) playlist_file.close() ## Create show folder enc_show = showname.translate(None, '\/:*?"<>|').strip('.') show_folder = os.path.join(library_folder, str(id) + '/') if not xbmcvfs.exists(show_folder): try: xbmcvfs.mkdir(show_folder) except: pass # Create play with file if play_plugin is not None: player_filepath = os.path.join(show_folder, 'player.info') player_file = xbmcvfs.File(player_filepath, 'w') content = "{0}".format(play_plugin) player_file.write(content) player_file.close() # Create nfo file nfo_filepath = os.path.join(show_folder, 'tvshow.nfo') if not xbmcvfs.exists(nfo_filepath): nfo_file = xbmcvfs.File(nfo_filepath, 'w') content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id) nfo_file.write(content) nfo_file.close() ## Get existing items in library # get all ids of the show ids = [id, show.get('imdb_id', None)] # TODO: add tmdb! ids = [x for x in ids if x] # get show episodes in library try: # get tvshow from library libshows = RPC.VideoLibrary.GetTVShows( properties=["imdbnumber", "title", "year"])['tvshows'] libshows = [ i for i in libshows if str(i['imdbnumber']) in ids or ( str(i['year']) == str(show.get('year', 0)) and equals(show['seriesname'], i['title'])) ] libshow = libshows[0] # get existing (non strm) episodes in library libepisodes = RPC.VideoLibrary.GetEpisodes( filter={ "and": [{ "field": "tvshow", "operator": "is", "value": to_utf8(libshow['title']) }] }, properties=["season", "episode", "file"])['episodes'] libepisodes = [(int(i['season']), int(i['episode'])) for i in libepisodes if not i['file'].endswith(".strm")] except: libepisodes = [] ## Create content strm files for (season_num, season) in show.items(): if season_num == 0: # or not season.has_aired(): continue for (episode_num, episode) in season.items(): if episode_num == 0: continue delete = False if plugin.get_setting(SETTING_AIRED_UNKNOWN, bool) == True: aired_unknown = True else: aired_unknown = False if not episode.has_aired(flexible=aired_unknown): delete = True #break if delete or (season_num, episode_num) in libepisodes: if library_tv_remove_strm(show, show_folder, id, season_num, episode_num): clean_needed = True else: library_tv_strm(show, show_folder, id, season_num, episode_num) files, dirs = xbmcvfs.listdir(show_folder) if not dirs: shutil.rmtree(show_folder) clean_needed = True # if xbmc.getCondVisibility("system.hasaddon(script.qlickplay)"): xbmc.executebuiltin("RunScript(script.qlickplay,info=afteradd)") # elif xbmc.getCondVisibility("system.hasaddon(script.extendedinfo)"): xbmc.executebuiltin("RunScript(script.extendedinfo,info=afteradd)") return clean_needed
def add_tvshow_to_library(library_folder, show, play_plugin = None): clean_needed = False id = show['id'] showname = to_utf8(show['seriesname']) if showname == "None" or showname == None: show_folder = os.path.join(library_folder, str(id)+'/') if os.path.isdir(show_folder): return shutil.rmtree(show_folder) playlist_folder = plugin.get_setting(SETTING_TV_PLAYLIST_FOLDER, unicode) if not xbmcvfs.exists(playlist_folder): try: xbmcvfs.mkdir(playlist_folder) except: dialogs.notify(msg=_('Creation of [COLOR ff0084ff]M[/COLOR]etalli[COLOR ff0084ff]Q[/COLOR] Playlist Folder'), title=_('Failed'), delay=5000, image=get_icon_path("lists")) playlist_file = os.path.join(playlist_folder, id+".xsp") if not xbmcvfs.exists(playlist_file): playlist_file = xbmcvfs.File(playlist_file, 'w') content = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><smartplaylist type="tvshows"><name>%s</name><match>all</match><rule field="path" operator="contains"><value>%s%s</value></rule><rule field="playcount" operator="is"><value>0</value></rule><order direction="ascending">numepisodes</order></smartplaylist>' % (showname, plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, str).replace('special://profile',''), str(id)) playlist_file.write(str(content)) playlist_file.close() ## Create show folder enc_show = showname.translate(None, '\/:*?"<>|').strip('.') show_folder = os.path.join(library_folder, str(id)+'/') if not xbmcvfs.exists(show_folder): try: xbmcvfs.mkdir(show_folder) except: pass # Create play with file if play_plugin is not None: player_filepath = os.path.join(show_folder, 'player.info') player_file = xbmcvfs.File(player_filepath, 'w') content = "{0}".format(play_plugin) player_file.write(content) player_file.close() # Create nfo file nfo_filepath = os.path.join(show_folder, 'tvshow.nfo') if not xbmcvfs.exists(nfo_filepath): nfo_file = xbmcvfs.File(nfo_filepath, 'w') content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id) nfo_file.write(content) nfo_file.close() ## Get existing items in library # get all ids of the show ids = [id, show.get('imdb_id', None)] # TODO: add tmdb! ids = [x for x in ids if x] # get show episodes in library try: # get tvshow from library libshows = RPC.VideoLibrary.GetTVShows(properties=["imdbnumber", "title", "year"])['tvshows'] libshows = [i for i in libshows if str(i['imdbnumber']) in ids or (str(i['year']) == str(show.get('year', 0)) and equals(show['seriesname'], i['title']))] libshow = libshows[0] # get existing (non strm) episodes in library libepisodes = RPC.VideoLibrary.GetEpisodes(filter={"and": [ {"field": "tvshow", "operator": "is", "value": to_utf8(libshow['title'])}]}, properties=["season", "episode", "file"])['episodes'] libepisodes = [(int(i['season']), int(i['episode'])) for i in libepisodes if not i['file'].endswith(".strm")] except: libepisodes = [] ## Create content strm files for (season_num,season) in show.items(): if season_num == 0 and not plugin.get_setting(SETTING_INCLUDE_SPECIALS, bool): continue if not season.has_aired(flexible=plugin.get_setting(SETTING_AIRED_UNKNOWN, bool)): continue for (episode_num, episode) in season.items(): if not season_num == 0 and not episode.has_aired(flexible=plugin.get_setting(SETTING_AIRED_UNKNOWN, bool)): continue delete = False if not episode.has_aired(flexible=plugin.get_setting(SETTING_AIRED_UNKNOWN, bool)): delete = True if delete or (season_num, episode_num) in libepisodes: if library_tv_remove_strm(show, show_folder, id, season_num, episode_num): clean_needed = True else: library_tv_strm(show, show_folder, id, season_num, episode_num) files, dirs = xbmcvfs.listdir(show_folder) if not dirs: shutil.rmtree(show_folder) clean_needed = True # if xbmc.getCondVisibility("system.hasaddon(script.qlickplay)"): xbmc.executebuiltin("RunScript(script.qlickplay,info=afteradd)") # elif xbmc.getCondVisibility("system.hasaddon(script.extendedinfo)"): xbmc.executebuiltin("RunScript(script.extendedinfo,info=afteradd)") return clean_needed
def patch(mode): import xbmcaddon adir = "special://home/addons/" AUTOS = eval(plugin.get_setting(SETTING_AUTOPATCHES, unicode)) # try: AUTOS = plugin.get_setting(SETTING_AUTOPATCHES, unicode) # except: AUTOS = [[], [], [], []] # return [p for p in get_players() if p.id in AUTOS] # xbmc.log("QQQQQ AUTOS = {0}".format(str(AUTOS)), xbmc.LOGNOTICE) INSTALLED = [i for i in xbmcvfs.listdir(adir)[0]] PATCHES = [ [], ["resources/lib/modules/control.py", "pass", "sys.exit()"], [ "default.py", "", "\n cool_down_active = kodi.get_setting('cool_down') == 'true'\n if not salts_utils.is_salts() or cool_down_active:\n kodi.notify(msg=i18n('playback_limited'))\n return False" ], [ "lib/dudehere/routines/scrapers/__init__.py", "", "\n\t\tif self._caller not in ALLOWED_CALLERS and self._caller: \n\t\t\tplugin.log('Caller not allowed')\n\t\t\tplugin.raise_error('Violation', 'This addon is not allowed.', 'Please do not use %s with %s' % (self._caller, ADDON_NAME))\n\t\t\tif return_sources:\n\t\t\t\treturn [], [], []\n\t\t\telse:\n\t\t\t\treturn []" ] ] if mode == "auto": if AUTOS != [[], [], [], []]: ADDONS = AUTOS else: if dialogs.yesno( '{0}: Patch'.format(plugin.name), '{0}.[CR]{1} & {2}'.format( _("%s not found") % 'Auto-patches', _("Enable"), _("Continue?"))): return patch("all") else: plugin.set_setting(SETTING_AUTOPATCH, "false") return else: ADDONS = [ [], [ i for i in INSTALLED if i.startswith("plugin.video.") and xbmcvfs.exists("{0}{1}/{2}".format(adir, i, PATCHES[1][0])) ], [ i for i in INSTALLED if i.startswith("plugin.video.") and xbmcvfs.exists("{0}{1}/{2}".format(adir, i, PATCHES[2][0])) ], [ i for i in INSTALLED if i.startswith("script.module.") and xbmcvfs.exists("{0}{1}/{2}".format(adir, i, PATCHES[3][0])) ] ] count = 0 for i in range(1, len(ADDONS)): for a in ADDONS[i]: count = count + 1 b = "{0}{1}/{2}".format(adir, a, PATCHES[i][0]) c = xbmcvfs.File(b) d = c.read() c.close() if PATCHES[i][2] in d: ADDON = xbmcaddon.Addon(a) if mode == "auto" or dialogs.yesno( '{0}: Patch "{1}"?'.format(plugin.name, ADDON.getAddonInfo("name")), '"{0}" {1} block-code.[CR]{2}'.format( ADDON.getAddonInfo("name"), _("contains"), _("Would you like to remove it from the library?"). replace(_("Library").lower(), _("Add-on").lower()))): h = xbmcvfs.File(b, 'w') d = d.replace(PATCHES[i][2], PATCHES[i][1]) result = h.write(d) h.close() if mode != "auto" and dialogs.yesno( "{0}: {1} Patch?".format(plugin.name, _("Auto")), '"{0}"[CR]{1} {2} re-patching?'.format( ADDON.getAddonInfo("name"), _("Enable"), _("Auto").lower())): if ADDON.getAddonInfo("id") not in AUTOS[i]: AUTOS[i].append(ADDON.getAddonInfo("id")) if AUTOS != [[], [], [], []] and AUTOS != ADDONS: plugin.set_setting(SETTING_AUTOPATCHES, AUTOS)