06-28-2013, 01:00 AM | #1 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jun 2013
Device: Kindle Paperwhite
|
Batch processing with kindlegen
Hi all,
how can I convert multiple epub files in a batch using kindlegen? ... well yeah the question is as simple as this. |
06-28-2013, 03:42 AM | #2 | |
Grand Sorcerer
Posts: 5,660
Karma: 23456789
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
FOR %%f IN ("*.epub") DO ( kindlegen "%%f" >> conversion.log ) Note that KindleGen will attach the source files to the .mobi files. If space is an issue, you'll need to use KindleStrip to strip off the source files. EDIT: You can also use the undocumented -dont_append_source parameter to prevent kindlegen from attaching the source files to the .mobi file: Code:
FOR %%f IN ("*.epub") DO ( kindlegen -dont_append_source "%%f" >> conversion.log )
Last edited by Doitsu; 04-25-2014 at 07:20 PM. Reason: Added: -dont_append_source information |
|
Advert | |
|
06-29-2013, 02:15 AM | #3 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jun 2013
Device: Kindle Paperwhite
|
Thank you very much!
Can I include a command to tell kindlegen to use the "-c2" format? (Sorry, I'm not really used to .bat-files. :/ ) EDIT: oh and how about batch-processing with kindlestrip? |
06-30-2013, 05:17 AM | #4 |
eBook Enthusiast
Posts: 85,544
Karma: 93383043
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
|
You can include any flags you want on the command line.
|
06-30-2013, 02:05 PM | #5 | |
Grand Sorcerer
Posts: 5,660
Karma: 23456789
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Assuming that you have ActivePython (or another Python 2.7 build) installed and Kindlestrip.py is the same folder as the batch file, you could use the following very simple batch file: Code:
DEL conversion.log FOR %%f IN ("*.epub") DO ( kindlegen "%%f" >> conversion.log IF EXIST "%%~nf.mobi" ( ECHO ******************************* >> conversion.log kindlestrip "%%~nf.mobi" "%%~nf.new" >> conversion.log IF EXIST "%%~nf.new" ( DEL "%%~nf.mobi" REN "%%~nf.new" "%%~nf.mobi" ) ) ) |
|
Advert | |
|
06-30-2013, 04:52 PM | #6 | |
Wizard
Posts: 1,614
Karma: 8399999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
|
|
06-30-2013, 05:29 PM | #7 | |
Grand Sorcerer
Posts: 5,660
Karma: 23456789
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
DEL conversion.log FOR %%f IN ("*.mobi") DO ( ECHO ******************************* >> conversion.log kindlestrip "%%~nf.mobi" "%%~nf.new" >> conversion.log IF EXIST "%%~nf.new" ( DEL "%%~nf.mobi" REN "%%~nf.new" "%%~nf.mobi" ) ELSE ( ECHO "%%~nf.mobi" was NOT stripped! >> conversion.log ) ) BTW, as with the other batch file there's always the possibility that something might go horribly wrong. Always keep backups and don't use it with the original files. |
|
06-30-2013, 06:45 PM | #8 | |
Wizard
Posts: 1,614
Karma: 8399999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
|
|
03-28-2014, 05:31 PM | #9 | |
Lector minore
Posts: 655
Karma: 1738720
Join Date: Jan 2008
Device: Aura One, Paperwhite Signature
|
Quote:
Is there any reason other than time/CPU+disk usage not to use the higher compression? |
|
04-21-2014, 08:37 PM | #10 |
Enthusiast
Posts: 35
Karma: 110336
Join Date: Dec 2011
Location: Los Angeles, CA
Device: Kindle n-T, Nook Color Tablet, Nexus 6
|
how would the code be different in a Linux terminal?
|
04-24-2014, 01:01 PM | #11 |
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)
|
Try this:
Code:
rm conversion.log for file in $@; do echo "*******************************" >> conversion.log if $(kindlestrip "$file" "$file">> conversion.log); then echo "$file was successfully stripped!" >> conversion.log else echo "$file was NOT stripped!" >> conversion.log fi done Last edited by eschwartz; 04-25-2014 at 07:21 PM. |
04-25-2014, 07:16 PM | #12 |
Grand Sorcerer
Posts: 5,660
Karma: 23456789
Join Date: Dec 2010
Device: Kindle PW2
|
@eschwartz:
Unfortunately, your script doesn't work, because kindlestrip.py requires two parameters: the original file and the stripped file. It also doesn't work with file names that contain spaces. This script actually works: Code:
#!/bin/bash # IFS change for file names with spaces in them SAVEIFS=$IFS IFS=$(echo -en "\n\b") # delete old log rm -f conversion.log # process all .mobi files in folder for i in *.mobi; do python kindlestrip.py "$i" ${i%%.*}.new ret=$? if [ $ret -ne 0 ]; then echo "$i" was NOT stripped >> conversion.log else rm $i mv ${i%%.*}.new ${i%%.*}.mobi echo "$i" was stripped >> conversion.log fi done # restore default IFS IFS=$SAVEIFS @Thalia Helikon: You no longer need to use kindlestrip.py, because there's a recently discovered undocumented kindlegen parameter that'll prevent kindlegen from attaching the source files, -dont_append_source. You could use it in a shell script file to convert multiple .epubs with KindleGen: Code:
#!/bin/bash
# IFS change for file names with spaces in them
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# delete old log
rm -f conversion.log
# process all .epub files in folder
for i in *.epub; do
kindlegen -dont_append_source "$i" >> conversion.log
ret=$?
if [ $ret -ne 0 ]; then
echo "$i" was NOT compiled. Error code: $ret >> conversion.log
fi
done
# restore default IFS
IFS=$SAVEIFS
|
04-25-2014, 07:28 PM | #13 | |
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)
|
So I added in the second parameter. Thanks, I didn't realize it required two. According to this post
Quote:
Shouldn't this work just as well? Code:
rm conversion.log #fix for() loop not handling witespace SAVEIFS=$IFS IFS=$(echo -en "\n\b") for file in $@; do echo "*******************************" >> conversion.log if $(kindlestrip "$file" "$file">> conversion.log); then echo "$file was successfully stripped!" >> conversion.log else echo "$file was NOT stripped!" >> conversion.log fi done #restore default IFS IFS=$SAVEIFS EDIT: Just realized what you meant when you said whitespaced files won't work -- because of the for loop. Fixed. Last edited by eschwartz; 04-25-2014 at 07:48 PM. |
|
04-25-2014, 07:44 PM | #14 |
Grand Sorcerer
Posts: 5,660
Karma: 23456789
Join Date: Dec 2010
Device: Kindle PW2
|
You may want to test your scripts before posting them. If you had done so, you'd have found out that they don't work, because had you actually executed kindlestrip.py you'd gotten the following syntax warning:
Code:
kindlestrip.py <infile> <outfile> <strippeddatafile> <strippeddatafile> is optional. EDIT: Apparently the <infile> <outfile> parameters can be identical. Since most command line utilities require different names for input and output files, I assumed that this was the case for this script also. Last edited by Doitsu; 04-25-2014 at 07:57 PM. |
04-25-2014, 08:07 PM | #15 | |
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)
|
Quote:
And why must the input file differ from the output? It looked to me like some artifact of the windows code to check for success by the presence of the .new file. I merely thought to cut out the middleman and do it with the if() test itself. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Scripting ebook-convert for batch parallel processing? | joewiz | Conversion | 9 | 03-15-2013 06:34 AM |
Tag editor with batch processing | semenoof | General Discussions | 0 | 01-17-2013 04:12 AM |
Batch processing of PDB files? | Asterra | iRex | 6 | 12-04-2007 02:10 PM |