Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 09-30-2023, 12:19 PM   #1
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 111
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
calibredb 'merge'

Is there a way to have calibredb use the 'merge' action I use via the GUI? This not the same as adding a format.

I am cleaning up a few libraries I have integrated. I have a reliable identifier I can use to identify duplicates (CRC,extension,filesize) but other associated information such tags and tag-like fields.. These are bitwise-identical files, but I want to aggregate the supplementary information.

What I'd like to do is write a script that will examine all sets of titles with the same unique key, and where the titles and authors match, merge them into a single entry. (I'll want to examine where these things differ to see which ones I prefer, so I'll still need to handle these ones manually.)

I could make my script a little more sophisticated, of course, and handle the aggregation myself via set_metadata... but if it's already built-in, I'd rather do that. It's less work for me, and much more importantly, less prone to error.

Last edited by kjdavies; 09-30-2023 at 12:27 PM. Reason: expand 'handle aggregation' description
kjdavies is offline   Reply With Quote
Old 09-30-2023, 12:50 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,188
Karma: 57532382
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Does calibredb --automerge, -m work?

If books with similar titles and authors are found, merge the incoming formats (files) automatically into existing book records. A value of "ignore" means duplicate formats are discarded. A value of "overwrite" means duplicate formats in the library are overwritten with the newly added files. A value of "new_record" means duplicate formats are placed into a new book record.

the number in the containing Folder is the books {ID} if that helps
theducks is offline   Reply With Quote
Advert
Old 09-30-2023, 01:00 PM   #3
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 111
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by theducks View Post
Does calibredb --automerge, -m work?

If books with similar titles and authors are found, merge the incoming formats (files) automatically into existing book records. A value of "ignore" means duplicate formats are discarded. A value of "overwrite" means duplicate formats in the library are overwritten with the newly added files. A value of "new_record" means duplicate formats are placed into a new book record.

the number in the containing Folder is the books {ID} if that helps
Not what I'm looking for. The books are already in the library, I'm confident they are the same book (bitwise identical), but I want to merge the the metadata.

I'm thinking of a command something like

Code:
calibredb merge id1 id2 id3
If I've got a '#notes' custom column, and the three titles with IDs id1, id2, id3 have #notes values of 'Note 1', 'Note 2', and 'Note 3', when I merge via the GUI I get a #notes value of 'Notes1\n\nNotes2\n\nNotes 3'. Taglike fields are similarly aggregated and the union stored in the result.
kjdavies is offline   Reply With Quote
Old 09-30-2023, 03:48 PM   #4
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by kjdavies View Post
Is there a way to have calibredb use the 'merge' action I use via the GUI? This not the same as adding a format.

I am cleaning up a few libraries I have integrated. I have a reliable identifier I can use to identify duplicates (CRC,extension,filesize) but other associated information such tags and tag-like fields.. These are bitwise-identical files, but I want to aggregate the supplementary information.

What I'd like to do is write a script that will examine all sets of titles with the same unique key, and where the titles and authors match, merge them into a single entry. (I'll want to examine where these things differ to see which ones I prefer, so I'll still need to handle these ones manually.)

I could make my script a little more sophisticated, of course, and handle the aggregation myself via set_metadata... but if it's already built-in, I'd rather do that. It's less work for me, and much more importantly, less prone to error.
A combination of Find Duplicates and Action Chains plugin can help you achieve what you want:
  1. Use the Find Duplicates plugin to group the identical books.
  2. Using Action Chains plugin, you can use this custom module to auto-merge the book records of the same duplicate group. The will be merged into the first book of each group.

Notes:
  • To add the custom module, go to Action Chains > Manage Module > add
  • This is a destructive action after which you will not be able to restore your merged records, make sure you backup you library before you proceed. You are ultimately responsible for any damage that might happen.
capink is offline   Reply With Quote
Old 09-30-2023, 03:54 PM   #5
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 111
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by capink View Post
A combination of Find Duplicates and Action Chains plugin can help you achieve what you want:
  1. Use the Find Duplicates plugin to group the identical books.
  2. Using Action Chains plugin, you can use this custom module to auto-merge the book records of the same duplicate group. The will be merged into the first book of each group.

Notes:
  • To add the custom module, go to Action Chains > Manage Module > add
  • This is a destructive action after which you will not be able to restore your merged records, make sure you backup you library before you proceed. You are ultimately responsible for any damage that might happen.
This sounds pretty close to what I want, so thank you for that. I've been meaning to learn action chains.

Can it be smart enough to also require that the titles match? Within a group I don't always have the titles match and would like to be able to pick which ones I want.

(Yes, I realize I might be more or less unique in my need here...)
kjdavies is offline   Reply With Quote
Advert
Old 09-30-2023, 04:00 PM   #6
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by kjdavies View Post
This sounds pretty close to what I want, so thank you for that. I've been meaning to learn action chains.

