Book details panel: Automatically convert ISSN identifiers into links to the periodicals page on worldcat.org.

This commit is contained in:
Kovid Goyal 2014-07-23 11:58:26 +05:30
parent 6320eab8e8
commit 69fcac5b9d
2 changed files with 19 additions and 0 deletions

View File

@ -360,6 +360,20 @@ def check_isbn(isbn):
return check_isbn13(isbn)
return None
def check_issn(issn):
if not issn:
return None
issn = re.sub(r'[^0-9X]', '', issn.upper())
try:
digits = map(int, issn[:7])
products = [(8 - i) * d for i, d in enumerate(digits)]
check = 11 - sum(products) % 11
if (check == 10 and issn[7] == 'X') or check == int(issn[7]):
return issn
except Exception:
pass
return None
def format_isbn(isbn):
cisbn = check_isbn(isbn)
if not cisbn:

View File

@ -16,6 +16,7 @@ from operator import attrgetter
from urlparse import urlparse
from calibre.customize.ui import metadata_plugins, all_metadata_plugins
from calibre.ebooks.metadata import check_issn
from calibre.ebooks.metadata.sources.base import create_log
from calibre.ebooks.metadata.sources.prefs import msprefs
from calibre.ebooks.metadata.xisbn import xisbn
@ -537,6 +538,10 @@ def urls_from_identifiers(identifiers): # {{{
if oclc:
ans.append(('OCLC', 'oclc', oclc,
'http://www.worldcat.org/oclc/'+oclc))
issn = check_issn(identifiers.get('issn', None))
if issn:
ans.append((issn, 'issn', issn,
'http://www.worldcat.org/issn/'+issn))
for x in ('uri', 'url'):
url = identifiers.get(x, None)
if url and url.startswith('http'):