|
|
#1 |
|
Member
![]() Posts: 23
Karma: 10
Join Date: Jun 2016
Location: France
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! |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,615
Karma: 28549044
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
|
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Member
![]() Posts: 23
Karma: 10
Join Date: Jun 2016
Location: France
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:
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 06:59 AM. Reason: spoilered log |
|
|
|
|
|
#4 |
|
Member
![]() Posts: 23
Karma: 10
Join Date: Jun 2016
Location: France
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 |
|
|
|
|
|
#5 |
|
Member
![]() Posts: 23
Karma: 10
Join Date: Jun 2016
Location: France
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?
|
|
|
|
| Advert | |
|
|
|
|
#6 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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
'''
Code:
{author_name: link_value, ... }
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
'''
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'))
Code:
calibre-debug -e foo.py 'path_to_library' |
|
|
|
|
|
#7 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Moderator Notice
This thread belongs in the development forum. Moved. |
|
|
|
|
|
#8 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,615
Karma: 28549044
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 |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| set_metadata and covers | DarkAbsynthe | Calibre | 12 | 09-19-2020 03:38 PM |
| Bulk calibredb set_metadata? | jsmm | Library Management | 0 | 03-16-2013 03:54 PM |
| How to colour columns based on timestamp or on author_link | odinokij | Library Management | 4 | 11-09-2012 09:18 PM |
| Newbie: set_metadata? | OffColour | Development | 4 | 06-27-2012 11:52 AM |
| Command line calibredb set_metadata problem | Nedan | Calibre | 1 | 02-27-2009 09:44 PM |