mirror of
https://github.com/apprenticeharper/DeDRM_tools
synced 2024-12-28 09:58:56 +01:00
Merge pull request #490 from wzyboy/backports/infer-filename
Infer filenames consistently
This commit is contained in:
commit
6956117e28
3 changed files with 30 additions and 18 deletions
|
@ -262,12 +262,16 @@ def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids):
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# if we're saving to the same folder as the original, use file name_
|
# Try to infer a reasonable name
|
||||||
# if to a different folder, use book name
|
orig_fn_root = os.path.splitext(os.path.basename(infile))[0]
|
||||||
if os.path.normcase(os.path.normpath(outdir)) == os.path.normcase(os.path.normpath(os.path.dirname(infile))):
|
if (
|
||||||
outfilename = os.path.splitext(os.path.basename(infile))[0]
|
re.match('^B[A-Z0-9]{9}(_EBOK|_EBSP|_sample)?$', orig_fn_root) or
|
||||||
else:
|
re.match('^{0-9A-F-}{36}$', orig_fn_root)
|
||||||
outfilename = cleanup_name(book.getBookTitle())
|
): # 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
|
# avoid excessively long file names
|
||||||
if len(outfilename)>150:
|
if len(outfilename)>150:
|
||||||
|
|
|
@ -262,12 +262,16 @@ def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids):
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# if we're saving to the same folder as the original, use file name_
|
# Try to infer a reasonable name
|
||||||
# if to a different folder, use book name
|
orig_fn_root = os.path.splitext(os.path.basename(infile))[0]
|
||||||
if os.path.normcase(os.path.normpath(outdir)) == os.path.normcase(os.path.normpath(os.path.dirname(infile))):
|
if (
|
||||||
outfilename = os.path.splitext(os.path.basename(infile))[0]
|
re.match('^B[A-Z0-9]{9}(_EBOK|_EBSP|_sample)?$', orig_fn_root) or
|
||||||
else:
|
re.match('^{0-9A-F-}{36}$', orig_fn_root)
|
||||||
outfilename = cleanup_name(book.getBookTitle())
|
): # 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
|
# avoid excessively long file names
|
||||||
if len(outfilename)>150:
|
if len(outfilename)>150:
|
||||||
|
|
|
@ -262,12 +262,16 @@ def decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serials, pids):
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# if we're saving to the same folder as the original, use file name_
|
# Try to infer a reasonable name
|
||||||
# if to a different folder, use book name
|
orig_fn_root = os.path.splitext(os.path.basename(infile))[0]
|
||||||
if os.path.normcase(os.path.normpath(outdir)) == os.path.normcase(os.path.normpath(os.path.dirname(infile))):
|
if (
|
||||||
outfilename = os.path.splitext(os.path.basename(infile))[0]
|
re.match('^B[A-Z0-9]{9}(_EBOK|_EBSP|_sample)?$', orig_fn_root) or
|
||||||
else:
|
re.match('^{0-9A-F-}{36}$', orig_fn_root)
|
||||||
outfilename = cleanup_name(book.getBookTitle())
|
): # 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
|
# avoid excessively long file names
|
||||||
if len(outfilename)>150:
|
if len(outfilename)>150:
|
||||||
|
|
Loading…
Reference in a new issue