Commits

Marcin Kasperski  committed 78b8597

Option --title-from-name added to calibre_add_if_missing (forcing filename as title whatever is the format)

  • Participants
  • Parent commits fd85219

Comments (0)

Files changed (1)

File src/mekk/calibre/scripts/add_if_missing.py

 
     calibre_add_if_missing *.pdf *.djvu subdir/*.pdf
 
+There are also some useful options, run --help to see them.
+
 """
 
 import shutil
     parser.add_option("-m", "--move",
                       action="store", type="string", dest="move",
                       help="Move source files to given directory after adding them")
+    parser.add_option("-n", "--title-from-name",
+                      action="store_true", default=False, dest="title_from_name",
+                      help="Always use file name as book title (by default we use file name for doc/rtf/txt, but embedded matadata for pdf, epub, mobi and other formats).")
     (options, args) = parser.parse_args()
     if not args:
         parser.error("""No file or directory specified. Execute with:
             # force filename into the title to know what is the book about.
             # TODO: make this behaviour an option
             base_file_name = os.path.basename(file_name)
-            m = re.match("^(.*)\.(rtf|docx?|txt)$", base_file_name)
+            m = re.match("^(.*)\.([a-z]+)$", base_file_name)
+            #m = re.match("^(.*)\.(rtf|docx?|txt)$", base_file_name)
+            force_title = None
             if m:
-                force_title = m.group(1)
-            else:
-                force_title = None
+                if options.title_from_name  or ( m.group(2) in ['txt', 'doc', 'docx', 'rtf'] ):
+                    force_title = m.group(1)
 
             add_to_calibre(file_name,
                            force_title=force_title,