Merging books
You'll either have a bunch of short books, or multiple books you want to put together. There's basically two methods you may want to do.
1) Extracting just the story portion of the book and adding it to the spine
2) Adding the whole book, then appending it.
If the books each fit neatly in to individual htm files, then grabbing just the single htm may be preferred. I did this when merging Macy Chu's works after OCR when i just didn't see the point of having 4 parts when a collection of all four parts was better. Either way you'll be using an archiver first.
So first step, extract the book(s) in question. Make them in their own directory to keep things separate. Since i use 7zip i will use that. Right click on all of the files, select
7-Zip->Extract to "*\". This will extract all the files as separate folders based on their filename.
Either make a new book, or decide which of these books should be your master/base. I'll choose chapter 1 in this case.
Looking at this example all three books are identical in structure, except they are nicely named Chapter 1, chapter 2 and chapter 3. So i copy the others into chapter 1. If you need to you can rename them to make them, as they may just be start or index, so having it say book2-slaying-the-dragon for said book, then sure that works.
At this point, you can just go into the editor, open as epub-directory, look for errors, find the missing files and append them in order to the spine. Update the Toc, the cover page (if you need to) and you should be done.
Personally, should there be unique cover pages for each part i like to copy those too, and then add the cover to the beginning of the book.
Whole Books
Okay, now that the easy one is out of the way, time for the harder one. Find the base directory and rename it to the ordering of the books you want. So Book 1 becomes 1, Book 2 becomes 2, etc. Then drag them all into the new base book.
Next, delete certain files. You don't need multiple mimes, META-INF directories or container.xml's etc, these are just in the way. Remove any files that are not the story in question, so 'about the author' you only need one of them unless you don't feel like cleaning these out. Don't delete the toc.ncx or content.opf until after you are done, as you'll likely be copying bulk from these files.
Open the content.opf of your base book and of the next book in the series. You'll be copying most of the
<item> tags, and you should probably copy from the spine too. Only difference is you need to rename the id's and the paths appropriately.
While i'm using Notepad++ you can easily do this in notepad, or do this in the editor (just mark the text first).
Find: id="
Replace: id="1-
Find: idref="
Replace: idref="1-
Find: href="
Replace: href="1/
You should get something like this. This updates the Id's so they don't clash, and updates the links to point to the relevant parts. Everything within the 1 folder should reference it's data correctly so that isn't an issue. Now you should be able to copy. Remember to change the 1 to whatever actual directory/book you're using...
Copy the contents in the spine you want to keep...
Next you'll want to open the toc.ncx, you'll be doing a bulk replace before copying as before, though id's and numbering are best left to the editor so we just want to strip them. So regex.
Find: [ ]id="[^<>\n]+>
Replace: >
Find: src="
Replace: src="1/
The xml nav points should be clean now. Copy and paste all NavPoint entries into the base toc.ncx and save.
At this point your work is mostly done, open the editor, look for errors and fix them until the epub is ready for use.
Assuming uneeded files were removed, you WILL have errors in the Toc. Just remove the nu-neccesary entries. Id's and Play order data should repopulate afterwards.
Though you could just leave the files and remove duplicates and excess sections rather than manual deletion.
Though it seems a lot of CSS may get flagged. You can probably ignore it unless you're better versed in CSS.
Double check the spine/order of files, TOC are all right. If that's all good you're probably good to go. Might replace the coverimage if there's one for the whole collection/grouping you're doing.