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 05-16-2023, 10:57 AM   #1
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2016
Device: PocketBook Touch Lux 2
Updating author_link field with calibredb set_metadata

Hi everyone

I want to know if it's is possible to modify the values of the author_link field with the command line calibresd set_metadata? And if so, how?

Yhnak you in advance!
Nicolas.Laurent is offline   Reply With Quote
Old 05-16-2023, 11:36 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
Look at the opf produced by calibredb show_metadata --as-opf see how the link field is encoded there and use similar encoding in the OPF you pass to set_metadata
kovidgoyal is offline   Reply With Quote
Old 05-17-2023, 02:02 AM   #3
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2016
Device: PocketBook Touch Lux 2
Hi Kovid

And thank you for such a quick answer
Unfortunately, the link field doesn't seem to appear when I look to the results of your code.

That's what I obtain (for information, the value of the author_link field is "https://fr.wikipedia.org/wiki/Renaud_Capu%C3%A7on")

Spoiler:

E:\Applications\!Exportation>chcp 28591 1>nul

E:\Applications\!Exportation>cd /d C:\Applications portables\Calibre\Calibre Portable\Calibre\

C:\Applications portables\Calibre\Calibre Portable\Calibre>calibredb show_metadata --as-opf 287 --with-library "C:\Applications portables\Calibre\Calibre Portable\Calibre Library"
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="calibre_id" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlnspf="http://www.idpf.org/2007/opf">
<dc:title>Mouvement perpétuel</dc:title>
<dc:creator opf:role="aut" opf:file-as="CAPUÇON, Renaud">CAPUÇON, Renaud</dc:creator>
<dc:contributor opf:role="bkp" opf:file-as="calibre">calibre (6.17.0) [https://calibre-ebook.com]</dc:contributor>
<dc:identifier id="calibre_id" opf:scheme="calibre">287</dc:identifier>
<dc:date>2020-02-05T09:14:16+00:00</dc:date>
<dc:language>fra</dc:language>
<dc:description>&lt;div&gt;
&lt;p&gt;*À peine mon archet eut-il effleuré les cordes du Vicomte de Panette que je fus saisi d’une sensation de bien-être intense. La sonorité de ce violon me parlait comme le ferait une voix intérieure. Je me mis à jouer le thème de la première sonate de Brahms…*».&lt;/p&gt;
&lt;p&gt;Un jour de 2005, Renaud Capuçon fait une rencontre bouleversante, celle du violon de sa vie : le mythique Guarnerius del Gesu de 1737, appelé Vicomte de Panette, que joua Isaac Stern pendant près de cinquante ans. Depuis lors, cet instrument merveilleux fait corps avec lui sur les scènes du monde entier.&lt;/p&gt;
&lt;p&gt;Initié à la musique à l’âge de quatre ans et formé à l’école des plus grands, du Conservatoire de Paris aux concerts avec Carlo Maria Giulini, Claudio Abbado, Daniel Barenboïm ou Martha Argerich, Renaud Capuçon nous livre ici les étapes d’une vie dédiée à la musique.&lt;br&gt;Artiste lumineux et tourné vers la transmission, mais aussi homme d’action, Renaud Capuçon a créé plusieurs festivals, dont le festival de Pâques d’Aix-en-Provence. &lt;/p&gt;
&lt;p&gt;*&lt;/p&gt;&lt;/div&gt;</dc:description>
<dcublisher>Flammarion (Éditions)</dcublisher>
<dc:identifier opf:scheme="ISBN">9782081517578</dc:identifier>
<dc:subject>Musique</dc:subject>
<dc:subject>Autobiographie</dc:subject>
<dc:subject>det_</dc:subject>
<meta name="calibre:title_sort" content="Mouvement perpétuel"/>
<meta name="calibre:timestamp" content="2021-09-24T09:32:55+00:00"/>
</metadata>
<manifest/>
<spine/>
<guide/>
</package>


I surely miss something, but I don't know what...
Could you help me a little more ?

Last edited by theducks; 05-17-2023 at 05:59 AM. Reason: spoilered log
Nicolas.Laurent is offline   Reply With Quote
Old 05-23-2023, 09:29 AM   #4
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2016
Device: PocketBook Touch Lux 2
It seems that adding link to authors is possible through the API function set_link_for_authors(author_id_to_link_map)

https://www.mobileread.com/forums/sh...d.php?t=287741

Can someone detail a little more how to use this feature?

Thanks in advance for your help
Nicolas.Laurent is offline   Reply With Quote
Old 07-04-2023, 08:54 AM   #5
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2016
Device: PocketBook Touch Lux 2
I am reposting this message in the hope that someone has a solution to propose. How to copy a list of links assigned to authors in calibre without having to enter them manually?
Nicolas.Laurent is offline   Reply With Quote
Old 07-04-2023, 10:25 AM   #6
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
I'm not sure what you are trying to do. I assume you want to read and write author links in a script using the calibre API.

The correct API to use is in db.cache:
Code:
def set_link_map(self, field, value_to_link_map, only_set_if_no_existing_link=False):
        '''
        Sets links for item values in field.
        Note: this method doesn't change values not in the value_to_link_map

        :param field: the lookup name
        :param value_to_link_map: dict(field_value:link, ...). Note that these are values, not field ids.

        :return: books changed by setting the link

        '''
In your case the map would be
Code:
{author_name: link_value, ... }
If you are trying to use/export existing links then use
Code:
    def get_link_map(self, for_field):
        '''
        Return a dictionary of links for the supplied field.

        :param for_field: the lookup name of the field for which the link map is desired

        :return: {field_value:link_value, ...} for non-empty links
        '''
Here is a code sample that manipulates the author links.
Code:
from calibre.library import db as DB

lib_path = sys.argv[1]
db = DB(path = lib_path)
cache = db.new_api

# print all the links in the map
author_link_map = cache.get_link_map('authors')
for aut,link in author_link_map.items():
    print(aut, link)
    
print('*******************')
# Save the existing link for author 'A B'
existing_link = author_link_map.get('A B')
print('existing link', existing_link)
print('*******************')

# modify a link
new_links = dict()
new_links['A B'] = 'This is a new link' # Author named "A B" must exist
cache.set_link_map('authors', new_links)

# Test that it was changed
author_link_map = cache.get_link_map('authors')
print('New link:', author_link_map.get('A B'))
print('*******************')

# Now put the old link back
new_links['A B'] = existing_link
cache.set_link_map('authors', new_links)
author_link_map = cache.get_link_map('authors')
print('Restored link:', author_link_map.get('A B'))
If the above is in the file foo.py you would call it with
Code:
calibre-debug -e foo.py 'path_to_library'
chaley is offline   Reply With Quote
Old 07-04-2023, 10:29 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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Moderator Notice
This thread belongs in the development forum. Moved.
chaley is offline   Reply With Quote
Old 07-04-2023, 11:00 AM   #8
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
calibre-debug myfile.py

In myfile.py something like
Code:
from calibre.library import db
db = db().new_api

now call whatever functions you want from that API
kovidgoyal is offline   Reply With Quote
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
Bulk calibredb set_metadata? jsmm Library Management 0 03-16-2013 02:54 PM
How to colour columns based on timestamp or on author_link odinokij Library Management 4 11-09-2012 08:18 PM
Newbie: set_metadata? OffColour Development 4 06-27-2012 10:52 AM
Command line calibredb set_metadata problem Nedan Calibre 1 02-27-2009 08:44 PM


All times are GMT -4. The time now is 04:20 PM.


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