|
|
#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? |
|
|
|
|
|
#2 |
|
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
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 06:19 PM. |
|
|
|
|
|
#3 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,620
Karma: 28549044
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()
|
|
|
|
|
|
#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 |
|
|
|
|
|
|
#5 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,620
Karma: 28549044
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 05:24 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! |
|
|
|
|
|
#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 11:46 PM |
| Flightcrew says Errors, but Sigil says no Errors… | Barcelona | Sigil | 4 | 02-09-2012 08:13 AM |
| kindle 3 got kneed . fixable ? | kut | Amazon Kindle | 7 | 12-05-2011 05:44 AM |
| Is this e-pub correct? | silviolorusso | ePub | 12 | 06-08-2011 04:52 PM |
| broken screen -fixable? | chebusashka | HanLin eBook | 7 | 02-11-2010 05:28 AM |