Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 07-08-2011, 09:49 PM   #1
Silek
Junior Member
Silek began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2011
Device: color nook
Can;t modify user columns with set_metadata?

Hello.

I am working on a script to update metadata in Calibre 0.8.8.

I have a perl script using XML::Simple with JSON to decode, and then encode the user_metadata->content fields.

When I run calibredb set_metadata on the OPF file I generate, I do not get an error, but I also do not get the user columns set. What is strange to me also is when I add fields to the user columns in the GUI, then run show_metadata, I do not see the entries in the OPF file for the user column.

Am I doing something wrong here? Does set_metadata not work for user/custom column data? Is show_metadata not supposed to show entries in these fields?
Silek is offline   Reply With Quote
Old 07-09-2011, 04:21 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,358
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Silek View Post
When I run calibredb set_metadata on the OPF file I generate, I do not get an error, but I also do not get the user columns set.
Command line set_metadata will update custom columns.

The format for custom columns in the OPF is complicated. My guess is that you have it wrong and the data is being ignored. Change a book using the GUI to have the data you expect when you run set_metadata, then look at the metadata.opf file for the book. Ensure that your script generates exactly the same stuff.
Quote:
What is strange to me also is when I add fields to the user columns in the GUI, then run show_metadata, I do not see the entries in the OPF file for the user column.
I see them in both the OPF and columnar output. For example, dumping the OPF for one of my books in my test library I get
Spoiler:
Code:
<meta name="calibre:user_metadata:#enum" content="{&quot;
is_category&quot;: true, &quot;
#extra#&quot;: null, &quot;
kind&quot;: &quot;
field&quot;, &quot;
is_custom&quot;: true, &quot;
is_csp&quot;: false, &quot;
colnum&quot;: 7, &quot;
column&quot;: &quot;value&quot;, &quot;
rec_index&quot;: 28, &quot;
search_terms&quot;: [&quot;#enum&quot;], &quot;
link_column&quot;: &quot;value&quot;, &quot;
is_multiple2&quot;: {}, &quot;
is_multiple&quot;: null, &quot;
datatype&quot;: &quot;enumeration&quot;, &quot;
#value#&quot;: &quot;def&quot;, &quot;
category_sort&quot;: &quot;value&quot;, &quot;
table&quot;: &quot;custom_column_7&quot;, &quot;
is_editable&quot;: true, &quot;
label&quot;: &quot;enum&quot;, &quot;
display&quot;: {&quot;use_decorations&quot;: 2, &quot;enum_values&quot;: [&quot;def&quot;, &quot;one&quot;, &quot;two&quot;, &quot;five&
quot;, &quot;no&quot;]}, &quot;
name&quot;: &quot;énum&quot;
}"/>
However, during testing I did find a bug in the OPF renderer that has been there for over a year (!). The generated OPF has empty values for tags-like custom columns. If you are testing exclusively with an is_multiple datatype, that would explain you not seeing. Non-multiple columns do render values correctly, as shown above. Note that the columnar output does not suffer from this problem.
chaley is offline   Reply With Quote
Advert
Old 07-09-2011, 09:15 AM   #3
Silek
Junior Member
Silek began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2011
Device: color nook
Thanks for the reply.

The rendering problem you mention may be why I am not seeing the GUI entries. I am using the "multiple text, show in tag browser" column type.

What my script is doing is (with perl XML:Simple and JSON) slurping a template.opf from an empty book, and in the case of custom columns, using JSON to decode the string, alter the resultant perl structure, and then encode and put the changed string back in the XML.

The XML format is somewhat different, but looks similar enough. I have even taken the "content" field out and cut and pasted it into the template and that also has not worked.

Now the order of the JSON fields is different, but I thought that would not matter.

The template entry for a custom field is:

<meta name="calibre:user_metadata:#characters" content="{&quot;is_category&quot;: true, &quot;#extra#&quot;: null, &quot;kind&quot;: &quot;field&quot;, &quot;is_custom&quot;: true, &quot;is_csp&quot;: false, &quot;colnum&quot;: 16, &quot;column&quot;: &quot;value&quot;, &quot;rec_index&quot;: 25, &quot;search_terms&quot;: [&quot;#characters&quot;], &quot;link_column&quot;: &quot;value&quot;, &quot;is_multiple2&quot;: {&quot;cache_to_list&quot;: &quot;|&quot;, &quot;list_to_ui&quot;: &quot; &amp; &quot;, &quot;ui_to_list&quot;: &quot;&amp;&quot;}, &quot;is_multiple&quot;: &quot;|&quot;, &quot;datatype&quot;: &quot;text&quot;, &quot;#value#&quot;: [], &quot;category_sort&quot;: &quot;value&quot;, &quot;table&quot;: &quot;custom_column_16&quot;, &quot;is_editable&quot;: true, &quot;label&quot;: &quot;characters&quot;, &quot;display&quot;: {&quot;is_names&quot;: true}, &quot;name&quot;: &quot;Characters&quot;}"/>


