ebook-meta: Add option to change published date

This commit is contained in:
Kovid Goyal 2010-02-15 12:27:05 -07:00
parent c82f3e4138
commit 8022663ac3
2 changed files with 7 additions and 1 deletions

View File

@ -15,6 +15,7 @@ from calibre.ebooks.metadata import string_to_authors, authors_to_sort_string, \
title_sort, MetaInformation title_sort, MetaInformation
from calibre.ebooks.lrf.meta import LRFMetaFile from calibre.ebooks.lrf.meta import LRFMetaFile
from calibre import prints from calibre import prints
from calibre.utils.date import parse_date
USAGE='%%prog ebook_file [' + _('options') + ']\n' + \ USAGE='%%prog ebook_file [' + _('options') + ']\n' + \
_(''' _('''
@ -69,6 +70,8 @@ def config():
help=_('Set the book producer.')) help=_('Set the book producer.'))
c.add_opt('language', ['-l', '--language'], c.add_opt('language', ['-l', '--language'],
help=_('Set the language.')) help=_('Set the language.'))
c.add_opt('pubdate', ['-d', '--date'],
help=_('Set the published date.'))
c.add_opt('get_cover', ['--get-cover'], c.add_opt('get_cover', ['--get-cover'],
help=_('Get the cover from the ebook and save it at as the ' 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() mi.series = opts.series.strip()
if getattr(opts, 'series_index', None) is not None: if getattr(opts, 'series_index', None) is not None:
mi.series_index = float(opts.series_index.strip()) 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: if getattr(opts, 'cover', None) is not None:
ext = os.path.splitext(opts.cover)[1].replace('.', '').upper() ext = os.path.splitext(opts.cover)[1].replace('.', '').upper()

View File

@ -863,7 +863,8 @@ class OPF(object):
def smart_update(self, mi): def smart_update(self, mi):
for attr in ('title', 'authors', 'author_sort', 'title_sort', for attr in ('title', 'authors', 'author_sort', 'title_sort',
'publisher', 'series', 'series_index', 'rating', 'publisher', 'series', 'series_index', 'rating',
'isbn', 'language', 'tags', 'category', 'comments'): 'isbn', 'language', 'tags', 'category', 'comments',
'pubdate'):
val = getattr(mi, attr, None) val = getattr(mi, attr, None)
if val is not None and val != [] and val != (None, None): if val is not None and val != [] and val != (None, None):
setattr(self, attr, val) setattr(self, attr, val)