Can it be smart enough to also require that the titles match? Within a group I don't always have the titles match and would like to be able to pick which ones I want.

(Yes, I realize I might be more or less unique in my need here...)
The solution to this is to choose the files you do not want to be merged, apply a tag to them, let say "exempt_unique", exit Find Duplicates view, apply a virtual library with the search
Code:
not tag:"=exempt_unique"
and then re-run Find Duplicates while in the virtual library, this way none of these books would show in the duplicates results.

Last edited by capink; 09-30-2023 at 04:08 PM.
capink is offline   Reply With Quote
Old 09-30-2023, 04:03 PM   #7
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 111
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by capink View Post
The solution to this is to choose the files you do not want to be merged, apply a tag to them, let say "exempt_unique", exit Find Duplicates view, apply a virtual library with the search tag:"=exempt_unique", and then re-run Find Duplicates while in the virtual library, this way none of these books would show in the duplicates results.
It comes to me that it might not be an important detail. This is just deduplicating the bitwise-identical files. I still have to review the results and bring them up to my standard. Being able to 'pick' the preferred title perhaps doesn't gain me much in that scenario.
kjdavies is offline   Reply With Quote
Old 09-30-2023, 04:07 PM   #8
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by kjdavies View Post
It comes to me that it might not be an important detail. This is just deduplicating the bitwise-identical files. I still have to review the results and bring them up to my standard. Being able to 'pick' the preferred title perhaps doesn't gain me much in that scenario.
OK, Just in case you decide to use what I posted in my previous post, the correct search would be:

Code:
not tag:"=exempt_unique"
capink is offline   Reply With Quote
Old 09-30-2023, 10:38 PM   #9
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: 44,205
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No there's no CLI interface for merging metadata.
kovidgoyal is offline   Reply With Quote
Old 10-01-2023, 12:19 PM   #10
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 111
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by kovidgoyal View Post
No there's no CLI interface for merging metadata.
Thanks Kovid, I was pretty sure. The documentation didn't mention it.

Is it worth submitting an enhancement request? I'm thinking the semantics would be something like

Code:
calibredb merge [options] id1 id2 [... idN]
Options might include
  • --library-path, of course
  • -h,--help, obviously
  • --version
  • setting/adding tag(s) -- user-specified would be nicest, but even a hardcoded 'calibredb-merged-this' would be great
  • setting other metadata (tag could be enough, though)
  • 'safe' (will refuse if it tries to merge two titles with the same format -- my use case specifically is to merge titles with the same formats, I'm deduping, but I can see value to this)
kjdavies is offline   Reply With Quote
Old 10-01-2023, 12:52 PM   #11
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: 44,205
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Not unless you are willing to implement it as well
kovidgoyal is offline   Reply With Quote
Old 10-01-2023, 01:36 PM   #12
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 111
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by kovidgoyal View Post
Not unless you are willing to implement it as well
If I had the knowledge. Python is probably one of my weakest languages.

I mean, LISP is lower (I've done some work with Schema via DSSSL... 20+ years ago) and I don't even admit to having seen COBOL, but of languages in common use today, Python is probably one of my weakest.
kjdavies is offline   Reply With Quote
Old 10-01-2023, 04:33 PM   #13
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,867
Karma: 7036359
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
@kovid: I looked at the merge_metadata() method in the edit_metadata action. It is very self contained. I copied it to a python template and ran it with almost no changes. Metadata from my test books was merged. Of course it doesn't do anything with formats and doesn't delete any books.

If I move it from the GUI to ebook.metadata.book then it could be used in scripts executed with 'calibre-debug -e' as well as be used by some eventual command line utility (that I am not volunteering to write). A stub must remain in edit_metadata to pass the db to the moved method.

I could do the same thing with merge_data_files(), but I don't think it is necessary. The only thing is does is call the db api merge_extra_files() method.

Is this OK with you?
chaley is offline   Reply With Quote
Old 10-01-2023, 07:38 PM   #14
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,092
Karma: 62580135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by kjdavies View Post
but of languages in common use today, Python is probably one of my weakest.
Just for you:

Spoiler:
Click image for larger version

Name:	IntroductoryPythonProgrammingCourse.png
Views:	56
Size:	307.9 KB
ID:	204051
ownedbycats is offline   Reply With Quote
Old 10-01-2023, 10:32 PM   #15
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: 44,205
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@charles: Yes that's fine.
kovidgoyal is offline   Reply With Quote
Reply

Tags
calibredb, merge


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installer for calibredb only? Freakeao Calibre 3 12-09-2020 09:19 PM
Merge books, how to select FIRST book or MERGE metadata? rboatright Library Management 11 08-20-2016 11:01 AM
commandline calibredb Divingduck Calibre 2 07-31-2014 05:18 AM
calibredb iomari Calibre 6 10-10-2011 08:35 AM
Merge feature request (different merge) Tarran Calibre 1 05-24-2010 10:57 AM


All times are GMT -4. The time now is 12:41 AM.


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