View Single Post
Old 01-17-2016, 03:31 AM   #1
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,625
Karma: 3120635
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
To correct endnotes links: a proposal

Hi

To batch correct broken links

Kovid Goyal some months ago enabled the Editor to detect and repair broken links. However, the Editor does not repair yet the broken links due to a wrong chapter number that we may find for example in the file containing the return links.

This script below allows you to do it.
It has been written by pingouinux (Ubuntu). Doitsu helped to debug it (now repaired).
For your information, this script has been successfully tested for one EPUB with 106 xhtml files and 837 -broken- endnotes (two seconds).

Please find enclosed the test epub, the script and these comments.

Before using it, open it to check your version of python. It works with 3 and 3.5. I did not try 2.7
You can customize the variables "chapter" and "xhtml". check that the script is executable.

Testing the script
For this purpose, I join a demo lorem.epub (EPUB2) with seven broken links due to wrong chapter numbers.

1. - Check it. The errors are reported by the Calibre Editor which does not repair them.
2. - Unzip the EPUB. Put it aside.
3. - Open the FILES, then the OEBPS folder.
4. - Put yourself in the path and launch with a terminal (Linux)
Code:
$./pingouin3.py
The script creates a chapter3modif.xhtml file (it uses the highest file number), close to the original chapter3.xhtml
5. - Delete chapter3.xhtml
6. - Rename chapter3modif.xhtml to chapter3.xhtml
7. - Open the EPUB, select chapter3.xhtml and change it (right-click) for the new chapter3.xhtml file in the OEBPS folder. Save.
8. - Check you EPUB: the errors are gone.

Comment

This is a very slow but fool-proof method to use it because the renaming of files with the Calibre editor can be tricky for beginners (it can generate "../chapter" instead of "chapter" for example). Later, this process will of course be simplified, mainly at the steps 5 and 6.

Of course, the ideal would be to make this repair script work directly within the Calibre editor either as a function or otherwise. But for this, some expert help is needed.
Attached Files
File Type: zip pingouinux.zip (174.7 KB, 188 views)
roger64 is offline   Reply With Quote