09-02-2012, 01:45 AM | #1 |
Confused N00b
Posts: 7
Karma: 10
Join Date: Sep 2012
Location: USA
Device: none
|
Using Templates with ePub data?
I'm trying to understand Calibre's template system, and failing miserably.
I have epub files with ISBN fields like this: <dc:identifier id="uid">2940011827945</dc:identifier> and <dc:identifier id="PrimaryID" opf:scheme="URN">urn:uuid:9780547601182</dc:identifier> For the later, I can do {identifier:select(urn)} and have urn:uuid:9780547601182 show up as a custom column. For the former, I have no way of actually getting 2940011827945. My question is... how can I get just the value of the identifier field? Also, how can I take something like urn:uuid:etc and use the standard python list methods to trim off the static length bit at the beginning there I don't need? I'd assume this should be inanely simple; how can I just access the value of any of the dc:? fields? (Especially, of course, the ISBN one... which {isbn} works for less than 1/10th of my books on, and the Extract ISBN plugin seems to completely ignore the opf file altogether...) The template tutorial doesn't seem to have any examples of accessing this, so help would be greatly appreciated. Thanks! |
09-02-2012, 03:45 AM | #2 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You can use general program mode to get access to various functions like substr. If you really want to write in python, write a custom template function.
|
09-02-2012, 03:59 AM | #3 |
Confused N00b
Posts: 7
Karma: 10
Join Date: Sep 2012
Location: USA
Device: none
|
I'm not attached to writing it in python; isn't that the internal language for Calibre? But, let's say I go ahead and do so... can you tell me how I can actually access the stuff I asked about, in ANY mode?
|
09-02-2012, 04:08 AM | #4 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
program: x=field('identifiers'); y=select(x, 'urn'); substr(y, 5, 0); |
|
09-02-2012, 05:07 PM | #5 |
Confused N00b
Posts: 7
Karma: 10
Join Date: Sep 2012
Location: USA
Device: none
|
Okay, that's much more helpful, thank you! And it works brilliantly, (after I changed it to y, 9, 0 ;-) ). Nice!
However, it won't pick up the 'uid' I posted above. I'm not sure which bit is the raw metadata from the .epub itself, which is what I want to get at. This is the line: <dc:identifier id="uid">2940012494870</dc:identifier> I note that it doesn't have opf:scheme, which ones where I can snarf the isbn (and now urn, thank you!) do. Here's a working one: <dc:identifier id="PrimaryID" opf:scheme="URN">urn:uuid:9780547601328</dc:identifier> So, what I'm trying to ask is, how do I ask Calibre to just give me whatever's inside the <dc:identifer>XXXXXX</dc:identifier> tag? (or, be able to actually specify the 'id' field... doing y=select(x, 'uid') fails...) (I'm not at all keen to reinvent any wheels; if there's already something that does this, I'll happily use it. For one of the books I posted above, 'downloading metadata' fails for all sources, even though the ISBN is sitting right there!) |
09-02-2012, 05:20 PM | #6 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Templates operate on calibre metadata, not the opf in the ebook. There is no way for a template or a custom function to see into any book format file. If the information is not visible in the edit metadata dialog, a template cannot see it.
It is also worth noting that calibre will replace the embedded opf if the book is sent to a device or saved to a disk. |
09-02-2012, 08:55 PM | #7 |
Confused N00b
Posts: 7
Karma: 10
Join Date: Sep 2012
Location: USA
Device: none
|
Ah. ;-( My eventual goal, of course, is to save back to disk with proper metadata (as well as extras, like a real cover, series, etc).
So, it seems like if I really wanted to do this, I'd either need to do a plugin, or just fix the files somewhere else. I'm still much further along though, so thank you again for your help; with your concrete example, at least now I can make sense of the template documentation. |
09-03-2012, 03:08 AM | #8 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You are welcome.
It does sound like a plugin would be the way to go, perhaps similar to modify epub. Your plugin could copy info from the OPF to calibre metadata columns where they could be manipulated more easily. Good luck. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Batch store meta-tag data in epub | TPFKAS | Conversion | 9 | 12-07-2011 08:28 AM |
using templates/pyhon and custom columns to extract specific data from tags | smoothrolla | Library Management | 6 | 11-10-2011 05:12 PM |
ePub meta data | brudigia | ePub | 4 | 07-26-2010 12:58 PM |
Any command line to edit epub meta data? | bthoven | Calibre | 1 | 03-25-2010 07:26 AM |
Any command line to edit epub meta data? | bthoven | ePub | 2 | 03-25-2010 04:15 AM |