My entry is:

<meta>
<name>calibre:user_metadata:#characters</name>
<content>{&quot;link_column&quot;:&quot;value&quot ;,&quot;is_csp&quot;:false,&quot;table&quot;:&quot ;custom_column_16&quot;,&quot;search_terms&quot;:[&quot;#characters&quot;],&quot;rec_index&quot;:25,&quot;display&quot;:{&qu ot;is_names&quot;:true},&quot;is_custom&quot;:true ,&quot;is_category&quot;:true,&quot;kind&quot;:&qu ot;field&quot;,&quot;#value#&quot;:&quot;[ Sasha Hammer, Iron Man, War Machine, Dum Dum Dugan, Pepper Potts, Maria Hill, Ezekiel Stane ]&quot;,&quot;colnum&quot;:16,&quot;is_editable&quo t;:true,&quot;category_sort&quot;:&quot;value&quot ;,&quot;column&quot;:&quot;value&quot;,&quot;name& quot;:&quot;Characters&quot;,&quot;is_multiple2&qu ot;:{&quot;ui_to_list&quot;:&quot;&amp;&quot;,&quo t;cache_to_list&quot;:&quot;|&quot;,&quot;list_to_ ui&quot;:&quot; &amp; &quot;},&quot;#extra#&quot;:null,&quot;label&quot; :&quot;characters&quot;,&quot;is_multiple&quot;:&q uot;|&quot;,&quot;datatype&quot;:&quot;text&quot;} </content>
</meta>

Due to the rendering problem, I do not have a good idea of what the entry is supposed to look like. I figure the #value# entry is wrong, but I am not getting an error from calibredb set_metadata. Since I did not get an error, I did not know to dig in to the format (or even, where in the format to look).

Any pointers on what is wrong with the JSON above, or where to look for either helpful error messages or a sample of a working XML snippet would be greatly appreciated.

I am using this data type because I wanted these entries to show in the tag browser. I suppose I could use dc:subject tags and add then specifically as tags, and leave them as one long comma delimited string in a text field, but that feels kludgy.

Thanks again.

Lawrence
Silek is offline   Reply With Quote
Old 07-09-2011, 09:36 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,358
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Silek View Post
The rendering problem you mention may be why I am not seeing the GUI entries. I am using the "multiple text, show in tag browser" column type.
Look at the metadata.opf file in the books folder in the library. They do not exhibit the problem.
Quote:
Now the order of the JSON fields is different, but I thought that would not matter.
It won't.
Quote:

The template entry for a custom field is:

My entry is:

<meta>
<name>calibre:user_metadata:#characters</name>
<content>
I have no idea if calibre's xml engine will consider this alternate structure as equivalent to its own.
Quote:
Due to the rendering problem, I do not have a good idea of what the entry is supposed to look like.
As mentioned above, you can see calibre's version in the metadata.opf file.
Quote:
I figure the #value# entry is wrong, but I am not getting an error from calibredb set_metadata. Since I did not get an error, I did not know to dig in to the format (or even, where in the format to look).
The question is whether or not the JSON decode will work. The decoder might not throw an error, but could come up with different values. For example, I note that your string constants in #value# are not quoted. JSON will probably ignore them.
Quote:
I am using this data type because I wanted these entries to show in the tag browser. I suppose I could use dc:subject tags and add then specifically as tags, and leave them as one long comma delimited string in a text field, but that feels kludgy.
There are a lot of types that show up in the tag browser, such as text, enumeration, text/multiple, composite w/show in tag browser checked. You should use the one that makes sense for your data.

I also note that your template declares that the multiple text entry contains names (the is_names in the display attribute). Why did you check that box for tags-like items?
chaley is offline   Reply With Quote
Old 07-09-2011, 02:40 PM   #5
Silek
Junior Member
Silek began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2011
Device: color nook
Thanks. In the book directory I see the metadata.opf.

I checked for "people's names" because usually they are people's names. That said, I did not actually check the documentation as to what the box did.

I am going to get the right format into the JSON and see if that resolved the problem.

Thank you very much for your quick replies. I did not even think to check the book directory metadata.opf.
Silek is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
set_metadata and covers DarkAbsynthe Calibre 12 09-19-2020 02:38 PM
User PNG's for User Columns transmitthis Library Management 7 06-29-2011 04:45 PM
Can I modify the dictionary? youngsmoke Fictionwise eBookwise 0 11-30-2010 04:48 PM
User Defined Columns jjansen Calibre 3 03-17-2010 05:33 PM
Command line calibredb set_metadata problem Nedan Calibre 1 02-27-2009 08:44 PM


All times are GMT -4. The time now is 01:58 PM.


MobileRead.com is a privately owned, operated and funded community.