]> xmof Git - DeDRM.git/commitdiff
Propagate changes
authorZhuoyun Wei <wzyboy@wzyboy.org>
Wed, 18 Apr 2018 09:23:12 +0000 (05:23 -0400)
committerZhuoyun Wei <wzyboy@wzyboy.org>
Wed, 18 Apr 2018 09:23:12 +0000 (05:23 -0400)
DeDRM_Macintosh_Application/DeDRM.app/Contents/Resources/k4mobidedrm.py
DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/k4mobidedrm.py

index 7875d0795ad97e039a2f48097ddee0a1fd59d0f2..1ce1f3595c2b9f741e1f31553f2d90fce0f02e24 100644 (file)
@@ -262,12 +262,16 @@ def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids):
         traceback.print_exc()
         return 1
 
-    # if we're saving to the same folder as the original, use file name_
-    # if to a different folder, use book name
-    if os.path.normcase(os.path.normpath(outdir)) == os.path.normcase(os.path.normpath(os.path.dirname(infile))):
-        outfilename = os.path.splitext(os.path.basename(infile))[0]
-    else:
-        outfilename = cleanup_name(book.getBookTitle())
+    # Try to infer a reasonable name
+    orig_fn_root = os.path.splitext(os.path.basename(infile))[0]
+    if (
+        re.match('^B[A-Z0-9]{9}(_EBOK|_EBSP|_sample)?$', orig_fn_root) or
+        re.match('^{0-9A-F-}{36}$', orig_fn_root)
+    ):  # Kindle for PC / Mac / Android / Fire / iOS
+        clean_title = cleanup_name(book.getBookTitle())
+        outfilename = '{}_{}'.format(orig_fn_root, clean_title)
+    else:  # E Ink Kindle, which already uses a reasonable name
+        outfilename = orig_fn_root
 
     # avoid excessively long file names
     if len(outfilename)>150:
index 7875d0795ad97e039a2f48097ddee0a1fd59d0f2..1ce1f3595c2b9f741e1f31553f2d90fce0f02e24 100644 (file)
@@ -262,12 +262,16 @@ def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids):
         traceback.print_exc()
         return 1
 
-    # if we're saving to the same folder as the original, use file name_
-    # if to a different folder, use book name
-    if os.path.normcase(os.path.normpath(outdir)) == os.path.normcase(os.path.normpath(os.path.dirname(infile))):
-        outfilename = os.path.splitext(os.path.basename(infile))[0]
-    else:
-        outfilename = cleanup_name(book.getBookTitle())
+    # Try to infer a reasonable name
+    orig_fn_root = os.path.splitext(os.path.basename(infile))[0]
+    if (
+        re.match('^B[A-Z0-9]{9}(_EBOK|_EBSP|_sample)?$', orig_fn_root) or
+        re.match('^{0-9A-F-}{36}$', orig_fn_root)
+    ):  # Kindle for PC / Mac / Android / Fire / iOS
+        clean_title = cleanup_name(book.getBookTitle())
+        outfilename = '{}_{}'.format(orig_fn_root, clean_title)
+    else:  # E Ink Kindle, which already uses a reasonable name
+        outfilename = orig_fn_root
 
     # avoid excessively long file names
     if len(outfilename)>150: