]>
Commit | Line | Data |
---|---|---|
11984c74 | 1 | import re |
11984c74 | 2 | |
517bcca2 | 3 | from .common import InfoExtractor |
fcd87701 | 4 | from ..compat import compat_str |
517bcca2 S |
5 | from ..utils import int_or_none |
6 | ||
11984c74 | 7 | |
ac943d48 DR |
8 | class BeatportIE(InfoExtractor): |
9 | _VALID_URL = r'https?://(?:www\.|pro\.)?beatport\.com/track/(?P<display_id>[^/]+)/(?P<id>[0-9]+)' | |
11984c74 | 10 | _TESTS = [{ |
ac943d48 | 11 | 'url': 'https://beatport.com/track/synesthesia-original-mix/5379371', |
11984c74 DP |
12 | 'md5': 'b3c34d8639a2f6a7f734382358478887', |
13 | 'info_dict': { | |
bba3fc79 S |
14 | 'id': '5379371', |
15 | 'display_id': 'synesthesia-original-mix', | |
11984c74 DP |
16 | 'ext': 'mp4', |
17 | 'title': 'Froxic - Synesthesia (Original Mix)', | |
18 | }, | |
19 | }, { | |
ac943d48 | 20 | 'url': 'https://beatport.com/track/love-and-war-original-mix/3756896', |
11984c74 DP |
21 | 'md5': 'e44c3025dfa38c6577fbaeb43da43514', |
22 | 'info_dict': { | |
bba3fc79 S |
23 | 'id': '3756896', |
24 | 'display_id': 'love-and-war-original-mix', | |
11984c74 DP |
25 | 'ext': 'mp3', |
26 | 'title': 'Wolfgang Gartner - Love & War (Original Mix)', | |
27 | }, | |
28 | }, { | |
ac943d48 | 29 | 'url': 'https://beatport.com/track/birds-original-mix/4991738', |
11984c74 DP |
30 | 'md5': 'a1fd8e8046de3950fd039304c186c05f', |
31 | 'info_dict': { | |
bba3fc79 S |
32 | 'id': '4991738', |
33 | 'display_id': 'birds-original-mix', | |
11984c74 DP |
34 | 'ext': 'mp4', |
35 | 'title': "Tos, Middle Milk, Mumblin' Johnsson - Birds (Original Mix)", | |
36 | } | |
37 | }] | |
38 | ||
39 | def _real_extract(self, url): | |
5ad28e7f | 40 | mobj = self._match_valid_url(url) |
ba1d4c04 S |
41 | track_id = mobj.group('id') |
42 | display_id = mobj.group('display_id') | |
43 | ||
44 | webpage = self._download_webpage(url, display_id) | |
11984c74 | 45 | |
fcd87701 S |
46 | playables = self._parse_json( |
47 | self._search_regex( | |
48 | r'window\.Playables\s*=\s*({.+?});', webpage, | |
49 | 'playables info', flags=re.DOTALL), | |
50 | track_id) | |
11984c74 | 51 | |
65c5e044 | 52 | track = next(t for t in playables['tracks'] if t['id'] == int(track_id)) |
11984c74 | 53 | |
11984c74 DP |
54 | title = ', '.join((a['name'] for a in track['artists'])) + ' - ' + track['name'] |
55 | if track['mix']: | |
56 | title += ' (' + track['mix'] + ')' | |
57 | ||
11984c74 DP |
58 | formats = [] |
59 | for ext, info in track['preview'].items(): | |
fcd87701 | 60 | if not info['url']: |
11984c74 DP |
61 | continue |
62 | fmt = { | |
63 | 'url': info['url'], | |
64 | 'ext': ext, | |
65 | 'format_id': ext, | |
66 | 'vcodec': 'none', | |
67 | } | |
68 | if ext == 'mp3': | |
11984c74 DP |
69 | fmt['acodec'] = 'mp3' |
70 | fmt['abr'] = 96 | |
71 | fmt['asr'] = 44100 | |
72 | elif ext == 'mp4': | |
11984c74 DP |
73 | fmt['acodec'] = 'aac' |
74 | fmt['abr'] = 96 | |
75 | fmt['asr'] = 44100 | |
517bcca2 | 76 | formats.append(fmt) |
1b537781 | 77 | self._sort_formats(formats) |
11984c74 | 78 | |
517bcca2 | 79 | images = [] |
11984c74 | 80 | for name, info in track['images'].items(): |
517bcca2 S |
81 | image_url = info.get('url') |
82 | if name == 'dynamic' or not image_url: | |
11984c74 | 83 | continue |
fcd87701 | 84 | image = { |
11984c74 | 85 | 'id': name, |
517bcca2 S |
86 | 'url': image_url, |
87 | 'height': int_or_none(info.get('height')), | |
88 | 'width': int_or_none(info.get('width')), | |
11984c74 | 89 | } |
fcd87701 | 90 | images.append(image) |
11984c74 DP |
91 | |
92 | return { | |
fcd87701 | 93 | 'id': compat_str(track.get('id')) or track_id, |
ba1d4c04 | 94 | 'display_id': track.get('slug') or display_id, |
11984c74 DP |
95 | 'title': title, |
96 | 'formats': formats, | |
517bcca2 | 97 | 'thumbnails': images, |
11984c74 | 98 | } |