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-2014, 04:55 PM   #1
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
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.
DaltonST is offline   Reply With Quote
Old 07-08-2014, 07:34 PM   #2
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
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.
davidfor is offline   Reply With Quote
Old 07-09-2014, 02:29 AM   #3
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: 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.
chaley is offline   Reply With Quote
Old 08-25-2014, 08:50 AM   #4
ahisham
Junior Member
ahisham began at the beginning.
 
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)
but it just fails without error message!

with this code:
Code:
um = {'#genre': {'#value#':genres, 'datatype':'text','is_multiple': None, 'name': u'Genre'}}
mi.set_all_user_metadata(um)
with genres as string, it completes but the genres are not saved!!

Could you please help me with correct way of doing it ?

Thanks
ahisham is offline   Reply With Quote
Old 08-25-2014, 02:55 PM   #5
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
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 .
DaltonST is offline   Reply With Quote
Old 08-26-2014, 03:55 AM   #6
ahisham
Junior Member
ahisham began at the beginning.
 
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
ahisham is offline   Reply With Quote
Old 08-26-2014, 05:35 AM   #7
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: 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.
chaley is offline   Reply With Quote
Old 08-26-2014, 10:36 AM   #8
ahisham
Junior Member
ahisham began at the beginning.
 
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)
Thanks
ahisham is offline   Reply With Quote
Old 08-26-2014, 10:49 AM   #9
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is online now   Reply With Quote
Old 08-26-2014, 11:18 AM   #10
ahisham
Junior Member
ahisham began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Aug 2014
Device: none
It seems so .. It is not possible!

Thanks all.
ahisham is offline   Reply With Quote
Old 08-26-2014, 11:20 AM   #11
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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
kovidgoyal is online now   Reply With Quote
Old 08-27-2014, 01:29 AM   #12
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: 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.
chaley is offline   Reply With Quote
Reply


Forum Jump

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


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


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