]>
Commit | Line | Data |
---|---|---|
3c4eebf7 | 1 | from .common import InfoExtractor |
3c7a2762 | 2 | from ..utils import ExtractorError, int_or_none |
3c4eebf7 | 3 | |
4 | ||
5 | class AmazonStoreIE(InfoExtractor): | |
73f035e1 | 6 | _VALID_URL = r'https?://(?:www\.)?amazon\.(?:[a-z]{2,3})(?:\.[a-z]{2})?/(?:[^/]+/)?(?:dp|gp/product)/(?P<id>[^/&#$?]+)' |
3c4eebf7 | 7 | |
8 | _TESTS = [{ | |
9 | 'url': 'https://www.amazon.co.uk/dp/B098XNCHLD/', | |
10 | 'info_dict': { | |
11 | 'id': 'B098XNCHLD', | |
7474e453 | 12 | 'title': 'md5:dae240564cbb2642170c02f7f0d7e472', |
3c4eebf7 | 13 | }, |
14 | 'playlist_mincount': 1, | |
15 | 'playlist': [{ | |
16 | 'info_dict': { | |
17 | 'id': 'A1F83G8C2ARO7P', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'mcdodo usb c cable 100W 5a', | |
20 | 'thumbnail': r're:^https?://.*\.jpg$', | |
7474e453 | 21 | 'duration': 34, |
3c4eebf7 | 22 | }, |
23 | }] | |
24 | }, { | |
25 | 'url': 'https://www.amazon.in/Sony-WH-1000XM4-Cancelling-Headphones-Bluetooth/dp/B0863TXGM3', | |
26 | 'info_dict': { | |
27 | 'id': 'B0863TXGM3', | |
7474e453 | 28 | 'title': 'md5:d1d3352428f8f015706c84b31e132169', |
3c4eebf7 | 29 | }, |
30 | 'playlist_mincount': 4, | |
31 | }, { | |
32 | 'url': 'https://www.amazon.com/dp/B0845NXCXF/', | |
33 | 'info_dict': { | |
34 | 'id': 'B0845NXCXF', | |
7474e453 | 35 | 'title': 'md5:f3fa12779bf62ddb6a6ec86a360a858e', |
3c4eebf7 | 36 | }, |
37 | 'playlist-mincount': 1, | |
7474e453 | 38 | }, { |
39 | 'url': 'https://www.amazon.es/Samsung-Smartphone-s-AMOLED-Quad-c%C3%A1mara-espa%C3%B1ola/dp/B08WX337PQ', | |
40 | 'info_dict': { | |
41 | 'id': 'B08WX337PQ', | |
42 | 'title': 'md5:f3fa12779bf62ddb6a6ec86a360a858e', | |
43 | }, | |
44 | 'playlist_mincount': 1, | |
3c4eebf7 | 45 | }] |
46 | ||
47 | def _real_extract(self, url): | |
48 | id = self._match_id(url) | |
3c7a2762 | 49 | |
8ca48a1a | 50 | for retry in self.RetryManager(): |
3c7a2762 L |
51 | webpage = self._download_webpage(url, id) |
52 | try: | |
7474e453 | 53 | data_json = self._search_json( |
54 | r'var\s?obj\s?=\s?jQuery\.parseJSON\(\'', webpage, 'data', id, | |
55 | transform_source=lambda x: x.replace(R'\\u', R'\u')) | |
3c7a2762 L |
56 | except ExtractorError as e: |
57 | retry.error = e | |
58 | ||
3c4eebf7 | 59 | entries = [{ |
60 | 'id': video['marketPlaceID'], | |
61 | 'url': video['url'], | |
62 | 'title': video.get('title'), | |
63 | 'thumbnail': video.get('thumbUrl') or video.get('thumb'), | |
64 | 'duration': video.get('durationSeconds'), | |
65 | 'height': int_or_none(video.get('videoHeight')), | |
66 | 'width': int_or_none(video.get('videoWidth')), | |
67 | } for video in (data_json.get('videos') or []) if video.get('isVideo') and video.get('url')] | |
7474e453 | 68 | return self.playlist_result(entries, playlist_id=id, playlist_title=data_json.get('title')) |