diff options
-rwxr-xr-x | imdb-lookup/imdbrating.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/imdb-lookup/imdbrating.py b/imdb-lookup/imdbrating.py index 662b8d9..ff0550b 100755 --- a/imdb-lookup/imdbrating.py +++ b/imdb-lookup/imdbrating.py @@ -39,13 +39,22 @@ def get_rating(imdb_id): return info['movie_results'][0]['vote_average'] return 0 +def print_ratings(files, db): + for filename in files: + if os.path.basename(filename).startswith('.'): + continue + elif os.path.isdir(filename): + print_ratings(map(lambda p: os.path.join(filename, p), os.listdir(filename)), db) + imdb_id = os.path.basename(filename).split('#')[-1] + if imdb_id.startswith('tt'): + if imdb_id not in db.keys() or db[imdb_id] == 0: + db[imdb_id] = str(get_rating(imdb_id)) + print u"{rating} {filename}".format(rating=db[imdb_id], filename=filename.decode('utf-8')) + if __name__ == u"__main__": tmdb.API_KEY = read_key() db = dbm.open(get_db_filename(), 'rw') - - for filename in sys.argv[1:]: - imdb_id = filename.split('#')[-1] - if imdb_id not in db.keys() or db[imdb_id] == 0: - db[imdb_id] = str(get_rating(imdb_id)) - print u"{rating} {filename}".format(rating=db[imdb_id], filename=filename.decode('utf-8')) + files = sum([os.listdir(x) if os.path.isdir(x) else [x] for x in sys.argv[1:]],[]) + print_ratings(files, db) db.close() + |