From 69fcac5b9d984ca4c2349413bec1711822e0d6e3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Jul 2014 11:58:26 +0530 Subject: [PATCH] Book details panel: Automatically convert ISSN identifiers into links to the periodicals page on worldcat.org. --- src/calibre/ebooks/metadata/__init__.py | 14 ++++++++++++++ src/calibre/ebooks/metadata/sources/identify.py | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 0f00ea7b24..427bb042e5 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -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: diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index c3d5dec420..c683d6289b 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -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'):