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 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 music_add_artist_to_library(artist_name): import math library_folder = setup_library( plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode)) album_results = lastfm.get_artist_top_albums(artist_name) total_albums = len(album_results) index = 0 pDialog = xbmcgui.DialogProgress() pDialog.create( 'MetalliQ', _("{0} {1} {2}").format(_("Adding"), artist_name, _("to library"))) for album in album_results["album"]: album_name = to_utf8(album["name"]) percent_done = int(math.floor((float(index) / total_albums) * 100)) pDialog.update( percent_done, _("{0} {1} - {2} {3}").format(_("Adding"), artist_name, album_name, _("to library"))) track_results = lastfm.get_album_info(artist_name, album_name) for track in track_results["tracks"]["track"]: if pDialog.iscanceled(): pDialog.update(0) return track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) index += 1 pDialog.update(0) scan_library(type="music")
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 movies_batch_add_to_library(): """ Batch add movies to library """ movie_batch_file = plugin.get_setting(SETTING_MOVIES_BATCH_ADD_FILE_PATH) if xbmcvfs.exists(movie_batch_file): try: f = open(xbmc.translatePath(movie_batch_file), 'r') r = f.read() f.close() ids = r.split('\n') except: return plugin.notify(msg='Movies Batch Add File', title='Not found', delay=3000, image=get_icon_path("movies")) library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) import_tmdb() for id in ids: if "," in id: csvs = id.split(',') for csv in csvs: if not str(csv).startswith("tt") and csv != "": movie = tmdb.Movies(csv).info() id = movie.get('imdb_id') batch_add_movies_to_library(library_folder, id) else: if not str(id).startswith("tt") and id != "": movie = tmdb.Movies(id).info() id = movie.get('imdb_id') batch_add_movies_to_library(library_folder, id) os.remove(xbmc.translatePath(movie_batch_file)) if xbmcvfs.exists(plugin.get_setting(SETTING_TV_BATCH_ADD_FILE_PATH)): xbmc.executebuiltin("RunPlugin(plugin://plugin.video.metalliq/tv/batch_add_to_library)") return True else: xbmc.sleep(1000) plugin.notify(msg='Added movie strm-files', title='Starting library scan', delay=3000, image=get_icon_path("movies")) scan_library(type="video") return True elif xbmcvfs.exists(plugin.get_setting(SETTING_TV_BATCH_ADD_FILE_PATH)): xbmc.executebuiltin("RunPlugin(plugin://plugin.video.metalliq/tv/batch_add_to_library)")
def music_add_album_to_library(artist_name, album_name): library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode)) results = lastfm.get_album_info(artist_name, album_name) for track in results["tracks"]["track"]: track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) scan_library(type="music")
def music_add_artist_to_library(artist_name): import math library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER)) album_results = lastfm.get_artist_top_albums(artist_name) total_albums = len(album_results) index = 0 pDialog = xbmcgui.DialogProgress() pDialog.create( "[COLOR ff0084ff]M[/COLOR]etalli[COLOR ff0084ff]Q[/COLOR]", _("{0} {1} {2}").format(_("Adding"), artist_name, _("to library")), ) for album in album_results["album"]: album_name = to_utf8(album["name"]) percent_done = int(math.floor((float(index) / total_albums) * 100)) pDialog.update( percent_done, _("{0} {1} - {2} {3}").format(_("Adding"), artist_name, album_name, _("to library")) ) track_results = lastfm.get_album_info(artist_name, album_name) for track in track_results["tracks"]["track"]: if pDialog.iscanceled(): pDialog.update(0) return track_name = to_utf8(track["name"]) add_music_to_library(library_folder, artist_name, album_name, track_name) index += 1 pDialog.update(0) scan_library(type="music")
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 movies_batch_add_to_library(): """ Batch add movies to library """ movie_batch_file = plugin.get_setting(SETTING_MOVIES_BATCH_ADD_FILE_PATH, unicode) if xbmcvfs.exists(movie_batch_file): try: f = open(xbmc.translatePath(movie_batch_file), 'r') r = f.read() f.close() ids = r.split('\n') except: return dialogs.notify(msg='Movies Batch Add File', title=_("%s not found").replace("%s ",""), delay=3000, image=get_icon_path("movies")) library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) import_tmdb() for id in ids: if "," in id: csvs = id.split(',') for csv in csvs: if not str(csv).startswith("tt") and csv != "": movie = tmdb.Movies(csv).info() csv = movie.get('imdb_id') batch_add_movies_to_library(library_folder, csv) else: if not str(id).startswith("tt") and id != "": movie = tmdb.Movies(id).info() id = movie.get('imdb_id') batch_add_movies_to_library(library_folder, id) os.remove(xbmc.translatePath(movie_batch_file)) if xbmcvfs.exists(plugin.get_setting(SETTING_TV_BATCH_ADD_FILE_PATH, unicode)): xbmc.executebuiltin("RunPlugin(plugin://plugin.video.chappaai/tv/batch_add_to_library)") return True else: xbmc.sleep(1000) dialogs.notify(msg='Added movie strm-files', title='Starting library scan', delay=3000, image=get_icon_path("movies")) scan_library(type="video") return True if xbmcvfs.exists(plugin.get_setting(SETTING_TV_BATCH_ADD_FILE_PATH, unicode)): xbmc.executebuiltin("RunPlugin(plugin://plugin.video.chappaai/tv/batch_add_to_library)")
def movies_add_to_library(src, id): """ Add movie to library """ library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) date = None if src == "tmdb": import_tmdb() movie = tmdb.Movies(id).info() date = date_to_timestamp(movie.get('release_date')) imdb_id = movie.get('imdb_id') if imdb_id: src = "imdb" id = imdb_id players = active_players("movies") if plugin.get_setting(SETTING_MOVIES_DEFAULT_AUTO_ADD, bool) == True: player = plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY, unicode) else: players.insert(0, ADDON_SELECTOR) players.insert(0, ADDON_DEFAULT) selection = dialogs.select(_("Play using..."), [p.title for p in players]) if selection == -1: return player = players[selection] # setup library folder library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) # add to library if plugin.get_setting(SETTING_MOVIES_DEFAULT_AUTO_ADD, bool) == True: add_movie_to_library(library_folder, src, id, play_plugin=plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY, unicode)) else: add_movie_to_library(library_folder, src, id, play_plugin=player.id) dialogs.notify(msg=player.id, title=_("%s not found").replace("%s ",""), delay=3000, image=get_icon_path("movies")) scan_library(type="video")
def movies_add_to_library(src, id): """ Add movie to library """ library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) date = None if src == "tmdb": import_tmdb() movie = tmdb.Movies(id).info() date = date_to_timestamp(movie.get('release_date')) imdb_id = movie.get('imdb_id') if imdb_id: src = "imdb" id = imdb_id players = active_players("movies") if plugin.get_setting(SETTING_MOVIES_DEFAULT_AUTO_ADD, bool) == True: player = plugin.get_setting(SETTING_MOVIES_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_MOVIES_LIBRARY_FOLDER)) # add to library if plugin.get_setting(SETTING_MOVIES_DEFAULT_AUTO_ADD, bool) == True: add_movie_to_library(library_folder, src, id, play_plugin=plugin.get_setting(SETTING_MOVIES_DEFAULT_PLAYER_FROM_LIBRARY, unicode)) else: add_movie_to_library(library_folder, src, id, play_plugin=ADDON_DEFAULT.id) 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 scan_library(type="video", path=plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode))
def music_add_to_library(artist_name, track_name, album_name): if album_name == "None": album_name = lastfm.get_track_info(artist_name, track_name)["album"]["title"] library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode)) add_music_to_library(library_folder, artist_name, album_name, track_name) scan_library(type="music")
def music_add_to_library(artist_name, track_name, album_name): if album_name == "None": album_name = lastfm.get_track_info(artist_name, track_name)["album"]["title"] library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER)) add_music_to_library(library_folder, artist_name, album_name, track_name) scan_library(type="music")
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 movies_add_all_to_library(items): library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) for item in items: ids = item["movie"]["ids"] if ids.get('imdb'): add_movie_to_library(library_folder, "imdb", ids["imdb"], None) elif ids.get('tmdb'): add_movie_to_library(library_folder, "tmdb", ids["tmdb"], None) else: plugin.log.error("movie %s is missing both imdb and tmdb ids" % ids['slug']) scan_library(type="video")
def update_library(): """ Update library """ url = plugin.get_setting(SETTING_MOVIES_SERVER_URL, converter=str) if not url: return # Get movies list from movies-server movies = query_movies_server(url) # setup library folder library_folder = setup_library( plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) changed = False # add new movies for movie in movies: date = int(movie.get('date', 0)) imdb = movie.get('imdb') tmdb = movie.get('tmdb') if imdb: if add_movie_to_library(library_folder, "imdb", imdb, date): changed = True elif tmdb: if add_movie_to_library(library_folder, "tmdb", tmdb, date): changed = True # remove old movies from DB keep_movies = [movie['imdb'] for movie in movies] db_movies = RPC.video_library.get_movies( properties=['title', 'imdbnumber', 'file']) for movie in db_movies.get('movies', []): file = xbmc.translatePath(movie['file']) imdb = os.path.splitext(os.path.basename(file))[0] if imdb not in keep_movies and plugin.id in file: # remove movie RPC.video_library.remove_movie(movieid=movie["movieid"]) # remove strm and nfo files os.remove(file) try: os.remove(file.replace(".strm", ".nfo")) except: pass changed = True if changed: scan_library()
def movies_add_all_to_library(items): library_folder = setup_library( plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) for item in items: ids = item["movie"]["ids"] if ids.get('imdb'): add_movie_to_library(library_folder, "imdb", ids["imdb"], None) elif ids.get('tmdb'): add_movie_to_library(library_folder, "tmdb", ids["tmdb"], None) else: plugin.log.error("movie %s is missing both imdb and tmdb ids" % ids['slug']) scan_library(type="video")
def movies_add_to_library_parsed(src, id, player): library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER, unicode)) date = None if src == "tmdb": import_tmdb() movie = tmdb.Movies(id).info() date = date_to_timestamp(movie.get('release_date')) imdb_id = movie.get('imdb_id') if imdb_id: if imdb_id != None and imdb_id != "": src = "imdb" id = imdb_id add_movie_to_library(library_folder, src, id, player) scan_library(type="video")
def update_library(): """ Update library """ url = plugin.get_setting(SETTING_MOVIES_SERVER_URL, converter=str) if not url: return # Get movies list from movies-server movies = query_movies_server(url) # setup library folder library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) changed = False # add new movies for movie in movies: date = int(movie.get('date', 0)) imdb = movie.get('imdb') tmdb = movie.get('tmdb') if imdb: if add_movie_to_library(library_folder, "imdb", imdb, date): changed = True elif tmdb: if add_movie_to_library(library_folder, "tmdb", tmdb, date): changed = True # remove old movies from DB keep_movies = [movie['imdb'] for movie in movies] db_movies = RPC.video_library.get_movies(properties=['title', 'imdbnumber','file']) for movie in db_movies.get('movies', []): file = xbmc.translatePath(movie['file']) imdb = os.path.splitext(os.path.basename(file))[0] if imdb not in keep_movies and plugin.id in file: # remove movie RPC.video_library.remove_movie(movieid=movie["movieid"]) # remove strm and nfo files os.remove(file) try: os.remove(file.replace(".strm", ".nfo")) except: pass changed = True if changed: scan_library()
def movies_add_to_library(id): """ Add movie to library """ library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) # TODO: we actually prefer tmdb... import_tmdb() movie = tmdb.Movies(id).info() imdb_id = movie.get('imdb_id') date = date_to_timestamp(movie.get('release_date')) if imdb_id: add_movie_to_library(library_folder, "imdb", imdb_id, date) else: add_movie_to_library(library_folder, "tmdb", id, date) scan_library()
def movies_add_to_library(src, id): """ Add movie to library """ library_folder = setup_library(plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) date = None if src == "tmdb": import_tmdb() movie = tmdb.Movies(id).info() date = date_to_timestamp(movie.get('release_date')) imdb_id = movie.get('imdb_id') if imdb_id: src = "imdb" id = imdb_id add_movie_to_library(library_folder, src, id, date) scan_library()
def movies_add_to_library(src, id): """ Add movie to library """ library_folder = setup_library( plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER)) date = None if src == "tmdb": import_tmdb() movie = tmdb.Movies(id).info() date = date_to_timestamp(movie.get('release_date')) imdb_id = movie.get('imdb_id') if imdb_id: src = "imdb" id = imdb_id add_movie_to_library(library_folder, src, id, date) 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 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(): # setup library folder library_folder = plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode) if not xbmcvfs.exists(library_folder): return scan_library(type="music")
def update_library(): # setup library folder library_folder = plugin.get_setting(SETTING_MOVIES_LIBRARY_FOLDER) if not xbmcvfs.exists(library_folder): return scan_library(type="video")