mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port calibredb embed_metadata
This commit is contained in:
parent
704b6b1b63
commit
f99ae299f5
@ -4,19 +4,58 @@
|
||||
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from calibre import prints
|
||||
from calibre.db.cli import integers_from_string
|
||||
from calibre.srv.changes import formats_added
|
||||
|
||||
readonly = False
|
||||
version = 0 # change this if you change signature of implementation()
|
||||
|
||||
|
||||
def implementation(db, notify_changes, *args):
|
||||
is_remote = notify_changes is not None
|
||||
is_remote
|
||||
def implementation(db, notify_changes, book_id, only_fmts):
|
||||
if book_id is None:
|
||||
return db.all_book_ids()
|
||||
with db.write_lock:
|
||||
if db.has_id(book_id):
|
||||
db.embed_metadata((book_id,), only_fmts=only_fmts)
|
||||
formats_added({book_id: db.formats(book_id)})
|
||||
return db.field_for('title', book_id)
|
||||
|
||||
|
||||
def option_parser(get_parser, args):
|
||||
pass
|
||||
parser = get_parser(_(
|
||||
'''
|
||||
%prog embed_metadata [options] book_id
|
||||
|
||||
Update the metadata in the actual book files stored in the calibre library from
|
||||
the metadata in the calibre database. Normally, metadata is updated only when
|
||||
exporting files from calibre, this command is useful if you want the files to
|
||||
be updated in place. Note that different file formats support different amounts
|
||||
of metadata. You can use the special value 'all' for book_id to update metadata
|
||||
in all books. You can also specify many book ids separated by spaces and id ranges
|
||||
separated by hyphens. For example: %prog embed_metadata 1 2 10-15 23'''))
|
||||
parser.add_option('-f', '--only-formats', action='append', default=[], help=_(
|
||||
'Only update metadata in files of the specified format. Specify it multiple'
|
||||
' times for multiple formats. By default, all formats are updated.'))
|
||||
return parser
|
||||
|
||||
|
||||
def main(opts, args, dbctx):
|
||||
raise NotImplementedError('TODO: implement this')
|
||||
ids = set()
|
||||
for arg in args:
|
||||
if arg == 'all':
|
||||
ids = None
|
||||
break
|
||||
ids |= set(integers_from_string(arg))
|
||||
only_fmts = opts.only_formats or None
|
||||
if ids is None:
|
||||
ids = dbctx.run('embed_metadata', None, None)
|
||||
|
||||
def progress(i, title):
|
||||
prints(_('Processed {0} ({1} of {2})').format(title, i, len(ids)))
|
||||
|
||||
for i, book_id in enumerate(ids):
|
||||
title = dbctx.run('embed_metadata', book_id, only_fmts)
|
||||
progress(i+1, title or _('No book with id: {}').format(book_id))
|
||||
|
||||
return 0
|
||||
|
@ -22,8 +22,8 @@ COMMANDS = (
|
||||
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
||||
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
|
||||
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
||||
'check_library', 'list_categories', 'backup_metadata', 'clone',
|
||||
# 'embed_metadata', 'search'
|
||||
'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
|
||||
# 'search'
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user