jlegewie / zotfile

Zotero plugin to manage your attachments: automatically rename, move, and attach PDFs (or other files) to Zotero items, sync PDFs from your Zotero library to your (mobile) PDF reader (e.g. an iPad, Android tablet, etc.), and extract PDF annotations.
4.04k stars 280 forks source link

Support for calibre? #47

Open egh opened 12 years ago

egh commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

Thanks, I'll see what I can do!

fBedecarrats commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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: <?xml version='1.0' encoding='utf-8'?>

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:

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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

fBedecarrats commented 11 years ago

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/jlegewie/zotfile/issues/47#issuecomment-22548088 .

andersjohansson commented 9 years ago

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!