Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for calibre? #47

Open
egh opened this issue Oct 30, 2012 · 10 comments
Open

Support for calibre? #47

egh opened this issue Oct 30, 2012 · 10 comments

Comments

@egh
Copy link

egh commented Oct 30, 2012

Hi,

I use calibre to manage ebooks for my ereader. It would be nice if zotfile, after (or instead of) pushing a file to a particular directory for "Send to tablet", would call the calibredb program, e.g.

calibredb add --author "Jane Doe" --title "Foo" foo.pdf

I've had a quick look at the source and it looks like this could be added to the end of the sendAttachmentToTablet function. I can look into it, but it might require abstracting sosendAttachmentToTabletme code (e.g. calling an executable).

My ereader does not support annotating texts so that is not an issue for me. I don't know if it is an issue for others.

@jlegewie
Copy link
Owner

Feel free to play around with it but I won't have time to get into it right now. If you implement something, you should add an option to the zotfile.js file in the defaults/pref folder.

@egh
Copy link
Author

egh commented Nov 1, 2012

Thanks, I'll see what I can do!

@fBedecarrats
Copy link

Hello, this idea is great and I believe that creating a bridge between Zotero and Calibre would be useful to many users.
I think the interest would be not only to send to tablet using Calibre, but also to join as metadata all the reference information stored in zotero. Would you have a clue on how to do this? I'm learning JS and I would be happy to work on it. I would just need some advice on the way to do it.

@jlegewie
Copy link
Owner

Hi, can you describe what exactly you are thinking about? Is egh's description in the first post what you want to do or is there something else? Does it make sense to add this to sendAttachmentToTablet or as a separate function and menu item? I can point you in the right direction once I have more details.

@fBedecarrats
Copy link

