View Single Post
Old 10-15-2024, 06:26 PM   #697
haertig
Wizard
haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.
 
Posts: 1,899
Karma: 31522252
Join Date: Sep 2017
Device: PW3, Fire HD8 Gen7, Moto G7, Sansa Clip v2, Ruizu X26
Quote:
Originally Posted by DNSB View Post
Perhaps replacing the check for EBOK in check_mobi.py with a check for PDOC?
Since the length of the text string "EBOK" is the same length as the text string "PDOC", replacement could be as simple as this (on a Linux computer):

Code:
sed -e 's/EBOK/PDOC/' -i.backup 'filename.azw3'
The "sed" command on Linux works fine on binary files for things like this. But "sed" on Unix, Windows or some other OS may not handle binary files appropriately. A wise proverb: "An assumption is the first step towards a screw-up". So don't assume this will work on other OS'es, even if they have the "sed" command. You have been warned!

I do not know the structure of an AZW3 file, and it may be perfectly find to alter the length of text like this when doing a replacement. But I can't say that for sure, since I know nothing about AZW3 files and any checksums (or whatever) they may or may not contain.

If you are more daring and don't want to create a backup copy of the original file before editing, you can replace the "-i.backup" part of the command with simply "-i". This would be fine if you keep current and solid backups of your Calibre library.

You could write a simple "for loop" script around the "sed" command to find and cycle through all the azw3 files you want to modify.

You may want to add some bulletproofness to the script and make sure that "EBOK" only appears once in the file before you go modifying it. If it appears more than once, you only want to do the replacement on the appearance in the metadata part of the file (which is probably the first occurrence, but you'd have to verify that).

The way to check it the text string appears multiple times is:

Code:
strings 'filename.azw3' | grep EBOK | wc -l
Note that if you use "-i.backup" it will create a backup copy of every file before it gets modified. So you will need twice the amount of storage space to allow two copies of each file (at least until you remove the *.backup copies after you've determined all is well and good).
haertig is offline   Reply With Quote