08-17-2015, 05:16 PM | #1 |
Junior Member
Posts: 4
Karma: 10
Join Date: Aug 2015
Device: ipad
|
Batch correct fixable errors
Hi,
I have a problem with fixing a lot of epub files. All files I have can be correctly fixed by Ebook Editor via command "Try to correct all fixable errors automatically". But the amount of files is quite big to do this for each file. I can't find corresponding command line tool to do this operation. Can you tell me, how to do this? |
08-17-2015, 05:17 PM | #2 |
Ex-Helpdesk Junkie
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
There is no command-line tool to do this (as of now). ebook-edit is an interactive tool, although you can use macros (function replace, plugins) from within the editor, you cannot open and edit books via a script in an entirely non-interactive way.
Last edited by eschwartz; 08-17-2015 at 05:19 PM. |
Advert | |
|
08-17-2015, 10:07 PM | #3 |
creator of calibre
Posts: 44,006
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you know how to program it should not be hard to wite a script that uses the check book infrastructure to auto-fix correctable errors and run it via calibre-debug
Something as simple as Code:
from calibre.ebooks.oeb.polish.check.main import run_checks, fix_errors from calibre.ebooks.oeb.polish.container import get_container import sys filepath = sys.argv[-1] container = get_container(filepath, tweak_mode=True) errors = run_checks(container) if errors: print ('Found errors, trying to fix them') if fix_errors(container, errors): container.commit() |
08-18-2015, 03:53 AM | #4 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Aug 2015
Device: ipad
|
Quote:
It is very useful information for me! I'm familiar with python, but not familiar with Calibre yet. Can you help me, or give me a link, that can explain, how to run this script in Calibre? Such a quick start to scripting. Thanks again, Georgy |
|
08-18-2015, 04:17 AM | #5 |
creator of calibre
Posts: 44,006
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Copy paste the code into myscript.py, run
calibre-debug myscript.py -- file.epub Last edited by kovidgoyal; 08-18-2015 at 04:24 AM. |
Advert | |
|
08-18-2015, 04:23 AM | #6 |
Junior Member
Posts: 4
Karma: 10
Join Date: Aug 2015
Device: ipad
|
Dear Kovid!
I see, calibre-debug is very fine, simple and pretty documented. So, it seems, I'm able to run the script and it works! I will write, if some problems occurs. Thank you very much! |
08-18-2015, 05:05 AM | #7 |
Junior Member
Posts: 4
Karma: 10
Join Date: Aug 2015
Device: ipad
|
This is script I use for fixing multiple files or all epubs in folder. For sb's sake.
Usage: calibre-debug batchfix.py -- <file or folder 1> <file or folder 2> ... batchfix.py: Code:
from calibre.ebooks.oeb.polish.check.main import run_checks, fix_errors from calibre.ebooks.oeb.polish.container import get_container from os import listdir from os.path import isfile, join, isdir def fix_file(filepath) : try : container = get_container(filepath, tweak_mode=True) errors = run_checks(container) if errors: if fix_errors(container, errors): print ('Fixed: %s' % filepath) container.commit() else : print ('Unable fix: %s' % filepath) else : print ('Correct: %s' % filepath) except : print ('Unhandled error: %s' % filepath) def fix_folder(folder) : epubs = [ f for f in listdir(folder) if isfile(join(folder,f)) and f.lower().endswith('.epub') ] for f in epubs : fix_file(join(folder,f)) import sys for arg in sys.argv[1:] : if isfile(arg) : fix_file(arg) elif isdir(arg) : fix_folder(arg) else : print ('Unknown argument: %s' % arg) |
Tags |
scripting |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
PRS-950 Bought Sony PRS-950--Has issues--Fixable? | gponym | Sony Reader | 3 | 04-17-2015 10:46 PM |
Flightcrew says Errors, but Sigil says no Errors… | Barcelona | Sigil | 4 | 02-09-2012 07:13 AM |
kindle 3 got kneed . fixable ? | kut | Amazon Kindle | 7 | 12-05-2011 04:44 AM |
Is this e-pub correct? | silviolorusso | ePub | 12 | 06-08-2011 03:52 PM |
broken screen -fixable? | chebusashka | HanLin eBook | 7 | 02-11-2010 04:28 AM |