summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmovietool/__init__.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/movietool/__init__.py b/movietool/__init__.py
index 6084c70..f90d8e3 100755
--- a/movietool/__init__.py
+++ b/movietool/__init__.py
@@ -448,7 +448,17 @@ def do_rename(args):
def substitute_filename(filename):
"""remove potentially harmful characters from filename"""
return re.sub(u"[^a-zA-Z0-9()\- _#]", u"_", filename)
-
+
+ def make_filename(result):
+ main_title = result["alternative_title"]
+ orig_title = result["original_title"]
+
+ filename = "{main_title} ({result[year]})".format(**locals())
+ if main_title != orig_title:
+ filename += " #{orig_title}".format(**locals())
+ filename += " #{result[imdb_id]}".format(**locals())
+ return filename
+
for input_file in args.file:
countrycode = locale.getdefaultlocale()[0][3:5]
db = Protector(TMDBCache())
@@ -464,7 +474,9 @@ def do_rename(args):
for (i, result) in zip(range(len(results)), results):
result["i"] = i+1
result["year"] = result["release_date"].split("-")[0]
- print("{i} {title} ({year}) - check: http://www.imdb.com/title/{imdb_id}".format(**result))
+ print("{i} {title} ({year})"
+ " (orig.: {original_title}) - check: "
+ "http://www.imdb.com/title/{imdb_id}".format(**result))
result["alternative_title"] = db.alternative_title(result["imdb_id"], locale=countrycode)
if result["alternative_title"] != result["title"]:
print(" a.k.a.: {}".format(result["alternative_title"]))
@@ -482,7 +494,7 @@ def do_rename(args):
print("Skip {}".format(input_file))
continue
- filename = "{alternative_title} ({year}) #{imdb_id}".format(**results[select-1])
+ filename = make_filename(results[select-1])
filename = substitute_filename(filename)
if os.path.exists(input_file):