Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 08-06-2026, 01:03 PM   #1
Siavahda
Addict
Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.
 
Posts: 225
Karma: 9400
Join Date: Aug 2010
Location: Helsinki
Device: Kobo Clara Colour
Re-merge files split by Calibre conversion?

Apologies, because this has must have been asked before, but I couldn't find it mentioned anywhere - probably not using the right search terms.

I've been given an EPUB that's gone through Calibre conversion at some point, and many of the files have been split - the chapter number in one file, body of the text in the next.

Is there any way to mass re-merge these files? I've always done it manually, one pair of split files at a time, which is time-consuming and painful, since I have hand damage. Finally occurred to me to ask if there was another way!

Maybe some instruction I can give during another conversion...?
Siavahda is offline   Reply With Quote
Old 08-06-2026, 01:06 PM   #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: 46,431
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
click edit book, shift click to select all the files you want merged, right click and select merge selected text files.
kovidgoyal is offline   Reply With Quote
Old 08-06-2026, 01:12 PM   #3
Siavahda
Addict
Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.
 
Posts: 225
Karma: 9400
Join Date: Aug 2010
Location: Helsinki
Device: Kobo Clara Colour
Quote:
Originally Posted by kovidgoyal View Post
click edit book, shift click to select all the files you want merged, right click and select merge selected text files.
Each chapter has been split in two. If I merge them ALL together, I'll have dozens of chapters in one file. Instead of each chapter being its own file.

I need something that merges each pair back with its pair, not with all the other split files.

Right now, it looks like this

part1_split_1
part1_split_2
part2_split_1
part2_split_2
part3_split_1
part3_split_2

and so on.

If I merge all those together, I'll just have one file called part1_split_1, when what I should have is part1, part2, part3.

