def omdb_force_update(show_s): success_count = 0 pr.info("force-updating omdb-data for {}".format(show_s)) show_d = db.data(show_s) nfo_imdb = tvtool.nfo_to_imdb(show_d) if nfo_imdb: if show_d["imdb"] != nfo_imdb: show_d["imdb"] = nfo_imdb need_update = True pr.info( f"found new (hopefully) imdb-id [{nfo_imdb}] in nfo for {show_s}" ) omdb_result = tvtool.omdb_search_show(show_d) show_d["omdb"] = omdb_result season_index = 0 for season_d in show_d["seasons"]: omdb_result = tvtool.omdb_search_season(show_d, season_d["folder"]) show_d["seasons"][season_index]["omdb"] = omdb_result episode_index = 0 for episode_d in season_d["episodes"]: if episode_d["status"] == "deleted": continue omdb_result = tvtool.omdb_search_episode(show_d, season_d["folder"], episode_d["file"]) show_d["seasons"][season_index]["episodes"][episode_index][ "omdb"] = omdb_result episode_index += 1 season_index += 1 db.update(show_d["folder"], show_d, key=None) db.save() ftool.copy_dbs_to_webserver("tv")
def check_status(): pr.info("confirming episode status flags...") need_save = False for ep in __flatten_eps(): if ep["status"] == "deleted": if ftool.is_existing_file(ep['full_path']): pr.warning(f"not deleted: [{ep['full_path']}]") si = ep["season_index"] ei = ep["episode_index"] show_d = db.data(ep["show"]) show_d["seasons"][si]["episodes"][ei]['status'] = "ok" db.update(ep["show"], db.data(ep["show"], key=None)) need_save = True else: if not ftool.is_existing_file(ep['full_path']): pr.info(f"found deleted: [{ep['full_path']}]") si = ep["season_index"] ei = ep["episode_index"] show_d = db.data(ep["show"]) show_d["seasons"][si]["episodes"][ei]['status'] = "deleted" db.update(ep["show"], db.data(ep["show"], key=None)) need_save = True if need_save: db.save() ftool.copy_dbs_to_webserver("tv")
def omdb_update(): pr.info("trying to omdb-search for missing data") save_db = False success_count = 0 for show_s in db.list_shows(): if in_skip_list(show_s): pr.info(f"skipping {show_s}, in skip list...") continue need_update = False show_d = db.data(show_s) nfo_imdb = tvtool.nfo_to_imdb(show_d) if nfo_imdb: if show_d["imdb"] != nfo_imdb: show_d["imdb"] = nfo_imdb need_update = True pr.info( f"found new (hopefully) imdb-id [{nfo_imdb}] in nfo for {show_s}" ) if not show_d["omdb"]: omdb_result = tvtool.omdb_search_show(show_d) if omdb_result: show_d["omdb"] = omdb_result need_update = True success_count += 1 season_index = 0 for season_d in show_d["seasons"]: if not season_d["omdb"]: omdb_result = tvtool.omdb_search_season( show_d, season_d["folder"]) if omdb_result: show_d["seasons"][season_index]["omdb"] = omdb_result need_update = True success_count += 1 episode_index = 0 for episode_d in season_d["episodes"]: if episode_d["status"] == "deleted": continue if not episode_d["omdb"]: omdb_result = tvtool.omdb_search_episode( show_d, season_d["folder"], episode_d["file"]) if omdb_result: need_update = True success_count += 1 show_d["seasons"][season_index]["episodes"][ episode_index]["omdb"] = omdb_result episode_index += 1 season_index += 1 if need_update: save_db = True db.update(show_d["folder"], show_d, key=None) pr.info("done!") if success_count > 0: pr.info("successfully updated omdb-data for {} items".format( success_count)) if save_db: db.save() ftool.copy_dbs_to_webserver("tv")
def db_maintainance(): pr.info("running moviedb maintainance...") need_save = False for mov in mlist: if db.movie_data(mov, 'status') == "deleted": continue full_path = os.path.join(mov_root, db.movie_data(mov, 'letter'), db.movie_data(mov, 'folder')) # Update movies with missing status if not db.movie_data(mov, 'status'): if os.path.isdir(full_path): db.update(mov, 'status', "ok") need_save = True if not db.movie_data(mov, 'nfo') or not db.movie_data(mov, 'imdb'): if try_add_nfo(mov): need_save = True # Try to update missing omdb-data data = db.movie_data(mov, 'omdb') if not data or 'Error' in data: if update_omdb_search(mov): need_save = True # Wrong title... elif "Title" in data and data['Title'].startswith("#"): pr.warning(f"{mov} has faulty title: [{data['Title']}]") if update_omdb_search(mov): if "Title" in data and not data['Title'].startswith("#"): need_save = True elif data['Title'].startswith("#"): pr.info("omdb data still contains faulty title, using folder as title") title = mtool.determine_title(db.movie_data(mov, 'folder')) pr.info(f"guessed title: [{title}]") data['Title'] = title db.update(mov, 'omdb', data) need_save = True sub_data = db.movie_data(mov, 'subs') for lang in ['en', 'sv']: if not sub_data[lang]: sub = mtool.has_subtitle(full_path, lang) if sub: pr.info(f"found [{lang}] sub for {mov}") sub_data[lang] = sub db.update(mov, 'subs', sub_data) need_save = True if need_save: db.save() ftool.copy_dbs_to_webserver("movie") else: pr.info("nothing updated")
def scan_for_deleted_movies(): pr.info("scanning for deleted movies...") need_save = False for mov in mlist: if db.movie_data(mov, 'status') == "deleted": continue path_to_check = os.path.join(mov_root, db.movie_data(mov, 'letter'), db.movie_data(mov, 'folder')) if not os.path.isdir(path_to_check): pr.info("folder deleted: {}".format(path_to_check)) db.update(mov, 'status', "deleted") need_save = True if need_save: db.save() ftool.copy_dbs_to_webserver("movie") else: pr.info("nothing updated")
def se_upper(): need_save = False for ep in __flatten_eps(): if not ep["se"] or ep["status"] == "deleted": continue if ep["se"].startswith("s"): si = ep["season_index"] ei = ep["episode_index"] show_d = db.data(ep["show"]) pr.info( f"found lowercase: {show_d['seasons'][si]['episodes'][ei]['se']}" ) show_d["seasons"][si]["episodes"][ei]["se"] = ep["se"].upper() db.update(ep["show"], show_d, key=None) pr.info(f"upper: {ep['se'].upper()}") need_save = True if need_save: db.save() ftool.copy_dbs_to_webserver("tv")
def scan_all_subtitles(): pr.info("scanning for subs") save_db = False new_count = 0 for ep in __flatten_eps(): if ep["status"] == "deleted": continue si = ep["season_index"] ei = ep["episode_index"] if not "subs" in ep: show_d = db.data(ep["show"]) show_d["seasons"][si]["episodes"][ei]['subs'] = { 'sv': None, 'en': None } ep["subs"] = {'sv': None, 'en': None} db.update(ep["show"], show_d, key=None) save_db = True if not ep['subs']['sv']: sv_srt_file = tvtool.has_subtitle(ep["show"], ep["file"], "sv") if sv_srt_file: show_d = db.data(ep["show"]) show_d["seasons"][si]["episodes"][ei]['subs'][ 'sv'] = sv_srt_file db.update(ep["show"], show_d, key=None) pr.info(f"found [{sv_srt_file}]") save_db = True if not ep['subs']['en']: en_srt_file = tvtool.has_subtitle(ep["show"], ep["file"], "en") if en_srt_file: show_d = db.data(ep["show"]) show_d["seasons"][si]["episodes"][ei]['subs'][ 'en'] = en_srt_file db.update(ep["show"], show_d, key=None) pr.info(f"found [{en_srt_file}]") save_db = True pr.info("done!") if save_db: db.save() ftool.copy_dbs_to_webserver("tv")
mov['omdb'] = mtool.omdb_search(mov) mov['subs'] = { 'sv': mtool.has_subtitle(fp, "sv"), 'en': mtool.has_subtitle(fp, "en") } mov['video'] = mtool.get_vid_file(fp) mov['status'] = "ok" pr.info(f"added [{movie}] to database!") db.add(mov) # Scan for new movies... for letter in letters: if letter in _valid_letters: pr.info(f"scanning {letter}") movies = os.listdir(os.path.join(mov_root, letter)) movies.sort() for movie in movies: if movie.startswith("@"): # Diskstation continue if not db.exists(movie): new_movie(letter, movie) new_count += 1 else: continue pr.info(f"done scanning. found ({new_count}) new movies.") if new_count > 0: db.save() ftool.copy_dbs_to_webserver("movie")
if show_s.startswith("@"): # Diskstation continue; if max_scan and new_show_count >= max_scan: pr.info("max new show scan limit reached! breaking") break; pr.info(f"scanning [{show_s}]") if not db.exists(show_s): new_show(show_s) new_show_count += 1 continue; # new_show() adds all new eps and seasons season_folder_list = tvtool.get_season_folder_list(show_s) for season_s in season_folder_list: ep_file_list = tvtool.get_episodes(show_s, season_s) for episode_s in ep_file_list: if not db.has_ep(show_s, episode_s): new_episode_count += 1 show_d = db.data(show_s) episode_d = new_episode(show_d, season_s, episode_s) if not db.has_season(show_s, season_s): season_d = new_season(show_d, season_s) pr.info("found new season!") db.add_season(show_s, season_d) db.add_ep(show_s, season_s, episode_d) pr.info("done scanning!") pr.info(f"found {new_show_count} new shows.") pr.info(f"found {new_episode_count} new episodes.") if new_show_count > 0 or new_episode_count > 0: db.save() ftool.copy_dbs_to_webserver("tv")