mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow downloading metadata from amazon.co.jp. To use it, configure the amazon metadata source to use the Japanese amazon site. Fixes #842447 ([improvement]add support for Amazon Japan metadata download)
This commit is contained in:
parent
88187c98d3
commit
48363e9d69
Binary file not shown.
@ -8,7 +8,7 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
|
||||||
import os, shutil#, unittest
|
import os, shutil, unittest, tempfile
|
||||||
|
|
||||||
def create_db(library_path):
|
def create_db(library_path):
|
||||||
from calibre.library.database2 import LibraryDatabase2
|
from calibre.library.database2 import LibraryDatabase2
|
||||||
@ -17,5 +17,17 @@ def create_db(library_path):
|
|||||||
src = os.path.join(os.path.dirname(__file__), 'metadata.db')
|
src = os.path.join(os.path.dirname(__file__), 'metadata.db')
|
||||||
db = os.path.join(library_path, 'metadata.db')
|
db = os.path.join(library_path, 'metadata.db')
|
||||||
shutil.copyfile(src, db)
|
shutil.copyfile(src, db)
|
||||||
db = LibraryDatabase2(library_path)
|
return db
|
||||||
|
|
||||||
|
class ReadingTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.library_path = tempfile.mkdtemp()
|
||||||
|
create_db(self.library_path)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.library_path)
|
||||||
|
|
||||||
|
def test_read(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@ -74,6 +74,20 @@ class Worker(Thread): # Get details {{{
|
|||||||
9: ['sept'],
|
9: ['sept'],
|
||||||
12: ['déc'],
|
12: ['déc'],
|
||||||
},
|
},
|
||||||
|
'jp': {
|
||||||
|
1: [u'1月'],
|
||||||
|
2: [u'2月'],
|
||||||
|
3: [u'3月'],
|
||||||
|
4: [u'4月'],
|
||||||
|
5: [u'5月'],
|
||||||
|
6: [u'6月'],
|
||||||
|
7: [u'7月'],
|
||||||
|
8: [u'8月'],
|
||||||
|
9: [u'9月'],
|
||||||
|
10: [u'10月'],
|
||||||
|
11: [u'11月'],
|
||||||
|
12: [u'12月'],
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +100,15 @@ class Worker(Thread): # Get details {{{
|
|||||||
text()="Produktinformation" or \
|
text()="Produktinformation" or \
|
||||||
text()="Dettagli prodotto" or \
|
text()="Dettagli prodotto" or \
|
||||||
text()="Product details" or \
|
text()="Product details" or \
|
||||||
text()="Détails sur le produit"]/../div[@class="content"]
|
text()="Détails sur le produit" or \
|
||||||
|
text()="登録情報"]/../div[@class="content"]
|
||||||
'''
|
'''
|
||||||
self.publisher_xpath = '''
|
self.publisher_xpath = '''
|
||||||
descendant::*[starts-with(text(), "Publisher:") or \
|
descendant::*[starts-with(text(), "Publisher:") or \
|
||||||
starts-with(text(), "Verlag:") or \
|
starts-with(text(), "Verlag:") or \
|
||||||
starts-with(text(), "Editore:") or \
|
starts-with(text(), "Editore:") or \
|
||||||
starts-with(text(), "Editeur")]
|
starts-with(text(), "Editeur") or \
|
||||||
|
starts-with(text(), "出版社:")]
|
||||||
'''
|
'''
|
||||||
self.language_xpath = '''
|
self.language_xpath = '''
|
||||||
descendant::*[
|
descendant::*[
|
||||||
@ -101,10 +117,11 @@ class Worker(Thread): # Get details {{{
|
|||||||
or text() = "Sprache:" \
|
or text() = "Sprache:" \
|
||||||
or text() = "Lingua:" \
|
or text() = "Lingua:" \
|
||||||
or starts-with(text(), "Langue") \
|
or starts-with(text(), "Langue") \
|
||||||
|
or starts-with(text(), "言語") \
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
self.ratings_pat = re.compile(
|
self.ratings_pat = re.compile(
|
||||||
r'([0-9.]+) (out of|von|su|étoiles sur) (\d+)( (stars|Sternen|stelle)){0,1}')
|
r'([0-9.]+) ?(out of|von|su|étoiles sur|つ星のうち) ([\d\.]+)( (stars|Sternen|stelle)){0,1}')
|
||||||
|
|
||||||
lm = {
|
lm = {
|
||||||
'eng': ('English', 'Englisch'),
|
'eng': ('English', 'Englisch'),
|
||||||
@ -112,6 +129,7 @@ class Worker(Thread): # Get details {{{
|
|||||||
'ita': ('Italian', 'Italiano'),
|
'ita': ('Italian', 'Italiano'),
|
||||||
'deu': ('German', 'Deutsch'),
|
'deu': ('German', 'Deutsch'),
|
||||||
'spa': ('Spanish', 'Espa\xf1ol', 'Espaniol'),
|
'spa': ('Spanish', 'Espa\xf1ol', 'Espaniol'),
|
||||||
|
'jpn': ('Japanese', u'日本語'),
|
||||||
}
|
}
|
||||||
self.lang_map = {}
|
self.lang_map = {}
|
||||||
for code, names in lm.iteritems():
|
for code, names in lm.iteritems():
|
||||||
@ -403,6 +421,7 @@ class Amazon(Source):
|
|||||||
'de' : _('Germany'),
|
'de' : _('Germany'),
|
||||||
'uk' : _('UK'),
|
'uk' : _('UK'),
|
||||||
'it' : _('Italy'),
|
'it' : _('Italy'),
|
||||||
|
'jp' : _('Japan'),
|
||||||
}
|
}
|
||||||
|
|
||||||
options = (
|
options = (
|
||||||
@ -411,6 +430,22 @@ class Amazon(Source):
|
|||||||
'country\'s Amazon website.'), choices=AMAZON_DOMAINS),
|
'country\'s Amazon website.'), choices=AMAZON_DOMAINS),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
Source.__init__(self, *args, **kwargs)
|
||||||
|
self.set_amazon_id_touched_fields()
|
||||||
|
|
||||||
|
def save_settings(self, *args, **kwargs):
|
||||||
|
Source.save_settings(self, *args, **kwargs)
|
||||||
|
self.set_amazon_id_touched_fields()
|
||||||
|
|
||||||
|
def set_amazon_id_touched_fields(self):
|
||||||
|
ident_name = "identifier:amazon"
|
||||||
|
if self.domain != 'com':
|
||||||
|
ident_name += '_' + self.domain
|
||||||
|
tf = [x for x in self.touched_fields if not
|
||||||
|
x.startswith('identifier:amazon')] + [ident_name]
|
||||||
|
self.touched_fields = frozenset(tf)
|
||||||
|
|
||||||
def get_domain_and_asin(self, identifiers):
|
def get_domain_and_asin(self, identifiers):
|
||||||
for key, val in identifiers.iteritems():
|
for key, val in identifiers.iteritems():
|
||||||
key = key.lower()
|
key = key.lower()
|
||||||
@ -488,13 +523,23 @@ class Amazon(Source):
|
|||||||
# Insufficient metadata to make an identify query
|
# Insufficient metadata to make an identify query
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
latin1q = dict([(x.encode('latin1', 'ignore'), y.encode('latin1',
|
# magic parameter to enable Japanese Shift_JIS encoding.
|
||||||
|
if domain == 'jp':
|
||||||
|
q['__mk_ja_JP'] = u'カタカナ'
|
||||||
|
|
||||||
|
if domain == 'jp':
|
||||||
|
encode_to = 'Shift_JIS'
|
||||||
|
else:
|
||||||
|
encode_to = 'latin1'
|
||||||
|
encoded_q = dict([(x.encode(encode_to, 'ignore'), y.encode(encode_to,
|
||||||
'ignore')) for x, y in
|
'ignore')) for x, y in
|
||||||
q.iteritems()])
|
q.iteritems()])
|
||||||
udomain = domain
|
udomain = domain
|
||||||
if domain == 'uk':
|
if domain == 'uk':
|
||||||
udomain = 'co.uk'
|
udomain = 'co.uk'
|
||||||
url = 'http://www.amazon.%s/s/?'%udomain + urlencode(latin1q)
|
elif domain == 'jp':
|
||||||
|
udomain = 'co.jp'
|
||||||
|
url = 'http://www.amazon.%s/s/?'%udomain + urlencode(encoded_q)
|
||||||
return url, domain
|
return url, domain
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
@ -663,7 +708,7 @@ if __name__ == '__main__': # tests {{{
|
|||||||
# To run these test use: calibre-debug -e
|
# To run these test use: calibre-debug -e
|
||||||
# src/calibre/ebooks/metadata/sources/amazon.py
|
# src/calibre/ebooks/metadata/sources/amazon.py
|
||||||
from calibre.ebooks.metadata.sources.test import (test_identify_plugin,
|
from calibre.ebooks.metadata.sources.test import (test_identify_plugin,
|
||||||
title_test, authors_test)
|
isbn_test, title_test, authors_test)
|
||||||
com_tests = [ # {{{
|
com_tests = [ # {{{
|
||||||
|
|
||||||
( # Description has links
|
( # Description has links
|
||||||
@ -744,6 +789,21 @@ if __name__ == '__main__': # tests {{{
|
|||||||
),
|
),
|
||||||
] # }}}
|
] # }}}
|
||||||
|
|
||||||
|
jp_tests = [ # {{{
|
||||||
|
( # isbn -> title, authors
|
||||||
|
{'identifiers':{'isbn': '9784101302720' }},
|
||||||
|
[title_test(u'精霊の守り人',
|
||||||
|
exact=True), authors_test([u'上橋 菜穂子'])
|
||||||
|
]
|
||||||
|
),
|
||||||
|
( # title, authors -> isbn (will use Shift_JIS encoding in query.)
|
||||||
|
{'title': u'考えない練習',
|
||||||
|
'authors': [u'小池 龍之介']},
|
||||||
|
[isbn_test('9784093881067'), ]
|
||||||
|
),
|
||||||
|
] # }}}
|
||||||
|
|
||||||
test_identify_plugin(Amazon.name, com_tests)
|
test_identify_plugin(Amazon.name, com_tests)
|
||||||
|
#test_identify_plugin(Amazon.name, jp_tests)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user