metadata upload to calibre

Tell us about your wildest feature dreams. Or just harmless suggestions for improvement.
Post Reply
demiadirac
Addicted to Bruji
Addicted to Bruji
Posts: 40
Joined: Sat Jun 14, 2014 5:32 am

metadata upload to calibre

Post by demiadirac »

I know how to pull metadata from calibre into BookPedia, but would it be possible to do the reverse, i.e. upload metadata from BookPedia into calibre somehow?
If BookPedia is supposed to be my authoritative source of data, this would be required to keep things consistent.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: metadata upload to calibre

Post by Conor »

Calibre can read the BibTeX export template. Use the "File (menu) -> Export (menu command) -> Text (tab) -> Template (radio button) -> BibTeX (pop-up)". With that file you should be able to import the info back into Calibre, not sure if Calibre is able to merge information, I think it can based on the ISBNs for the books.
demiadirac
Addicted to Bruji
Addicted to Bruji
Posts: 40
Joined: Sat Jun 14, 2014 5:32 am

Re: metadata upload to calibre

Post by demiadirac »

Hi Conor, thanks for replying. I'm not entirely with you, though. Calibre can write bibtex, but it can't read bibtex, or at least I couldn't find out how. Besides, bibtex is not very extensive: It does not contain covers, it contains series but not numbers (or rather, they are not exported by BookPedia).
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: metadata upload to calibre

Post by Conor »

The BibTeX export is set for the standard fields that BibTeX handles, but can be extended to include more fields. But if Calibre can't handle the import then there is no point in extending it, as BibTeX also does not handle images and you want those as well. I just mentioned BibTex as I knew that it's one of the native files that Calibre exports and thought it would be able to handle an import as well.

Googling around for a solution I found an excellent resource, just happens to be exactly back on our own forum. :D

I was not aware that Calibre had a command line tool, although the post above is for importing from Calibre, one can reverse it to take all the fields and info you want back to Calibre.

1. The location of the command line interface for Calibre, is now inside the Calibre app and there is no install command that I can find as mentioned in that post. You can run the tool by referencing the location of your Calibre install, the script below assumes your Calibre is in the Applications folder.

2. Create a text file as an export template for Bookpedia. The contents of the template would be along the lines of the text below (change /me/ to be the username of your home folder, otherwise it won't be able to find the covers):

Code: Select all

#!/bin/bash
<!--BeginRepeat-->/Applications/calibre.app/Contents/console.app/Contents/MacOS/calibredb set_metadata <!--IFauthor-f authors:"[key:author]"ENDauthor--> <!--IFcomments-f comments:"[key:comments]"ENDcomments--> -f cover:"/Users/me/Library/Application Support/Bookpedia/Covers/[key:uid].jpg" <!--IFseries-f series:"[key:series]"ENDseries--> <!--IFvolume-f series_index:[key:volume]ENDvolume--> $(/Applications/calibre.app/Contents/console.app/Contents/MacOS/calibredb search isbn:[key:isbn] -l 1)
<!--EndRepeat-->
3. Place the file in your data folder at ~/Library/Application Support/Bookpedia/Templates. You might have to create the Templates folder, to open your Library folder use the "Go" menu in the Finder while holding down the option key and select "Library". After installing the template you will then find this export option at the same spot as the BibTex export was found. When exporting with this template, you are in essence creating a list of imports via the command line tool for Calibre.

4. Breaking down the above command down into parts to explain:
A. It uses the search command to look up a book via ISBN in calibre. This is the last part of the command. You would have to have ISBN for all the books you want to send data back for. The search could be update to anything that calibre understands in it's power search, such as author:"An Author" title:"title" if you don't have ISBNs for all books or have other identifiers.

B. This search returns an internal ID that calibre uses, that is then used in the second command to get a specific book and add metadata via the set_metadata command.

B. The fields that Calibre understands for metadata are:
  • author_sort
    authors
    comments
    cover
    identifiers
    languages
    pubdate
    publisher
    rating
    series
    series_index
    size
    sort
    tags
    timestamp
    title
C. The <!--IFauthor ENDauthor--> are statements for the export in Bookpedia to only add the info inside if the field is set. Not actually needed as the command line import will ignore empty strings. But this way you don't accidentally overwrite any data in Calibre that is not also in Bookpedia.

D. -f authors:"An Author" is how you import data into Calibre, the [key:author] is the export key for Bookpedia.

E. Duplicate those middle sections and add as many extra fields as you want. You can add custom fields with hashtag: #customField:value

There is also an add command that works pretty much in the same way, if you are not merging information into existing books, but importing from Bookpedia.

As reference the commands you can give calibredb are listed here in their help file.

Once you have exported using that template you will get a long list of commands that you can copy paste into the program named Terminal in your Applications/Utilities folder, if just a few books. If many books I would recommend running the exported file as a script to avoid issues with the size of the clipboard in Terminal. To do so in Terminal do:

Code: Select all

bash /Users/me/Desktop/exported.txt
You can write bash and a space in Terminal and then drag and drop the file and it will fill out the path for you, if exporting to a different location than Desktop. If you want to review the import you can save all the messages to a file by adding > results.txt to the end of the command. Then results.txt will have all the info that was updated. Could be useful to then search that file for "You must specify a record id as the first argument", this is the error you get when an ISBN is not found in Calibre, it would let you know what book got ignored as it was not found in Calibre.

If you want something much more customized you would then need to build an actual script that can parse the information from any of the open sources of Bookpedia data including a tab delimited export. Here is a python script that someone built for the same purpose coming from Delicious Library file.
demiadirac
Addicted to Bruji
Addicted to Bruji
Posts: 40
Joined: Sat Jun 14, 2014 5:32 am

Re: metadata upload to calibre

Post by demiadirac »

Hi Conor,
now that works! Thanks a lot for replying so elaborately!
demiadirac
Addicted to Bruji
Addicted to Bruji
Posts: 40
Joined: Sat Jun 14, 2014 5:32 am

Re: metadata upload to calibre

Post by demiadirac »

I added a rating to the app store telling how pleased I am.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: metadata upload to calibre

Post by Conor »

Glad we could get Bookpedia and Calibre talking to each other and let you manage all that info.

Thank you so much for leaving us a review – much appreciated.
Post Reply