tagger.py: add -A for audiobook mode option
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Thu, 7 Jul 2016 18:17:24 +0000 (11:17 -0700)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Thu, 7 Jul 2016 18:17:24 +0000 (11:17 -0700)
tagger.py

index 870da42..be22447 100755 (executable)
--- a/tagger.py
+++ b/tagger.py
@@ -44,6 +44,7 @@ import sys
 dry_run = False
 verbose = False
 self_test = False
+audiobook = False
 
 # globals
 total_albums = 0
@@ -85,6 +86,10 @@ music_file_name_re = re.compile(".*/" +
             "(?P<track_name>[^/]*)" +
             "\.[a-zA-Z0123456789]*$")
 
+audiobook_file_name_re = re.compile(".*/" +
+            "(?P<dir_name>[^/]*)/" +
+            "(?P<track_number>[0123456789][0123456789]*)");
+
 dir_name_re = re.compile("(.*/)?" +
             "(?P<artist>[0-9A-Za-z _.\-]*?) - " +
             "(?P<album>[0-9A-Za-z _(),'.\-\+]*)" + 
@@ -229,13 +234,18 @@ class MusicFile(object):
         self.track_number = int(track_number)
 
     def from_filename(filename):
-        match = music_file_name_re.match(filename)
+        if (audiobook):
+            match = audiobook_file_name_re.match(filename)
+            track_name = ""
+        else:
+            match = music_file_name_re.match(filename)
+            track_name = match.group('track_name')
         if (not match):
             raise MusicFileErr("can't parse music file name \"" + 
                             filename + "\"")
         album = Album.from_dirname(match.group('dir_name'))
         return MusicFile(filename, album, 
-                        match.group('track_name'),
+                        track_name,
                         match.group('track_number'))
     from_filename = staticmethod(from_filename)
 
@@ -279,12 +289,13 @@ def Usage():
     print "-h: this help message"
     print "-d: dry-run mode"
     print "-s: self-test"
+    print "-A: audiobook mode"
     print "dirs: directories to search for albums."
     print "This program skips dirs with \"[LL]\" in the name."
     sys.exit(1)
 
 try:
-    optlist, dirs = getopt.getopt(sys.argv[1:], ':dhi:sv')
+    optlist, dirs = getopt.getopt(sys.argv[1:], ':dhi:svA')
 except getopt.GetoptError:
     Usage()
 
@@ -297,6 +308,8 @@ for opt in optlist:
         verbose = True
     if opt[0] == '-s':
         self_test = True
+    if opt[0] == '-A':
+        audiobook = True
 
 if (self_test):
     run_self_test()