Zach Isbach 2 年 前
親
コミット
8b1e75569d
1 ファイル変更、24 行追加、3 行削除
  1. 24 3
      TVDB/main.py

+ 24 - 3
TVDB/main.py

@@ -1,6 +1,7 @@
 # Imports
 import re
 import os
+import pathlib
 import argparse
 from datetime import datetime
 import tvdb_v4_official
@@ -25,8 +26,9 @@ def readConfigLine(file):
 
 # CLI config
 parser = argparse.ArgumentParser('TVDB Renamer')
-parser.add_argument('path', help='The directory containing files to be renamed')
-parser.add_argument('--api', default=default_apikey, required=False, help='Path to a file containing the TVDB API key')
+parser.add_argument('--api', default=default_apikey, help='Path to a file containing the TVDB API key')
+parser.add_argument('--verbose', '-v', action='store_true', help='Display missing and unexpected episodes')
+parser.add_argument('path', type=pathlib.Path, help='The directory containing files to be renamed')
 cli = parser.parse_args()
 if not os.path.isfile(cli.api):
   print('Invalid API key file path: {path}'.format(path=cli.api))
@@ -108,13 +110,32 @@ except Exception as error:
   print('Unable to parse episode data: {e}'.format(e=error))
   exit(1)
 
+# Find unexpected episodes
+if cli.verbose:
+  db_seasons = {}
+  for e in episodes:
+    if not e['season'] in db_seasons:
+      db_seasons[ e['season'] ] = {}
+    if not e['number'] in db_seasons[ e['season'] ]:
+      db_seasons[ e['season'] ][ e['number'] ] = True
+  for snum, s in seasons.items():
+    for enum, elist in s.items():
+      for e in elist:
+        if (
+          not e['season'] in db_seasons or
+          not e['number'] in db_seasons[ e['season'] ]
+        ):
+          print('Unexpected: {f}'.format(f=e['file']))
+  del db_seasons
+
 # Rename matched files
 for e in episodes:
   if (
     not e['season'] in seasons or
     not e['number'] in seasons[ e['season'] ]
   ):
-    #print('Missing: {m}'.format(m=e['filename']))
+    if cli.verbose:
+      print('Missing: {m}'.format(m=e['filename']))
     continue
   files = seasons[ e['season'] ][ e['number'] ]
   for file in files: