Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 08-10-2014, 06:46 AM   #1
Tobisas
Junior Member
Tobisas began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Aug 2014
Device: Sony Reader PRS-T2
Lightbulb Simple utils for comic to EPUB conversion to perserve order

Hi all,

Like some others I had some problems when I wanted to convert a CBZ/CBR comic to EPUB in Calibre, because the conversion puts filename order above directory order. For example a CBZ with the following images:
Code:
Comic Chapter 1/1.jpg
Comic Chapter 1/2.jpg
Comic Chapter 1/3.jpg
...
Comic Chapter 2/1.jpg
Comic Chapter 2/2.jpg
Comic Chapter 2/3.jpg
turns into an EPUB with the unreadable order:
Code:
Comic Chapter 1/1.jpg
Comic Chapter 2/1.jpg
Comic Chapter 1/2.jpg
Comic Chapter 2/2.jpg
Comic Chapter 1/3.jpg
Comic Chapter 2/3.jpg
I saw that user FangornUK created a utility to properly convert comics to LRF with his comiclrf util, but personally I wanted to manually manage my CBZ's/CBR's/EPUBs in Calibre, so I'd rather just rename the files/directories to create workable CBZs/CBRs.

Manually renaming everything is kind of a drag though, so I quickly wrote two utilities to help me rename files and create CBZ's out of these. Since I might not be the only one who wanted this, I thought it would be nice to share these with the community.

Keep in mind that I just quickly put these together, so don't expect a pretty interface and all. I created it in Java since that'll work on most different operating systems and because that's what I'm good at, so it'll require you to install the Java Runtime Environment (JRE) if you haven't already (just try to run it and you'll automatically see if you have the proper Java installed).
I included the runnable jars as attachments, which can be run on any OS. For Windows users such as myself I also created executables of these jars, for ease of use.


AppDir.jar / appendir.exe
This utility will go through all the subdirectories and prefix the filenames with a number for the directory, so the filenames will remain in the same order when flattened. It'll use human readable parsing to ensure that for example directory "Chapter 9" comes before "Chapter 10" (which wouldn't be the case in alphabetical ordering).

So for example, if you run the appendir.exe in the following directory with comic chapters
Code:
...
Comic Chapter 9/1.jpg
Comic Chapter 9/2.jpg
Comic Chapter 9/3.jpg
Comic Chapter 9.5/1.jpg
Comic Chapter 9.5/2.jpg
Comic Chapter 9.5/3.jpg
Comic Chapter 10/1.jpg
Comic Chapter 10/2.jpg
Comic Chapter 10/3.jpg
It will rename the files to:
Code:
...
Comic Chapter 9/009_1.jpg
Comic Chapter 9/009_2.jpg
Comic Chapter 9/009_3.jpg
Comic Chapter 9.5/010_1.jpg
Comic Chapter 9.5/010_2.jpg
Comic Chapter 9.5/010_3.jpg
Comic Chapter 10/011_1.jpg
Comic Chapter 10/011_2.jpg
Comic Chapter 10/011_3.jpg
As you can see in the example, the filename prefixes might not match the actual chapter, but that doesn't matter because the total order will be perserved when turned into an EPUB and that's all we care about.

Options
You can run the utility as is, but I added two optional commandline parameters for more control if required:
  1. Start directory - The directory to start processing. If not used, it will start in the directory where you run the utility.
  2. Depth - How many directories deep it will go to rename files. By default the maximum is 4 folders, so if you run it in "C:\Comics" it will go as deep as "C:\Comics\Fantasy\Timebird\Volume 1\Chapter 1\".

Example use: Put appendir.exe in the comic folder you need to rename and doubleclick.
Example use with parameters: Open command prompt, go to location of appendir.exe and run: appendir.exe "C:\Comics" 5
Example use with jar: Open command prompt or terminal, go to location of AppDir.jar and run: java -jar AppDir.jar

Dir2CBZ.jar / dir2cbz.exe
After renaming all the files in comic volumes I still needed to create CBZ's or CBR's out of them. This is rather trivial to do by creating a zip file of every volume and renaming it to *.cbz, but I couldn't quickly find a satisfactory method of doing this automatically for all folders, so again I made a simple utility to do this for me.
So this just automatically creates CBZ files for all folders in the directory it's run in, which then can be directly imported into Calibre.

Options
You can run the utility as is, but I added one optional commandline parameters:
  1. Start directory - The directory to start processing. If not used, it will start in the directory where you run the utility.

Example use: Put dir2cbz.exe in the comic folder containing all the folders you want to create CBZs out of and doubleclick.
Example use with parameters: Open command prompt, go to location of dir2cbz.exe and run: dir2cbz.exe "C:\Comics"
Example use with jar: Open command prompt or terminal, go to location of Dir2CBZ.jar and run: java -jar Dir2CBZ.jar


Any feedback / suggestions / requests are welcome, though again keep in mind that these are just simple utilities I quickly created. Feel free to use them as you like, hopefully I helped someone else with this to manage their comic library.

Enjoy!
Attached Files
File Type: zip appendir.zip (17.0 KB, 197 views)
File Type: zip dir2cbz.zip (178.8 KB, 209 views)
File Type: jar AppDir.jar (7.6 KB, 175 views)
File Type: jar Dir2CBZ.jar (185.1 KB, 182 views)
Tobisas is offline   Reply With Quote
Old 08-11-2014, 12:05 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,844
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
https://github.com/kovidgoyal/calibr...dede500637203b
kovidgoyal is offline   Reply With Quote
Old 08-14-2014, 01:59 PM   #3
Tobisas
Junior Member
Tobisas began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Aug 2014
Device: Sony Reader PRS-T2
Thanks kovidgoyal, that'll make it a lot easier!
Tobisas is offline   Reply With Quote
Reply

Tags
cbz, comic, epub, order, ordered


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
comic conversion killa Conversion 1 02-28-2011 09:31 AM
Having a very hard time converting a comic and keeping it in order! branchedout Reading and Management 2 08-18-2010 11:13 AM
Simple Esperanto ePub conversion script? amuzulo ePub 10 03-06-2010 02:54 PM
Calibre comic conversion yields poor results when target is epub; looks fine on LRF acidzebra Calibre 2 08-17-2009 10:54 AM
Comic Conversion grzy7316 Calibre 2 04-08-2009 06:55 PM


All times are GMT -4. The time now is 09:07 PM.


MobileRead.com is a privately owned, operated and funded community.