|
|
Thread Tools | Search this Thread |
07-08-2014, 04:55 PM | #1 |
Deviser
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
|
Metadata(_('Unknown')) : How To Dynamically Add Custom Columns To Definition
The plugin code fragment below is for updating a custom column "genre". However, Metadata(_('Unknown')) does not show that custom column being available for updating, as shown below.
id_map = {} for line in book_new_genre_list: s = line.split("$") s_book = s[0] s_genre = s[1] n_book = int(s_book) mi = Metadata(_('Unknown')) << So Only Updates Custom Column i = n_book mi.genre= s_genre << This does nothing for item in mi: print(str(item)) <<<<Output Shown Below id_map[i] = mi (output from print above) author_link_map author_sort cover_data tags user_categories identifiers author_sort_map languages user_metadata authors title device_collections edit_metadata_action = self.gui.iactions['Edit Metadata'] edit_metadata_action.apply_metadata_changes(id_map , callback=self._finish_displaying_results(payload)) Besides the unsuccessful "mi.genre" test, I also tried appending the new custom column, and even treating mi like a dictionary with a key = custom column name. Nothing works. Question: how does one add a custom column value to Metadata(_('Unknown')) "on the fly" so that the id_map is properly constructed? Thank you in advance for sharing your knowledge. |
07-08-2014, 07:34 PM | #2 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
You don't need to do anything extra to add it. Have a look for "set_user_metadata" and "get_user_metadata" in any of the plugins that use a custom column for storage. My Kobo Utilities plugin does it, but I suggest a smaller plugin such as Count Pages.
|
07-09-2014, 02:29 AM | #3 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
If 'genre' is a custom column then you should be using its lookup name, probably '#genre'. It is also probably better to use mi.set() instead of directly assigning to instance attributes, especially if dealing with series-type custom columns.
|
08-25-2014, 08:50 AM | #4 |
Junior Member
Posts: 8
Karma: 10
Join Date: Aug 2014
Device: none
|
Hi,
I tried to use the "mi.set_user_metadata(col_name, col)" as in count pages plugin. However, it uses the "col" variable that results from "db.field_metadata.custom_field_metadata()" function. In "src/calibre/ebooks/metadata/sources/amazon.py", I want to set a value in custom genre column. However, I don't have access to the above function (since "self.gui" is undefined). I tried to use this code instead: Code:
um = {'#genre': {'#value#':genres, 'datatype':'text','is_multiple': '|', 'name': u'Genre'}} mi.set_all_user_metadata(um) with this code: Code:
um = {'#genre': {'#value#':genres, 'datatype':'text','is_multiple': None, 'name': u'Genre'}} mi.set_all_user_metadata(um) Could you please help me with correct way of doing it ? Thanks |
08-25-2014, 02:55 PM | #5 |
Deviser
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
|
GUI Plugin API <> Metadata Download Plugin API
ahisham,
It appears to me that you might be trying to mix functions for GUI plugins together with Metadata Download plugins. The Calibre APIs are very different. Metadata Download plugins use: class calibre.ebooks.metadata.sources.base GUI plugins use: class calibre.gui2.actions.InterfaceAction Also, be aware that if you modify standard Calibre software, your modifications will be overwritten the next time you upgrade Calibre to the latest version (which happens every Friday). So, changing "src/calibre/ebooks/metadata/sources/amazon.py" itself is not recommended. The only help I can give to you is to refer you to: http://manual.calibre-ebook.com/plugins.html . |
08-26-2014, 03:55 AM | #6 |
Junior Member
Posts: 8
Karma: 10
Join Date: Aug 2014
Device: none
|
@DaltonST, Thanks a lot for your fast reply
Ok .. My objective is that I want to fill specific values into a custom column during amazon metadata download. This is why I looked for "src/calibre/ebooks/metadata/sources/amazon.py" since these values will be ready there. However, I just don't know how to save them into the custom column. The example of count pages plugin is a GUI plugin, so its way of saving the values in custom columns doesn't apply with amazon metadata downloader. For the updates, I just need this to run once on my library filling the values and then I will revert back my changes. Could you help me with saving the values in the custom column ? Or is it not feasible since amazon metadata downloader is not a GUI plugin ? Thanks |
08-26-2014, 05:35 AM | #7 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You cannot write values into the database inside a metadata download plugin. It has no access to the database, and can't have such access because the plugin is being run as a separate process.
And in any event, how would you know which books to change? As far as I can tell from looking at the source, the metadata download plugins don't have any idea what books are being updated. |
08-26-2014, 10:36 AM | #8 |
Junior Member
Posts: 8
Karma: 10
Join Date: Aug 2014
Device: none
|
As far as I read in amazon metadata downloader, I think it just update a Metadata object and then put it on a result queue (I still didn't figure who is responsible for getting it back). Then this Metadata is saved to database for the corresponding book which started the downloader in the first place.
This is why I was trying to add my values to this Metadata object to be saved along. Code:
mi.set_all_user_metadata(um) |
08-26-2014, 10:49 AM | #9 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
IIRC, metadata downloading discards all custom metadata fields, setting them on the metadata object will have no effect.
|
08-26-2014, 11:18 AM | #10 |
Junior Member
Posts: 8
Karma: 10
Join Date: Aug 2014
Device: none
|
It seems so .. It is not possible!
Thanks all. |
08-26-2014, 11:20 AM | #11 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Well, if you are willing to modify the source code anyway, you can change that, IIRC the relevant code is in sources/identify.py
|
08-27-2014, 01:29 AM | #12 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You could encode the data into a column you can change such as publisher, and then use global search and replace to move the data to the right column.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
importing metadata into custom columns | taleia | Library Management | 4 | 10-03-2023 05:56 AM |
Custom columns and metadata sources | kiwidude | Development | 30 | 06-05-2014 01:36 AM |
Custom Columns and metadata.calibre | cryzed | Library Management | 0 | 06-04-2013 06:00 PM |
Metadata and custom columns | dbolack | Development | 9 | 03-05-2012 09:07 AM |
Custom columns and epub metadata | xmodder | Library Management | 7 | 11-22-2011 09:31 PM |