mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Book details panel: Automatically convert ISSN identifiers into links to the periodicals page on worldcat.org.
This commit is contained in:
parent
6320eab8e8
commit
69fcac5b9d
@ -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:
|
||||
|
@ -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'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user