Quote:
Originally Posted by myki
Thanx for your answer chaley. When i will have more time to spend on this, i will try by using ebook-meta.exe in a batch file.
|
Even better would be a plugin. They have access to the database and can update book metadata. Of course, doing a plugin has a fairly high start-up cost, to learn python, to learn calibre's API, and to learn the plugin architecture. But in the end you would have a solution where you push one button in calibre and all the books are updated.
Another solution that is easier than a plugin is to write a python script that uses calibre's API. Here is an example that does what you want (I think)
Code:
def init_cache(library_path):
from calibre.db.backend import DB
from calibre.db.cache import Cache
backend = DB(library_path)
cache = Cache(backend)
cache.init()
return cache
from collections import defaultdict
cache = init_cache(library_path = sys.argv[1])
series_info = {}
for id_ in cache.all_book_ids():
series = cache.field_for('series', id_)
if series:
sidx = cache.field_for('series_index', id_)
if series in series_info:
sidx = max(sidx, series_info[series]['max_index'])
series_info[series]['max_index'] = sidx
else:
series_info[series] = {'max_index':sidx, 'ids':set()}
series_info[series]['ids'].add(id_)
for series in series_info.iterkeys():
sidx = series_info[series]['max_index']
dct = {book_id:sidx for book_id in series_info[series]['ids']}
cache.set_field('#myfloat', dct)
print(series, sidx)
You would need to change the lookup name where you want to store the maximum series number.
You call the script with something like
Code:
d:\CBH_Data\calibre.git>calibre-debug -e tests\highest_number_is_series.py Library.test_small
where "tests\highest_number_is_series.py" is the file containing the above script and the last parameter is the path to the folder containing the library.