mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
EPUB2 metadata: Read ISBNs in identifier elements without schemes if they are valid ISBNs and no properly identified isbns are present
This commit is contained in:
parent
9562e85768
commit
1b03cd029a
@ -399,10 +399,13 @@ def check_isbn13(isbn):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def check_isbn(isbn):
|
def check_isbn(isbn, simple_sanitize=False):
|
||||||
if not isbn:
|
if not isbn:
|
||||||
return None
|
return None
|
||||||
isbn = re.sub(r'[^0-9X]', '', isbn.upper())
|
if simple_sanitize:
|
||||||
|
isbn = isbn.upper().replace('-', '').strip().replace(' ', '')
|
||||||
|
else:
|
||||||
|
isbn = re.sub(r'[^0-9X]', '', isbn.upper())
|
||||||
il = len(isbn)
|
il = len(isbn)
|
||||||
if il not in (10, 13):
|
if il not in (10, 13):
|
||||||
return None
|
return None
|
||||||
|
@ -971,6 +971,7 @@ class OPF(object): # {{{
|
|||||||
|
|
||||||
def get_identifiers(self):
|
def get_identifiers(self):
|
||||||
identifiers = {}
|
identifiers = {}
|
||||||
|
schemeless = []
|
||||||
for x in self.XPath(
|
for x in self.XPath(
|
||||||
'descendant::*[local-name() = "identifier" and text()]')(
|
'descendant::*[local-name() = "identifier" and text()]')(
|
||||||
self.metadata):
|
self.metadata):
|
||||||
@ -993,6 +994,15 @@ class OPF(object): # {{{
|
|||||||
val = check_isbn(val.split(':')[-1])
|
val = check_isbn(val.split(':')[-1])
|
||||||
if val is not None:
|
if val is not None:
|
||||||
identifiers['isbn'] = val
|
identifiers['isbn'] = val
|
||||||
|
else:
|
||||||
|
schemeless.append(val)
|
||||||
|
|
||||||
|
if schemeless and 'isbn' not in identifiers:
|
||||||
|
for val in schemeless:
|
||||||
|
if check_isbn(val, simple_sanitize=True) is not None:
|
||||||
|
identifiers['isbn'] = check_isbn(val)
|
||||||
|
break
|
||||||
|
|
||||||
return identifiers
|
return identifiers
|
||||||
|
|
||||||
def set_identifiers(self, identifiers):
|
def set_identifiers(self, identifiers):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user