Quote:
Originally Posted by Terisa de morgan
Thank you, I thought that was the way but I was not sure if there was an automated way. As I have a whole library with authors, that is not polished, I think I'll keep it for a future development... or I'll think for the future authors and I'll explore from there (I already copy through a plugin new authors to the authors library).
|
Generating the author links is straightforward using the calibre API. For each author in the library, find the book containing that author then write the link to standard output.
The code below generates links to a book for every author in the database. The output is 2-column CSV where column 1 is the author name and col 2 is the link.
Code:
from calibre.library import db as DB
import posixpath
lib_path = sys.argv[1]
lib_name = '_hex_-' + posixpath.basename(lib_path).encode('utf-8').hex()
db = DB(path = lib_path, read_only=True)
cache = db.new_api
# Loop through all the books in the library
author_info = cache.author_data()
for auth_id in author_info:
auth_books = cache.books_for_field('authors', auth_id)
print('"{}",calibre://show-book/{}/{}'.format(
author_info[auth_id]['name'], lib_name, str(next(iter(auth_books)))))
You run this code using
Code:
calibre-debug -e script.py path-to-library
The other side to put the author links into the author table would be similar.
- Read the data from above into a link_dict author_name:link
- Get the author data
- Make a list author_dict of author-name: author_id
- Make an empty dict new_link_dict
- for each name in link_dict check if the name is in author_dict. If so, add author_id:link to new_link_dict
- call cache.set_link_for_authors(new_link_dict)