Quote:
Originally Posted by geekraver
Sounds like I would need to make a PR against Calibre.
|
If you know how to code well enough to make a PR (github Pull Request) against calibre then you should be able to write a script that does the work. The script would walk the library looking for an a.txt file (or whatever it is named) in the book folder. When it finds one then it uses
the calibre API method cache.add_format() method to add it as a book.
After verifying that the script worked, delete all the a.txt files.
This script might be a place to start.
Code:
import os
from calibre.library import db as DB
lib_path = sys.argv[1]
db = DB(path = lib_path)
cache = db.new_api
# Get the normalized library path
library_path = cache.backend.library_path
for book_id in cache.all_book_ids():
# Construct the full path to the book folder
path = os.path.join(library_path, cache.field_for('path', book_id).replace('/', os.sep))
# Check if the file a.txt is in that folder
txt_file = os.path.join(path, 'a.txt')
if os.path.exists(txt_file):
# It is. Add it as a format
cache.add_format(book_id, 'txt', txt_file, run_hooks=False)
print('added', txt_file)
You run it with calibre-debug -e script_file path_to_library
Of course, back up your library before running it!