07-12-2013, 09:43 AM | #1 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Merging Libraries with custom columns
I lost my entire library due to stupidity on my part, and I'm trying to rebuild it from old backups and partial recovered deleted copies of the library.
I need to be able to merge libraries where the merge functions like a manual merge - merging all the data from the incoming record of Library 1 into the matching existing record of Library2. A "copy to library" with the automerge turned on can be set to insert incoming formats from Library1 into existing records of Library2, but doesn't seem to have any way to bring with it the accompanying tags or custom column data from Library1. One option is to add the records rom Library1 to Library 2 as new records (without automerge) and then do a manual merge of duplicates, which will merge custom data and tags, but it's a very lengthy process to manually process all the records. (As a sidenote: I did some of the original coding for the merge and automerge Calibre functions a long while ago, but I've been in hospital and away from Calibre for a long time recovering. During that period I lost the entire library and my primary backup. I'm not sure if it's possible to make the library merge work the way individual record merges work within a single library.) Thanks for any advice. |
07-12-2013, 10:13 AM | #2 |
Well trained by Cats
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Welcome back
Remember there is a tweak to copy tags Code:
# Control how tags are applied when copying books to another library |
Advert | |
|
07-12-2013, 11:16 AM | #3 | |||
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Thanks! It's been a long road.
Quote:
Quote:
Quote:
Everything works great if the destination library has no matching record. The new record created has all the source record metadata. The problem arises when a record in the source library title/author matches a record in the destination and the source library record has extra metadata, such as tags or a custom #genre column. If the two libraries have the same formats, my only choice is to create an extra record and manually merge. I wrote the first version of that manual merge function and it does what I want it to do - it merges all the data, but it's time consuming for me to manually merge all the records I need merged. If the two records don't have the same formats, I can use Automerge, but that function only puts the incoming format into the existing record in the destination library. It doesn't bring associated metadata from the source library to the destination record. Basically, I'd like an option in Automerge for Copy to Library to act like the manual merge works within a single library. If the author/title matches during the CTL operation, apply the manual merge process to merge the metadata of the source with the destination. When I first wrote the automerge function (with Kovid's substantial help) it was designed for normal Adding of books, not CTL, and the treatment of metadata with the incoming books wasn't at the forefront of my mind.) Since it's been so long since I did any work on Calibre, I thought perhaps someone else (Chaley?) had already built something like this, or perhaps there is a plugin, or perhaps it's already in the buglist as a requested option. Or perhaps someone knows how to do it using some tricks and could make recommendations. Ideally I'd like to bring in the tags and custom column data (and the comments) from the source library to the destination library record regardless of whether the destination record has all, some or none of the same formats found in the source library record. Last edited by Starson17; 07-12-2013 at 11:24 AM. |
|||
07-12-2013, 11:56 AM | #4 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Long time no see
I suggest just bringing them in as new records and then using the duplicate finder to help with merging. Or if you are sure that the records are identical use duplicate finder to search for dupes across both libraries and then delete the dupes from one library. |
07-12-2013, 12:12 PM | #5 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@Starson17: like theducks, welcome back. I hope the future is rosier than the recent past seems to have been!
Re merging: I haven't touched that part of calibre. I never use it so I can't even describe what it does. I do know that db.set_metadata will update custom columns from a metadata object, but I have no idea if abd when it is called. I can imagine merging working one of three ways: the existing record has the master metadata, the new record has the master metadata, or fields in the new record that are not in the existing record are added. The last one isn't exactly easy to do. You seem to be saying that you want the new record to be the master. I don't see that as an option, but it should be possible to do. You would call set_metadata on the existing record, giving it the mi from the new one, possibly setting force_changes=True |
Advert | |
|
07-12-2013, 01:57 PM | #6 | ||
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
It's nice to be back and find that I'm still remembered the absence wasn't exactly voluntary. You play the cards that life deals you .
Quote:
Quote:
Most of the code I would need is already written - Copy to Library reads the data from Library1/Library2 and Merge handles metadata merging, including custom columns exactly as I need it to be handled. It's just a matter of putting the two together. I was hoping that the Duplicate Finder code might already have implemented something like this - batch merging where you know that the records truly should be merged. I'll check, but I'd appreciate anyone would let me know if there have been any major changes in the way the source code is being accessed and used for development. I still have my old development tools installed. Thanks for the comments. I hope all has been going well for you and Calibre. Things can't have changed too much, as the first thread I saw was another lengthy one of those "Why can't Calibre use my personal directory structure?" threads. |
||
07-12-2013, 02:26 PM | #7 | |||
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Quote:
I don't need to, nor am I interested in tackling number 3 - new field creation. I was thinking that there would be three options for CTL Automerge operations: 1) destination is master (don't change fields in the destination, but add data from the source or fill in blank fields when a format from the source is added to a record in the destination) 2) source is master (change fields in the destination to match source data, and add data to supplement or fill in blank field data when a format from the source is added to a record in the destination), and 3) function as it currently functions - make no change to metadata in the destination record, just add the new format into the existing record according to the Add settings (overwrite or skip) New record creation rules would remain unchanged. I suppose this could be useful for the Find Duplicates code as well. There are times I want to just merge them all, and not have to go through all the found dupe groups. Quote:
It's nice to hear from you (BTW, I'm not really proposing that I write this for others. As usual, my skills are too poor to do anything other than hack together something to solve my immediate personal problem of reassembling multiple recovered databases.) Last edited by Starson17; 07-12-2013 at 02:33 PM. |
|||
07-12-2013, 09:09 PM | #8 |
Wizard
Posts: 4,812
Karma: 26912940
Join Date: Apr 2010
Device: sony PRS-T1 and T3, Kobo Mini and Aura HD, Tablet
|
Your name was in my brain earlier today when was writing a post saying how many people helped me personally with calibre. Once that I remember clearly was with importing records way back in 2010
One thing that may help. The find duplicates plugin will find duplicates across libraries. You can create a temp library using the copy structure option and import x books, use the plugin with the duplicate library option, put not before marked duplicates in the search bar and you will have a list of all of the books not in your main library. What I do at this point is use the copy to library function to copy (and delete after copy) to the main library. Then I copy the duplicates to another temp duplicates library in case I want to compare later. Then it is on to the next batch of x books. It is actually pretty fast and efficient. Helen |
07-12-2013, 10:20 PM | #9 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
calibre's source control system has moved from bzr to git, see the sticky post in the development section. Other than that, the code layout is mostly the same. You have two ways you can approach this:
1) Make copy to library use merging code optionally. As I recall, it already does this in some circumstances, search for auto_merged_ids in actions/copy_to_library.py for details. You might need to improve it a bit to do exactly what you need. 2) Create a simple plugin that automates merging duplicates found by Find Duplicates, or extend Find Duplicates to do that. |
07-13-2013, 03:00 AM | #10 | |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I found that tool SmartGit/HG helped me a lot with this transition. It is free for non-commercial use. It presents the log in a very readable threaded form, has full-file presentations of changes, presents uncommitted changes clearly, makes reversions easy, and lets you easily select what "upstream repository" to use for a given operation. My secret for happiness was discovering that if I "pull" from Kovid's master, "merge" the pulled records to my local repo, and then "sync" with my own upstream repo, then that repo is in good shape for submitting the necessary "pull request". You do the "pull request" by going to github, signing in, clicking on your upstream repo, clicking "pull requests" on the right, then clicking the green "new pull request" button. |
|
07-15-2013, 08:58 AM | #11 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Last edited by Starson17; 07-15-2013 at 09:04 AM. |
|
07-15-2013, 09:04 AM | #12 | ||
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Quote:
|
||
07-15-2013, 09:06 AM | #13 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
|
07-15-2013, 05:33 PM | #14 |
null operator (he/him)
Posts: 20,575
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
I may be misunderstanding what you want to do but (LibraryA is assumed to have the good formats, LibraryB is assumed to have the good metadata) ...
Could you not just move the opf file from the book in LibraryB to the book in LibraryA and rebuild the LibraryA database ? Or if the LibraryA is big, move the books in question From LibraryA to LibraryC, move the opfs from LibraryB book folders to LibraryC book folders, rebuild LibraryC database, move books from LibraryC to LibraryA, remove (now empty) LibraryC Or copy the format files from LibraryB to somewhere or other in case you want them some time, remove the format files from LibraryB, add the format files from LibraryA to LibraryB, remove the books from LibraryA, move the books from LibraryB to LibraryA. BR |
07-15-2013, 08:23 PM | #15 |
null operator (he/him)
Posts: 20,575
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
I now remember that I used the last one a while back, I had to adjust the custom columns so that the two library's matched.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom Columns and Virtual Libraries | Soxendom | Library Management | 3 | 05-25-2013 10:43 AM |
Different Libraries, Custom Columns and send to device | Soxendom | Calibre | 1 | 07-30-2011 07:43 PM |
Merging libraries | Codex | Library Management | 5 | 04-11-2011 01:25 PM |
merging libraries | glnagrom | Library Management | 1 | 02-21-2011 12:17 AM |
Query re: Custom columns & multiple libraries | jackie_w | Calibre | 4 | 10-03-2010 02:16 AM |