diff --git a/src/calibre/ebooks/metadata/cli.py b/src/calibre/ebooks/metadata/cli.py index 5de8b76c43..780d3febcf 100644 --- a/src/calibre/ebooks/metadata/cli.py +++ b/src/calibre/ebooks/metadata/cli.py @@ -15,6 +15,7 @@ from calibre.ebooks.metadata import string_to_authors, authors_to_sort_string, \ title_sort, MetaInformation from calibre.ebooks.lrf.meta import LRFMetaFile from calibre import prints +from calibre.utils.date import parse_date USAGE='%%prog ebook_file [' + _('options') + ']\n' + \ _(''' @@ -69,6 +70,8 @@ def config(): help=_('Set the book producer.')) c.add_opt('language', ['-l', '--language'], help=_('Set the language.')) + c.add_opt('pubdate', ['-d', '--date'], + help=_('Set the published date.')) c.add_opt('get_cover', ['--get-cover'], help=_('Get the cover from the ebook and save it at as the ' @@ -132,6 +135,8 @@ def do_set_metadata(opts, mi, stream, stream_type): mi.series = opts.series.strip() if getattr(opts, 'series_index', None) is not None: mi.series_index = float(opts.series_index.strip()) + if getattr(opts, 'pubdate', None) is not None: + mi.pubdate = parse_date(opts.pubdate, assume_utc=False, as_utc=False) if getattr(opts, 'cover', None) is not None: ext = os.path.splitext(opts.cover)[1].replace('.', '').upper() diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 15ee0d1bc6..5e57b0b515 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -863,7 +863,8 @@ class OPF(object): def smart_update(self, mi): for attr in ('title', 'authors', 'author_sort', 'title_sort', 'publisher', 'series', 'series_index', 'rating', - 'isbn', 'language', 'tags', 'category', 'comments'): + 'isbn', 'language', 'tags', 'category', 'comments', + 'pubdate'): val = getattr(mi, attr, None) if val is not None and val != [] and val != (None, None): setattr(self, attr, val)