From fd61b97f067505234f796b22cfd431a8cb89155c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Mar 2011 19:40:50 -0600 Subject: [PATCH] EPUB metadata: Read ISBN from Penguin epubs that dont correctly specify it --- src/calibre/ebooks/metadata/opf2.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 846fdf1322..6af4f79cbb 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -16,7 +16,7 @@ from lxml import etree from calibre.ebooks.chardet import xml_to_unicode from calibre.constants import __appname__, __version__, filesystem_encoding from calibre.ebooks.metadata.toc import TOC -from calibre.ebooks.metadata import string_to_authors, MetaInformation +from calibre.ebooks.metadata import string_to_authors, MetaInformation, check_isbn from calibre.ebooks.metadata.book.base import Metadata from calibre.utils.date import parse_date, isoformat from calibre.utils.localization import get_lang @@ -863,6 +863,7 @@ class OPF(object): # {{{ for x in self.XPath( 'descendant::*[local-name() = "identifier" and text()]')( self.metadata): + found_scheme = False for attr, val in x.attrib.iteritems(): if attr.endswith('scheme'): typ = icu_lower(val) @@ -870,7 +871,15 @@ class OPF(object): # {{{ method='text').strip() if val and typ not in ('calibre', 'uuid'): identifiers[typ] = val + found_scheme = True break + if not found_scheme: + val = etree.tostring(x, with_tail=False, encoding=unicode, + method='text').strip() + if val.lower().startswith('urn:isbn:'): + val = check_isbn(val.split(':')[-1]) + if val is not None: + identifiers['isbn'] = val return identifiers @dynamic_property