Hello, thanks for your quick reaction. The idea would be not only to send the file to calibre (the command 'add'), but also to attach the metadata created in Zotero, using the command: calibredb set_metadata [options] id /path/to/metadata.opf (see description of Calibre commands : http://manual.calibre-ebook.com/cli/calibredb.html)

Just to clarify (I hope), the result would be Calibre not only store to the files in ...\CalibreLibrary\Author\Title\doc.pdf (and the equivalent doc.epub, doc.mobi, doc.azw, the wondeful thing about calibre being its ability to translate formats and synchronize them with reading devices). It would also create a ...\CalibreLibrary\Author\Title\metadata.opf with all the ref information corresponding to the document

So this would require (I think) Zotfile to call an Zotero export function to have a file with metadata to be adapted to Calibre format.

So for instance, the following reference (BiBtex):
@book{strange_retreat_1998,
address = {Cambridge},
title = {The Retreat of the State. The Diffusion of Power in the World Economy},
publisher = {Cambridge University Press},
author = {Strange, Susan},
year = {1998},
note = {Generic},
file = {Strange - 1998 - The Retreat of the State. The Diffusion of Power i.pdf:D:\Dropbox\Bibli-Zotero\Strange - 1998 - The Retreat of the State. The Diffusion of Power i.pdf:application/pdf;Strange - 1998 - The Retreat of the State2.pdf:D:\Dropbox\Bibli-Zotero\Strange - 1998 - The Retreat of the State2.pdf:application/pdf}
}

Would generate a metadata.odf with the following information:

2/dc:identifier 5a7e096c-2cdc-4051-b220-265935becce0/dc:identifier dc:titleThe Retreat of the State. The Diffusion of Power in the World Economy/dc:title Susan Strange/dc:creator dc:publisherCambridge University Press/dc:publisher

So, from what I understand, this would require:

  • to add a checkbox in Zotfile options to select if you want to make such Calibre export
  • if checked, this would call 'Calibre functions' instead of 'Tablet functions'
  • The Calibre functions would call 'calibredb add'
  • The Calibre functions would also call a Zotero export functions (eg. in BibTex), translate it to correspond to Calibre format (I have done something similar in perl, so I hope I will be able to do it in JS) and send ot through 'calibredb set_metadata'

What I would need from you is to tell me:

  1. if this makes any sense
  2. if you think it is relevant to add this function to zotfile (otherwise I will find something else to play with)
  3. if you can give me some hints on how I should proceed

And thanks for this great addon!

@fBedecarrats
Copy link

Ups, I replace > and < by #
#?xml version='1.0' encoding='utf-8'?#
#package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuid_id"#
#metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"#
#dc:identifier opf:scheme="calibre" id="calibre_id"#2#/dc:identifier#
#dc:identifier opf:scheme="uuid" id="uuid_id"#5a7e096c-2cdc-4051-b220-265935becce0#/dc:identifier#
#dc:title#The Retreat of the State. The Diffusion of Power in the World Economy#/dc:title#
#dc:creator opf:file-as="Strange, Susan" opf:role="aut"#Susan Strange#/dc:creator#
#dc:contributor opf:file-as="calibre" opf:role="bkp"#calibre (0.9.14) [http://calibre-ebook.com]#/dc:contributor#
#dc:date#0101-01-01T00:00:00+00:00#/dc:date#
#dc:publisher#Cambridge University Press#/dc:publisher#
#meta content="The Retreat of the State. The Diffusion of Power in the World Economy" name="calibre:title_sort"/#
#meta name="calibre:user_metadata:#year" content="1998,"/#
#meta name="calibre:user_metadata:#adress" content="Cambridge"/#
#/metadata#
#/package#

@jlegewie
Copy link
Owner

Hey

  1. Yes, I think it does but see 2.
  2. I can't really tell you because I have never used Calibre and I don't know how many people do. My own motivation for zotfile was that I wanted to add functionality I need myself. It is always much more work to add something so that it is useable for everyone and not just yourself but that is okay. If you find it useful and think there are others, go for it. If you want to contribute to zotfile in another way, I am happy to point you to things that I think are important.
  3. I suggest that you don't worry about the option in the zotfile preference window and the zotfile integration for now but instead focus on the function that executes the relevant steps. So just write a function that takes an attachment as an argument (att or something) and adds that attachment to Calibre. To begin, I would use something like Execute JS (FF addon), which is much easier for debugging etc. Using Execute JS you can get the currently selected zotero items using this code
var Zotero = Components.classes["@zotero.org/Zotero;1"]
                .getService(Components.interfaces.nsISupports)
                .wrappedJSObject;
var ZoteroPane = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser").ZoteroPane;

var items = ZoteroPane.getSelectedItems();

The first selected item is items[0]. If a regular item is selected, you can get the attachments of the first item using var atts = items[0].getAttachments();. Now just create a function function sendToCalibre(att) {...} and call it passing an attachment object (items[0] or atts[0] depending on what is selected). The function should create the file metadata.odf and then call two external binary (for adding the file and for the metadata). You will have to figure out the metadata.odf stuff yourself (not sure whether it makes sense to write the file directly or first export an bibtex - you could ask about the bibtex on the zotero dev google group). To call an external binary, take a look at the popplerExtractorCall function in zotfile.js. It calls the poppler extractor so it should be easy to adopt.

Does that help to get you started?

@saroele
Copy link

saroele commented Aug 13, 2013

Any news on this? Or another solution to sync the content of zotero with an ereader?

@fBedecarrats
Copy link

Hello, sorry but I have been overwhelmed with finishing my phd and I
haven't moved forward yet.
Le 13 août 2013 09:42, "saroele" notifications@github.com a écrit :

Any news on this? Or another solution to sync the content of zotero with
an ereader?


Reply to this email directly or view it on GitHubhttps://github.com//issues/47#issuecomment-22548088
.

@andersjohansson
Copy link

A short description of my alternative workflow for people finding this issue (ping @saroele):
I have a Sony PRS-T3 which is actually pretty good (for being an e-ink reader) at reading and annotating pdfs. The annotations are stored in some proprietary format on the device but can be written back into the pdfs (with varying results) using the great prsannots tool (https://github.com/rschroll/prsannots)

My workflow then:
Zotfile, send to tablet > run prsam add FILE in tablet folder > read and annotate on T3 > run prsam sync in tablet folder > rename FILE.annot to FILE (so that Zotfile recognizes it as changed I have another script for that) > Zotfile, get from tablet

It's a little clunky, but enables me to read and annotate my Zotero pdf:s on my e-ink reader!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants