From e937036ae43f402590225743f0a51982c7f80364 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 24 Jan 2009 13:34:49 -0500 Subject: [PATCH] Get metadata from filename based on standard format if no metadata can be or is retrieved from the file --- src/calibre/ebooks/metadata/meta.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/calibre/ebooks/metadata/meta.py b/src/calibre/ebooks/metadata/meta.py index f2c31a538d..a65d55a63d 100644 --- a/src/calibre/ebooks/metadata/meta.py +++ b/src/calibre/ebooks/metadata/meta.py @@ -72,6 +72,17 @@ def get_metadata(stream, stream_type='lrf', use_libprs_metadata=False): name = os.path.basename(getattr(stream, 'name', '')) base = metadata_from_filename(name) + if base.title == os.path.splitext(name)[0] and base.authors is None: + # Assume that there was no metadata in the file and the user set pattern + # to match meta info from the file name did not match. + # The regex is meant to match the standard format filenames are written + # in: title_-_author_number.extension + base.smart_update(metadata_from_filename(name, re.compile( + '^(?P[^\s]+?)_-_(?P<author>[^\s]+?)_+\d+'))) + if base.title: + base.title = base.title.replace('_', ' ') + if base.authors: + base.authors = [a.replace('_', ' ').strip() for a in base.authors] if not base.authors: base.authors = [_('Unknown')] if not base.title: