def __pymoviedb_check(): # check exiftool if __helpers.which('exiftool') is None: print("`exiftool` not found! please install exiftool!") exit(-1) l = _get_folders() for f in l: match = len(re.findall( __cfg.folder_regex, f[1] )) if match == 0: print ( "please rename: \"%s%s\"" % (f[0], f[1])) match = __helpers.getFileMatches(("%s%s" % (f[0], f[1])), tuple(__cfg._exts)) if match is None: print ( "no files found in \"%s%s\"" % (f[0], f[1]))
def __pymoviedb_do(): global movies global err_lines movies = {} err_lines = set() err_lines.add( "# errors logged at program exec at %s\n" % datetime.utcnow() ) if os.path.isfile(_cfg_list_file()): with open(_cfg_list_file()) as data_file: n = json.load(data_file) for v in n: movies[v['imdbID']] = v l = _get_folders() for movie in l: _dir, _name, _cur_dir = movie[0], movie[1], os.getcwd() dat = {} print_v ( "processing: %s\n" % _name ) dat['base'] = _name dat['res'] = 'NA' if __helpers.which('exiftool') is not None: match = __helpers.getFileMatches(_dir + _name, tuple(__cfg._exts)) if match is not None: dat['res'] = __helpers.getFileRes(match) # search s_title = _name.replace("_", " ") imdbid = False res = None skip = False jsondb = None if os.path.isfile(_cfg_imdb_file(movie)): with open(_cfg_imdb_file(movie)) as f: imdbid = f.read() imdbid = imdbid.strip("\r\n") print ( "%s: " % _name, end='' ) sys.stdout.flush() if __cfg.force_regen == True or not os.path.isfile(_cfg_info_file(movie)): print ( "network: ", end='' ) sys.stdout.flush() if (imdbid): try: res = omdb.request(i=imdbid) except: skip = True else: try: res = omdb.request(t=s_title) except: skip = True if not skip: jsondb = json.loads(res.content.decode('utf-8')) else: jsondb = None print ( "fail", end='' ) else: # force_regen == false print ( "file: ", end='' ) sys.stdout.flush() with open(_cfg_info_file(movie)) as f: jsondb = json.loads(f.read()) if len(jsondb) == 0: jsondb = None print ( "fail", end='' ) else: print ( "ok", end='' ) if jsondb == None or skip or 'Error' in jsondb.keys(): print ( "...skip" ) err_lines.add( "skipping %s%s\n" % (_dir, _name) ) # continue with next movie continue # goto next line print ( "\n", end='' ) dat['Title'] = jsondb['Title'] dat['imdbID'] = jsondb['imdbID'] dat['Year'] = jsondb['Year'] dat['Released'] = jsondb['Released'] dat['imdbRating'] = jsondb['imdbRating'] dat['Language'] = jsondb['Language'] movies[dat['imdbID']] = dat with open(_cfg_info_file(movie), 'w') as f: json.dump(dat, f, indent=2) # for movie in l: end # sort back movies n = sorted(movies.values(), key=itemgetter('base')) movies = {} for v in n: movies[v['imdbID']] = v # write moviews with open(_cfg_list_file(), "w") as f: json.dump(n, f, indent=2) # write err with open(_cfg_err_file(), "w") as f: f.writelines(sorted(err_lines))