[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / beatport.py
blobacc8d125950fee669a1b220c6868c6c42450f30d
1 import re
3 from .common import InfoExtractor
4 from ..utils import int_or_none
7 class BeatportIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.|pro\.)?beatport\.com/track/(?P<display_id>[^/]+)/(?P<id>[0-9]+)'
9 _TESTS = [{
10 'url': 'https://beatport.com/track/synesthesia-original-mix/5379371',
11 'md5': 'b3c34d8639a2f6a7f734382358478887',
12 'info_dict': {
13 'id': '5379371',
14 'display_id': 'synesthesia-original-mix',
15 'ext': 'mp4',
16 'title': 'Froxic - Synesthesia (Original Mix)',
18 }, {
19 'url': 'https://beatport.com/track/love-and-war-original-mix/3756896',
20 'md5': 'e44c3025dfa38c6577fbaeb43da43514',
21 'info_dict': {
22 'id': '3756896',
23 'display_id': 'love-and-war-original-mix',
24 'ext': 'mp3',
25 'title': 'Wolfgang Gartner - Love & War (Original Mix)',
27 }, {
28 'url': 'https://beatport.com/track/birds-original-mix/4991738',
29 'md5': 'a1fd8e8046de3950fd039304c186c05f',
30 'info_dict': {
31 'id': '4991738',
32 'display_id': 'birds-original-mix',
33 'ext': 'mp4',
34 'title': "Tos, Middle Milk, Mumblin' Johnsson - Birds (Original Mix)",
38 def _real_extract(self, url):
39 mobj = self._match_valid_url(url)
40 track_id = mobj.group('id')
41 display_id = mobj.group('display_id')
43 webpage = self._download_webpage(url, display_id)
45 playables = self._parse_json(
46 self._search_regex(
47 r'window\.Playables\s*=\s*({.+?});', webpage,
48 'playables info', flags=re.DOTALL),
49 track_id)
51 track = next(t for t in playables['tracks'] if t['id'] == int(track_id))
53 title = ', '.join(a['name'] for a in track['artists']) + ' - ' + track['name']
54 if track['mix']:
55 title += ' (' + track['mix'] + ')'
57 formats = []
58 for ext, info in track['preview'].items():
59 if not info['url']:
60 continue
61 fmt = {
62 'url': info['url'],
63 'ext': ext,
64 'format_id': ext,
65 'vcodec': 'none',
67 if ext == 'mp3':
68 fmt['acodec'] = 'mp3'
69 fmt['abr'] = 96
70 fmt['asr'] = 44100
71 elif ext == 'mp4':
72 fmt['acodec'] = 'aac'
73 fmt['abr'] = 96
74 fmt['asr'] = 44100
75 formats.append(fmt)
77 images = []
78 for name, info in track['images'].items():
79 image_url = info.get('url')
80 if name == 'dynamic' or not image_url:
81 continue
82 image = {
83 'id': name,
84 'url': image_url,
85 'height': int_or_none(info.get('height')),
86 'width': int_or_none(info.get('width')),
88 images.append(image)
90 return {
91 'id': str(track.get('id')) or track_id,
92 'display_id': track.get('slug') or display_id,
93 'title': title,
94 'formats': formats,
95 'thumbnails': images,