(Sorry for over-explaining, I don't know many of the technical terms so I'm never sure if I'm explaining properly.)
Siavahda is offline   Reply With Quote
Old 08-06-2026, 01:13 PM   #4
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: 46,431
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
merge them all together and then use splitting tool to automatically re split them based on heading tags or whatever other criteria you need.
kovidgoyal is offline   Reply With Quote
Old 08-06-2026, 01:14 PM   #5
Siavahda
Addict
Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.
 
Posts: 225
Karma: 9400
Join Date: Aug 2010
Location: Helsinki
Device: Kobo Clara Colour
Quote:
Originally Posted by kovidgoyal View Post
merge them all together and then use splitting tool to automatically re split them based on heading tags or whatever other criteria you need.
I will try that, thank you!
Siavahda is offline   Reply With Quote
Old 08-06-2026, 01:27 PM   #6
Siavahda
Addict
Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.
 
Posts: 225
Karma: 9400
Join Date: Aug 2010
Location: Helsinki
Device: Kobo Clara Colour
Well, that worked on the files that were initially split, but because the same tags were used elsewhere in the book, now parts that weren't split before, are now split.

Can't overstate how much of a mess this ebook is.
Siavahda is offline   Reply With Quote
Old 08-06-2026, 02:07 PM   #7
Sirtel
Grand Sorcerer
Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.
 
Sirtel's Avatar
 
Posts: 15,542
Karma: 248046501
Join Date: Jan 2014
Location: Estonia
Device: Kobo Sage & Libra 2
Quote:
Originally Posted by Siavahda View Post
Well, that worked on the files that were initially split, but because the same tags were used elsewhere in the book, now parts that weren't split before, are now split.

Can't overstate how much of a mess this ebook is.
I've had plenty of really messy books from 10-15 years ago. And plenty which I had to split or merge manually, as there was no way to do it automatically with correct results. Plus all the other smart formatting decisions, like the author deciding that the best way to end a chapter was to insert a ton of empty paragraphs after the last sentence. And every chapter had a different number of empty paragraphs, so you couldn't even use mass search & replace to delete them.

Oh, happy days.
Sirtel is offline   Reply With Quote
Old 08-06-2026, 02:16 PM   #8
Siavahda
Addict
Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.Siavahda can eat soup with a fork.
 
Posts: 225
Karma: 9400
Join Date: Aug 2010
Location: Helsinki
Device: Kobo Clara Colour
Quote:
Originally Posted by Sirtel View Post
I've had plenty of really messy books from 10-15 years ago. And plenty which I had to split or merge manually, as there was no way to do it automatically with correct results. Plus all the other smart formatting decisions, like the author deciding that the best way to end a chapter was to insert a ton of empty paragraphs after the last sentence. And every chapter had a different number of empty paragraphs, so you couldn't even use mass search & replace to delete them.

Oh, happy days.
You, sir, entirely understand the struggle 😂
Siavahda is offline   Reply With Quote
Old 08-06-2026, 04:16 PM   #9
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
Posts: 14,054
Karma: 83121446
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
I can't help but think you should get in touch with the Author, Publisher or Retailer you obtained the book from and express concerns over the formatting of the material.
PeterT is offline   Reply With Quote
Old 08-06-2026, 04:54 PM   #10
Sirtel
Grand Sorcerer
Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.
 
Sirtel's Avatar
 
Posts: 15,542
Karma: 248046501
Join Date: Jan 2014
Location: Estonia
Device: Kobo Sage & Libra 2
Quote:
Originally Posted by PeterT View Post
I can't help but think you should get in touch with the Author, Publisher or Retailer you obtained the book from and express concerns over the formatting of the material.
Depends. It may not be a recently published book; many self-published books were quite messy and poorly formatted 15 years ago, as their authors didn't really have any idea how to format ebooks properly, and several programs currently used for book creating didn't exist yet. It would have been no use to complain about it then, as they obviously didn't know how to do a better job. It was much simpler and faster to fix the books myself.

And if the book was published a decade or more ago, it would be pretty strange to start complaining about it now.
Sirtel is offline   Reply With Quote
Old 08-06-2026, 05:00 PM   #11
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 84,436
Karma: 153744815
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
I know what the problem is. Whoever did the conversion did not or does not know how to use calibre.
JSWolf is offline   Reply With Quote
Old 08-06-2026, 05:12 PM   #12
Sirtel
Grand Sorcerer
Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.
 
Sirtel's Avatar
 
Posts: 15,542
Karma: 248046501
Join Date: Jan 2014
Location: Estonia
Device: Kobo Sage & Libra 2
Quote:
Originally Posted by JSWolf View Post
I know what the problem is. Whoever did the conversion did not or does not know how to use calibre.
They presumably converted with default settings, which would split the headings in some books.
Sirtel is offline   Reply With Quote
Old 08-06-2026, 05:58 PM   #13
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 84,436
Karma: 153744815
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by Sirtel View Post
They presumably converted with default settings, which would split the headings in some books.
I've done that before way back when. But I've gone back and sorted it properly so that didn't happen.
JSWolf is offline   Reply With Quote
Old Yesterday, 12:08 PM   #14
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,365
Karma: 1589505
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by Siavahda View Post
Each chapter has been split in two. If I merge them ALL together, I'll have dozens of chapters in one file. Instead of each chapter being its own file.

I need something that merges each pair back with its pair, not with all the other split files.

Right now, it looks like this

part1_split_1
part1_split_2
part2_split_1
part2_split_2
part3_split_1
part3_split_2

and so on.

If I merge all those together, I'll just have one file called part1_split_1, when what I should have is part1, part2, part3.

(Sorry for over-explaining, I don't know many of the technical terms so I'm never sure if I'm explaining properly.)
This can be done using the 'Editor Chains' plugin. You have to create a chain first, but then you can use it with a single click in any other book in the future.

This is the necessary module:
Spoiler:
Code:
import re

from qt.core import (QWidget, QVBoxLayout, QGroupBox)

from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES
from calibre.ebooks.oeb.polish.split import merge
from calibre.ebooks.oeb.polish.replace import rename_files
from calibre.gui2.tweak_book import editors

from calibre_plugins.editor_chains.actions.base import EditorAction
from calibre_plugins.editor_chains.scope import scope_names, ScopeWidget, validate_scope, scope_is_headless


def spine_index(container, name):
    idx = 0
    for spine_name, is_linear in container.spine_names:
        idx +=1
        if name == spine_name:
            return idx

class ConfigWidget(QWidget):
    def __init__(self, plugin_action):
        QWidget.__init__(self)
        self.plugin_action = plugin_action
        self._init_controls()

    def _init_controls(self):

        l = self.l = QVBoxLayout()
        self.setLayout(l)

        scope_groupbox = QGroupBox(_('Files to merge'))
        l.addWidget(scope_groupbox)
        scope_l = QVBoxLayout()
        scope_groupbox.setLayout(scope_l)
        self.where_box = ScopeWidget(self, self.plugin_action, orientation='vertical',
                                     headless=self.plugin_action.gui is None,
                                     hide=['selected-text','open','current'])
        scope_l.addWidget(self.where_box)

        l.addStretch(1)
        self.resize(self.sizeHint())

    def load_settings(self, settings):
        if settings:
            self.where_box.where = settings['where']

    def save_settings(self):
        settings = {}
        settings['where'] = self.where_box.where
        return settings

class MergeFiles(EditorAction):

    name = 'Merge Files'
    headless = True

    def run(self, chain, settings, *args, **kwargs):
        names = scope_names(chain, settings['where'])
        print(f'DEBUG: Merging Files\n       names: {names}')
        if len(names) < 2:
            print('Error: You need to select at least 2 files to merge')
            return
        container = chain.current_container
        spine_names = [name for name, is_linear in container.spine_names]
        if names[0] in set(container.manifest_items_of_type(OEB_DOCS)):
            category = 'text'
        elif names[0] in set(container.manifest_items_of_type(OEB_STYLES)):
            category = 'styles'
        else:
            print('Error: Can only merge files of categories: text or styles')
            return
        if category == 'text':
            if not set(names).issubset(set(container.manifest_items_of_type(OEB_DOCS))):
                print('Error: some files are your trying to merge are not of category text')
                return
            if not set(names).issubset(set(spine_names)):
                print('Error: Some files you are trying to merge not in spine')
                return
            names = sorted(names, key=lambda name: spine_index(container, name))
        else:
            if not set(names).issubset(set(container.manifest_items_of_type(OEB_STYLES))):
                print('Error: some files are your trying to merge are not of category styles')
                return
            names = sorted(names)
        master = names[0]
        print(f'DEBUG: Merging Files\n       master: {master}')

        # Create groups with the same prefix before merging
        while names:
            master = names[0]
            group = []
            for name in names[:]:
                master_prefix =  re.search('.*?_split_[^d+]', master)[0]
                if re.search('.*?_split_[^d+]', name)[0] == master_prefix:
                    group.append(name)
                    names.remove(name)
            merge(container, category, group, master)
            new_name = re.sub('_split_.*?\\d+', '', master)
            rename_files(container, {master: new_name})
            #if new_name in editors:
            #    chain.boss.show_editor(new_name)

    def validate(self, settings):
        scope_ok = validate_scope(settings['where'])
        if scope_ok is not True:
            return scope_ok
        return True

    def config_widget(self):
        return ConfigWidget

    def is_headless(self, settings):
        return scope_is_headless(settings['where'])

Instructions to configure the chain:
1) Manage Modules > Create > Choose a name for the module (merge_files) > Clear the contents of the code area > Copy/paste the code above > Ok
2) Add/Modify Chains > Plus sign > Give it a title (Merge splited)
3) Gear icon > Choose an icon (optional) > Plus sign > Double click the 'Action' cell > User Actions > Merge Files
4) Gear icon > Choose 'Filenames' > Include filters > Use this regex:
Code:
.*?_split_
5) Click OK in all windows

Now you have a 'Merge splited' option in the Editor Chain menu. You can also set a keyboard shortcut via: Add/Modify Chains > Keyboard shortcuts.
thiago.eec is offline   Reply With Quote
Reply

Tags
calibre, conversion, merge file, split file


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Calibre merge images files to PDF halfpiint Conversion 2 08-13-2021 11:46 PM
Only split large files (no other conversion) seanos Conversion 6 10-04-2020 09:09 PM
Calibre-merge 2 language ePub files smashingpuffins Editor 4 01-06-2015 06:14 AM
Does Calibre recognize chm merge files? Prion9 Conversion 1 08-06-2013 10:26 PM


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


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