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 10-14-2022, 09:09 AM   #1
lrpirlet
Connoisseur
lrpirlet began at the beginning.
 
Posts: 93
Karma: 40
Join Date: Mar 2020
Location: Belgium (sorry, I am from the Walloon side of the country and I speak french only)
Device: PW3, Kobo Libra H2O
Question method identify() is inconsistent in providing authors

I am developing a "new" babelio_db plugin. This is a french site with all books in french...

I am developing in the English language to get the messages ( so I can find the sources), and switching to the french language from time to time to check how it goes.

calibre interface is in English.
When I create an empty book with no authors, it get translated and stored as "unknown"...
I then run the plugin, identify() passes authors as None

calibre interface is in French.
When I create an empty book with no authors, it get translated and stored as "Inconnu(e)"...
When running the plugin, identify() passes authors as None

so far so good..

Now, I have a book created under calibre in English. I switch to the french interface, the identify() passes the authors as ['Unknown'].
That makes a very different result compared to authors = None

Same situation in reverse for a french created book under the English interface, except that identify() now returns ['Inconnu(e)'].
I have worked around this last situation by forcing authors = ['Inconnu(e)'] to be None, or by wiping out the authors field before starting the metadata download...
But I am not sure that this would be the right approach...

I am not that fluent with python, but I am learning (when I have time)... I can try to correct that behavior... but I could not find in the calibre sources where the translation from 'unknown', or equivalent in other language, to None is implemented...

Thanks in advance for any help
lrpirlet is offline   Reply With Quote
Old 10-14-2022, 10:04 AM   #2
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,866
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yes, if you switch between interface languages this will happen. This is because calibre requires there to always be an author value as it is used int he filesystem.

If you expect people to be using multiple interface languages with your plugin, with books with unknown authors, simply special case the "Unknown" string for authors in all those languages in the identify method in your plugin. For you likely five or six major european languages is all you need.
kovidgoyal is online now   Reply With Quote
Advert
Old 10-14-2022, 11:58 AM   #3
lrpirlet
Connoisseur
lrpirlet began at the beginning.
 
Posts: 93
Karma: 40
Join Date: Mar 2020
Location: Belgium (sorry, I am from the Walloon side of the country and I speak french only)
Device: PW3, Kobo Libra H2O
OK, fair enough... If that is the normal behavior, I'll make a note in the associated documentation.

Thanks anyway.

To be complete this is what I have done in the very first line of identify():
Code:
        debug=self.dbg_lvl & 1
        if debug:
            log.info("title             : ", title)
            log.info("identifiers       : ", identifiers)
            log.info("authors           : ", authors)

        nknwn = ['Inconnu(e)', 'Unknown']
        for i in range(len(nknwn)):
            if authors and nknwn[i] in authors[0]: 
                authors = None
                break
            
        if debug:
            log.info("authors corrected : ", authors)
If switching between language, the nknwn list should be completed. I may add French Canadian, Italian and Roman too...
lrpirlet is offline   Reply With Quote
Old 10-15-2022, 05:42 AM   #4
un_pogaz
Chalut o/
un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.
 
un_pogaz's Avatar
 
Posts: 410
Karma: 145324
Join Date: Dec 2017
Device: Kobo
Oh, un plugin babelio, merci, ça sera utile.

You can also retrieve the current translated value of 'Unknown' with
Code:
from calibre.ebooks.metadata.book.base import NULL_VALUES
NULL_VALUES is a dict, but small trap 'authors' value is a list
Code:
nknwn = ['Inconnu(e)', 'Unknown', NULL_VALUES['authors'][0]]
un_pogaz is online now   Reply With Quote
Old 10-15-2022, 06:03 AM   #5
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by un_pogaz View Post
Oh, un plugin babelio, merci, ça sera utile.

You can also retrieve the current translated value of 'Unknown' with
Code:
from calibre.ebooks.metadata.book.base import NULL_VALUES
NULL_VALUES is a dict, but small trap 'authors' value is a list
Code:
nknwn = ['Inconnu(e)', 'Unknown', NULL_VALUES['authors'][0]]
Another option if you have a metadata object (mi): use
Code:
mi.is_null('authors')
chaley is offline   Reply With Quote
Advert
Old 10-15-2022, 08:28 AM   #6
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,866
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Those only work for the current translation, which is handled anyway. its when you have an Unknown value translated into something other than the current language that the issue arises.
kovidgoyal is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding using metadata objects in identify method of metadata download plugin api aprekates Development 1 07-06-2014 03:35 AM
Metadata download API , regarding identify method. aprekates Development 1 07-04-2014 12:01 PM
Is Amazon providing samples not available in restricted countries? lene1949 Amazon Kindle 0 04-16-2010 11:08 AM


All times are GMT -4. The time now is 09:19 AM.


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