mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New metadata:
1) remove 'category' from standard metadata fields 2) make isbn a classifier. Add ability to add more classifiers 3) fixup TODO: to make them easier to find.
This commit is contained in:
parent
a60d58f1c1
commit
65f8767057
@ -135,6 +135,7 @@ class CollectionsBookList(BookList):
|
|||||||
elif isinstance(val, unicode):
|
elif isinstance(val, unicode):
|
||||||
val = [val]
|
val = [val]
|
||||||
for category in val:
|
for category in val:
|
||||||
|
# TODO: NEWMETA: format the custom fields
|
||||||
if attr == 'tags' and len(category) > 1 and \
|
if attr == 'tags' and len(category) > 1 and \
|
||||||
category[0] == '[' and category[-1] == ']':
|
category[0] == '[' and category[-1] == ']':
|
||||||
continue
|
continue
|
||||||
|
@ -19,8 +19,14 @@ SOCIAL_METADATA_FIELDS = frozenset([
|
|||||||
# Of the form { scheme1:value1, scheme2:value2}
|
# Of the form { scheme1:value1, scheme2:value2}
|
||||||
# For example: {'isbn':'123456789', 'doi':'xxxx', ... }
|
# For example: {'isbn':'123456789', 'doi':'xxxx', ... }
|
||||||
'classifiers',
|
'classifiers',
|
||||||
'isbn', # Pseudo field for convenience, should get/set isbn classifier
|
])
|
||||||
'category', # TODO: not sure what this is, but it is used by OPF
|
|
||||||
|
'''
|
||||||
|
The list of names that convert to classifiers when in get and set.
|
||||||
|
'''
|
||||||
|
|
||||||
|
TOP_LEVEL_CLASSIFIERS = frozenset([
|
||||||
|
'isbn',
|
||||||
])
|
])
|
||||||
|
|
||||||
PUBLICATION_METADATA_FIELDS = frozenset([
|
PUBLICATION_METADATA_FIELDS = frozenset([
|
||||||
@ -77,7 +83,7 @@ CALIBRE_METADATA_FIELDS = frozenset([
|
|||||||
'application_id', # An application id, currently set to the db_id.
|
'application_id', # An application id, currently set to the db_id.
|
||||||
# the calibre primary key of the item.
|
# the calibre primary key of the item.
|
||||||
'db_id', # the calibre primary key of the item.
|
'db_id', # the calibre primary key of the item.
|
||||||
# TODO: May want to remove once Sony's no longer use it
|
# TODO: NEWMETA: May want to remove once Sony's no longer use it
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import traceback
|
|||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.ebooks.metadata.book import COPYABLE_METADATA_FIELDS
|
from calibre.ebooks.metadata.book import COPYABLE_METADATA_FIELDS
|
||||||
from calibre.ebooks.metadata.book import STANDARD_METADATA_FIELDS
|
from calibre.ebooks.metadata.book import STANDARD_METADATA_FIELDS
|
||||||
|
from calibre.ebooks.metadata.book import TOP_LEVEL_CLASSIFIERS
|
||||||
from calibre.utils.date import isoformat
|
from calibre.utils.date import isoformat
|
||||||
|
|
||||||
|
|
||||||
@ -55,6 +56,8 @@ class Metadata(object):
|
|||||||
|
|
||||||
def __getattribute__(self, field):
|
def __getattribute__(self, field):
|
||||||
_data = object.__getattribute__(self, '_data')
|
_data = object.__getattribute__(self, '_data')
|
||||||
|
if field in TOP_LEVEL_CLASSIFIERS:
|
||||||
|
return _data.get('classifiers').get(field, None)
|
||||||
if field in STANDARD_METADATA_FIELDS:
|
if field in STANDARD_METADATA_FIELDS:
|
||||||
return _data.get(field, None)
|
return _data.get(field, None)
|
||||||
try:
|
try:
|
||||||
@ -68,7 +71,9 @@ class Metadata(object):
|
|||||||
|
|
||||||
def __setattr__(self, field, val, extra=None):
|
def __setattr__(self, field, val, extra=None):
|
||||||
_data = object.__getattribute__(self, '_data')
|
_data = object.__getattribute__(self, '_data')
|
||||||
if field in STANDARD_METADATA_FIELDS:
|
if field in TOP_LEVEL_CLASSIFIERS:
|
||||||
|
_data['classifiers'].update({field: val})
|
||||||
|
elif field in STANDARD_METADATA_FIELDS:
|
||||||
if val is None:
|
if val is None:
|
||||||
val = NULL_VALUES.get(field, None)
|
val = NULL_VALUES.get(field, None)
|
||||||
_data[field] = val
|
_data[field] = val
|
||||||
@ -301,8 +306,6 @@ class Metadata(object):
|
|||||||
fmt('Publisher', self.publisher)
|
fmt('Publisher', self.publisher)
|
||||||
if getattr(self, 'book_producer', False):
|
if getattr(self, 'book_producer', False):
|
||||||
fmt('Book Producer', self.book_producer)
|
fmt('Book Producer', self.book_producer)
|
||||||
if self.category:
|
|
||||||
fmt('Category', self.category)
|
|
||||||
if self.comments:
|
if self.comments:
|
||||||
fmt('Comments', self.comments)
|
fmt('Comments', self.comments)
|
||||||
if self.isbn:
|
if self.isbn:
|
||||||
@ -321,14 +324,7 @@ class Metadata(object):
|
|||||||
fmt('Published', isoformat(self.pubdate))
|
fmt('Published', isoformat(self.pubdate))
|
||||||
if self.rights is not None:
|
if self.rights is not None:
|
||||||
fmt('Rights', unicode(self.rights))
|
fmt('Rights', unicode(self.rights))
|
||||||
# TODO: These are not in metadata. Should they be?
|
# TODO: NEWMETA: What to do about custom fields?
|
||||||
# if self.lccn:
|
|
||||||
# fmt('LCCN', unicode(self.lccn))
|
|
||||||
# if self.lcc:
|
|
||||||
# fmt('LCC', unicode(self.lcc))
|
|
||||||
# if self.ddc:
|
|
||||||
# fmt('DDC', unicode(self.ddc))
|
|
||||||
# CUSTFIELD: What to do about custom fields?
|
|
||||||
return u'\n'.join(ans)
|
return u'\n'.join(ans)
|
||||||
|
|
||||||
def to_html(self):
|
def to_html(self):
|
||||||
@ -339,13 +335,6 @@ class Metadata(object):
|
|||||||
ans += [(_('Producer'), unicode(self.book_producer))]
|
ans += [(_('Producer'), unicode(self.book_producer))]
|
||||||
ans += [(_('Comments'), unicode(self.comments))]
|
ans += [(_('Comments'), unicode(self.comments))]
|
||||||
ans += [('ISBN', unicode(self.isbn))]
|
ans += [('ISBN', unicode(self.isbn))]
|
||||||
# TODO: These are not in metadata. Should they be?
|
|
||||||
# if self.lccn:
|
|
||||||
# ans += [('LCCN', unicode(self.lccn))]
|
|
||||||
# if self.lcc:
|
|
||||||
# ans += [('LCC', unicode(self.lcc))]
|
|
||||||
# if self.ddc:
|
|
||||||
# ans += [('DDC', unicode(self.ddc))]
|
|
||||||
ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))]
|
ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))]
|
||||||
if self.series:
|
if self.series:
|
||||||
ans += [(_('Series'), unicode(self.series)+ ' #%s'%self.format_series_index())]
|
ans += [(_('Series'), unicode(self.series)+ ' #%s'%self.format_series_index())]
|
||||||
|
@ -1188,7 +1188,7 @@ def metadata_to_opf(mi, as_string=True):
|
|||||||
factory(DC('contributor'), mi.book_producer, __appname__, 'bkp')
|
factory(DC('contributor'), mi.book_producer, __appname__, 'bkp')
|
||||||
if hasattr(mi.pubdate, 'isoformat'):
|
if hasattr(mi.pubdate, 'isoformat'):
|
||||||
factory(DC('date'), isoformat(mi.pubdate))
|
factory(DC('date'), isoformat(mi.pubdate))
|
||||||
if mi.category:
|
if hasattr(mi, 'category') and mi.category:
|
||||||
factory(DC('type'), mi.category)
|
factory(DC('type'), mi.category)
|
||||||
if mi.comments:
|
if mi.comments:
|
||||||
factory(DC('description'), mi.comments)
|
factory(DC('description'), mi.comments)
|
||||||
|
@ -34,8 +34,8 @@ class SaveTemplate(QWidget, Ui_Form):
|
|||||||
self.option_name = name
|
self.option_name = name
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
# TODO: I haven't figured out how to get the custom columns into here,
|
# TODO: NEWMETA: I haven't figured out how to get the custom columns
|
||||||
# so for the moment make all templates valid.
|
# into here, so for the moment make all templates valid.
|
||||||
return True
|
return True
|
||||||
# tmpl = preprocess_template(self.opt_template.text())
|
# tmpl = preprocess_template(self.opt_template.text())
|
||||||
# fa = {}
|
# fa = {}
|
||||||
|
@ -131,7 +131,7 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250,
|
|||||||
format_args['series_index'] = mi.format_series_index()
|
format_args['series_index'] = mi.format_series_index()
|
||||||
else:
|
else:
|
||||||
template = re.sub(r'\{series_index[^}]*?\}', '', template)
|
template = re.sub(r'\{series_index[^}]*?\}', '', template)
|
||||||
## TODO: format custom values. Check all the datatypes.
|
## TODO: NEWMETA: format custom values. Check all the datatypes.
|
||||||
|
|
||||||
if mi.rating is not None:
|
if mi.rating is not None:
|
||||||
format_args['rating'] = mi.format_rating()
|
format_args['rating'] = mi.format_rating()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user