mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
9b11947989
commit
ec571a7a19
@ -15,6 +15,7 @@ from calibre.customize import Plugin
|
||||
from calibre.utils.logging import ThreadSafeLog, FileStream
|
||||
from calibre.utils.config import JSONConfig
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from calibre.ebooks.metadata import check_isbn
|
||||
|
||||
msprefs = JSONConfig('metadata_sources.json')
|
||||
|
||||
@ -236,6 +237,7 @@ class Source(Plugin):
|
||||
mi.title = fixcase(mi.title)
|
||||
mi.authors = list(map(fixcase, mi.authors))
|
||||
mi.tags = list(map(fixcase, mi.tags))
|
||||
mi.isbn = check_isbn(mi.isbn)
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -14,6 +14,7 @@ from io import BytesIO
|
||||
|
||||
from calibre.customize.ui import metadata_plugins
|
||||
from calibre.ebooks.metadata.sources.base import create_log
|
||||
from calibre.ebooks.metadata.xisbn import xisbn
|
||||
|
||||
# How long to wait for more results after first result is found
|
||||
WAIT_AFTER_FIRST_RESULT = 30 # seconds
|
||||
@ -120,7 +121,41 @@ def identify(log, abort, title=None, authors=None, identifiers=[], timeout=30):
|
||||
log('We have %d merged results, merging took: %.2f seconds' %
|
||||
(len(merged_results), time.time() - start_time))
|
||||
|
||||
class ISBNMerge(object):
|
||||
|
||||
def __init__(self):
|
||||
self.pools = {}
|
||||
|
||||
def isbn_in_pool(self, isbn):
|
||||
if isbn:
|
||||
for p in self.pools:
|
||||
if isbn in p:
|
||||
return p
|
||||
return None
|
||||
|
||||
def pool_has_result_from_same_source(self, pool, result):
|
||||
results = self.pools[pool][1]
|
||||
for r in results:
|
||||
if r.identify_plugin is result.identify_plugin:
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_result(self, result, isbn):
|
||||
pool = self.isbn_in_pool(isbn)
|
||||
if pool is None:
|
||||
isbns, min_year = xisbn.get_isbn_pool(isbn)
|
||||
if not isbns:
|
||||
isbns = frozenset([isbn])
|
||||
self.pool[isbns] = pool = (min_year, [])
|
||||
|
||||
if not self.pool_has_result_from_same_source(pool, result):
|
||||
pool[1].append(result)
|
||||
|
||||
def merge_identify_results(result_map, log):
|
||||
pass
|
||||
for plugin, results in result_map.iteritems():
|
||||
for result in results:
|
||||
isbn = result.isbn
|
||||
if isbn:
|
||||
isbns, min_year = xisbn.get_isbn_pool(isbn)
|
||||
|
||||
|
||||
|
@ -71,6 +71,20 @@ class xISBN(object):
|
||||
ans.add(i)
|
||||
return ans
|
||||
|
||||
def get_isbn_pool(self, isbn):
|
||||
data = self.get_data(isbn)
|
||||
isbns = frozenset([x.get('isbn') for x in data if 'isbn' in x])
|
||||
min_year = 100000
|
||||
for x in data:
|
||||
try:
|
||||
year = int(x['year'])
|
||||
if year < min_year:
|
||||
min_year = year
|
||||
except:
|
||||
continue
|
||||
if min_year == 100000:
|
||||
min_year = None
|
||||
return isbns, min_year
|
||||
|
||||
|
||||
xisbn = xISBN()
|
||||
|
Loading…
x
Reference in New Issue
Block a user