mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update amazon metadata plugin for change in amazon.de markup. Fixes #1869369 [Ratings at amazon.de at meta query are not saved.](https://bugs.launchpad.net/calibre/+bug/1869369)
This commit is contained in:
parent
b45163f59e
commit
dd2d98b187
@ -289,7 +289,7 @@ class Worker(Thread): # Get details {{{
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
self.ratings_pat = re.compile(
|
self.ratings_pat = re.compile(
|
||||||
r'([0-9.]+) ?(out of|von|van|su|étoiles sur|つ星のうち|de un máximo de|de) ([\d\.]+)( (stars|Sternen|stelle|estrellas|estrelas|sterren)){0,1}')
|
r'([0-9.,]+) ?(out of|von|van|su|étoiles sur|つ星のうち|de un máximo de|de) ([\d\.]+)( (stars|Sternen|stelle|estrellas|estrelas|sterren)){0,1}')
|
||||||
self.ratings_pat_cn = re.compile('平均([0-9.]+)')
|
self.ratings_pat_cn = re.compile('平均([0-9.]+)')
|
||||||
|
|
||||||
lm = {
|
lm = {
|
||||||
@ -540,26 +540,43 @@ class Worker(Thread): # Get details {{{
|
|||||||
# ratings matches
|
# ratings matches
|
||||||
x.getparent().remove(x)
|
x.getparent().remove(x)
|
||||||
|
|
||||||
rating_paths = ('//div[@data-feature-name="averageCustomerReviews" or @id="averageCustomerReviews"]',
|
rating_paths = (
|
||||||
'//div[@class="jumpBar"]/descendant::span[contains(@class,"asinReviewsSummary")]',
|
'//div[@data-feature-name="averageCustomerReviews" or @id="averageCustomerReviews"]',
|
||||||
'//div[@class="buying"]/descendant::span[contains(@class,"asinReviewsSummary")]',
|
'//div[@class="jumpBar"]/descendant::span[contains(@class,"asinReviewsSummary")]',
|
||||||
'//span[@class="crAvgStars"]/descendant::span[contains(@class,"asinReviewsSummary")]')
|
'//div[@class="buying"]/descendant::span[contains(@class,"asinReviewsSummary")]',
|
||||||
|
'//span[@class="crAvgStars"]/descendant::span[contains(@class,"asinReviewsSummary")]'
|
||||||
|
)
|
||||||
ratings = None
|
ratings = None
|
||||||
for p in rating_paths:
|
for p in rating_paths:
|
||||||
ratings = root.xpath(p)
|
ratings = root.xpath(p)
|
||||||
if ratings:
|
if ratings:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def parse_ratings_text(text):
|
||||||
|
try:
|
||||||
|
m = self.ratings_pat.match(text)
|
||||||
|
return float(m.group(1).replace(',', '.')) / float(m.group(3)) * 5
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
if ratings:
|
if ratings:
|
||||||
for elem in ratings[0].xpath('descendant::*[@title]'):
|
ratings = ratings[0]
|
||||||
|
for elem in ratings.xpath('descendant::*[@title]'):
|
||||||
t = elem.get('title').strip()
|
t = elem.get('title').strip()
|
||||||
if self.domain == 'cn':
|
if self.domain == 'cn':
|
||||||
m = self.ratings_pat_cn.match(t)
|
m = self.ratings_pat_cn.match(t)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
return float(m.group(1))
|
return float(m.group(1))
|
||||||
else:
|
else:
|
||||||
m = self.ratings_pat.match(t)
|
ans = parse_ratings_text(t)
|
||||||
if m is not None:
|
if ans is not None:
|
||||||
return float(m.group(1)) / float(m.group(3)) * 5
|
return ans
|
||||||
|
for elem in ratings.xpath('descendant::span[@class="a-icon-alt"]'):
|
||||||
|
t = self.tostring(
|
||||||
|
elem, encoding='unicode', method='text', with_tail=False).strip()
|
||||||
|
ans = parse_ratings_text(t)
|
||||||
|
if ans is not None:
|
||||||
|
return ans
|
||||||
|
|
||||||
def _render_comments(self, desc):
|
def _render_comments(self, desc):
|
||||||
from calibre.library.comments import sanitize_comments_html
|
from calibre.library.comments import sanitize_comments_html
|
||||||
@ -878,7 +895,7 @@ class Worker(Thread): # Get details {{{
|
|||||||
class Amazon(Source):
|
class Amazon(Source):
|
||||||
|
|
||||||
name = 'Amazon.com'
|
name = 'Amazon.com'
|
||||||
version = (1, 2, 11)
|
version = (1, 2, 12)
|
||||||
minimum_calibre_version = (2, 82, 0)
|
minimum_calibre_version = (2, 82, 0)
|
||||||
description = _('Downloads metadata and covers from Amazon')
|
description = _('Downloads metadata and covers from Amazon')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user