mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow use of {last_modified} in save to disk templates
This commit is contained in:
parent
f11ab2f63d
commit
4eba1acad2
@ -222,7 +222,7 @@ class SaveWorker(Thread):
|
|||||||
if isbytestring(fpath):
|
if isbytestring(fpath):
|
||||||
fpath = fpath.decode(filesystem_encoding)
|
fpath = fpath.decode(filesystem_encoding)
|
||||||
formats[fmt.lower()] = fpath
|
formats[fmt.lower()] = fpath
|
||||||
data[i] = [opf, cpath, formats]
|
data[i] = [opf, cpath, formats, mi.last_modified.isoformat()]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -17,6 +17,7 @@ from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
|||||||
from calibre.constants import preferred_encoding
|
from calibre.constants import preferred_encoding
|
||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
from calibre.ebooks.metadata import title_sort
|
from calibre.ebooks.metadata import title_sort
|
||||||
|
from calibre.utils.date import parse_date
|
||||||
from calibre import strftime, prints, sanitize_file_name_unicode
|
from calibre import strftime, prints, sanitize_file_name_unicode
|
||||||
|
|
||||||
plugboard_any_device_value = 'any device'
|
plugboard_any_device_value = 'any device'
|
||||||
@ -42,6 +43,8 @@ FORMAT_ARG_DESCS = dict(
|
|||||||
publisher=_('The publisher'),
|
publisher=_('The publisher'),
|
||||||
timestamp=_('The date'),
|
timestamp=_('The date'),
|
||||||
pubdate=_('The published date'),
|
pubdate=_('The published date'),
|
||||||
|
last_modified=_('The date when the metadata for this book record'
|
||||||
|
' was last modified'),
|
||||||
id=_('The calibre internal id')
|
id=_('The calibre internal id')
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -191,6 +194,9 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250,
|
|||||||
format_args['timestamp'] = strftime(timefmt, mi.timestamp.timetuple())
|
format_args['timestamp'] = strftime(timefmt, mi.timestamp.timetuple())
|
||||||
if hasattr(mi.pubdate, 'timetuple'):
|
if hasattr(mi.pubdate, 'timetuple'):
|
||||||
format_args['pubdate'] = strftime(timefmt, mi.pubdate.timetuple())
|
format_args['pubdate'] = strftime(timefmt, mi.pubdate.timetuple())
|
||||||
|
if hasattr(mi, 'last_modified') and hasattr(mi.last_modified, 'timetuple'):
|
||||||
|
format_args['last_modified'] = strftime(timefmt, mi.last_modified.timetuple())
|
||||||
|
|
||||||
format_args['id'] = str(id)
|
format_args['id'] = str(id)
|
||||||
# Now format the custom fields
|
# Now format the custom fields
|
||||||
custom_metadata = mi.get_all_user_metadata(make_copy=False)
|
custom_metadata = mi.get_all_user_metadata(make_copy=False)
|
||||||
@ -373,10 +379,14 @@ def save_serialized_to_disk(ids, data, plugboards, root, opts, callback):
|
|||||||
root, opts, length = _sanitize_args(root, opts)
|
root, opts, length = _sanitize_args(root, opts)
|
||||||
failures = []
|
failures = []
|
||||||
for x in ids:
|
for x in ids:
|
||||||
opf, cover, format_map = data[x]
|
opf, cover, format_map, last_modified = data[x]
|
||||||
if isinstance(opf, unicode):
|
if isinstance(opf, unicode):
|
||||||
opf = opf.encode('utf-8')
|
opf = opf.encode('utf-8')
|
||||||
mi = OPF(cStringIO.StringIO(opf)).to_book_metadata()
|
mi = OPF(cStringIO.StringIO(opf)).to_book_metadata()
|
||||||
|
try:
|
||||||
|
mi.last_modified = parse_date(last_modified)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
tb = ''
|
tb = ''
|
||||||
try:
|
try:
|
||||||
failed, id, title = do_save_book_to_disk(x, mi, cover, plugboards,
|
failed, id, title = do_save_book_to_disk(x, mi, cover, plugboards,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user