kopia lustrzana https://github.com/yt-dlp/yt-dlp
Fix beatport extractor
rodzic
7565fcb271
commit
a4d4809298
|
@ -2,7 +2,7 @@ import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_str
|
from ..compat import compat_str
|
||||||
from ..utils import int_or_none
|
from ..utils import int_or_none, ExtractorError
|
||||||
|
|
||||||
|
|
||||||
class BeatportIE(InfoExtractor):
|
class BeatportIE(InfoExtractor):
|
||||||
|
@ -43,55 +43,47 @@ class BeatportIE(InfoExtractor):
|
||||||
|
|
||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
|
||||||
playables = self._parse_json(
|
try:
|
||||||
self._search_regex(
|
playables_json = self._search_regex(
|
||||||
r'window\.Playables\s*=\s*({.+?});', webpage,
|
r'window\.Playables\s*=\s*({.+?})\s*;', webpage,
|
||||||
'playables info', flags=re.DOTALL),
|
'playables info', default='{}', flags=re.DOTALL)
|
||||||
track_id)
|
playables = self._parse_json(playables_json, track_id)
|
||||||
|
except re.error:
|
||||||
|
raise ExtractorError('Failed to extract playables information. The page structure may have changed.')
|
||||||
|
|
||||||
track = next(t for t in playables['tracks'] if t['id'] == int(track_id))
|
if not playables or 'tracks' not in playables:
|
||||||
|
raise ExtractorError('No playable tracks found in the extracted information.')
|
||||||
|
|
||||||
title = ', '.join((a['name'] for a in track['artists'])) + ' - ' + track['name']
|
track = next((t for t in playables['tracks'] if t['id'] == int(track_id)), None)
|
||||||
if track['mix']:
|
if not track:
|
||||||
|
raise ExtractorError(f'No track with ID {track_id} found.')
|
||||||
|
|
||||||
|
title = ', '.join(a['name'] for a in track['artists']) + ' - ' + track['name']
|
||||||
|
if track.get('mix'):
|
||||||
title += ' (' + track['mix'] + ')'
|
title += ' (' + track['mix'] + ')'
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for ext, info in track['preview'].items():
|
for ext, info in track.get('preview', {}).items():
|
||||||
if not info['url']:
|
url = info.get('url')
|
||||||
continue
|
if url:
|
||||||
fmt = {
|
fmt = {
|
||||||
'url': info['url'],
|
'url': url,
|
||||||
'ext': ext,
|
'ext': ext,
|
||||||
'format_id': ext,
|
'format_id': ext,
|
||||||
'vcodec': 'none',
|
'vcodec': 'none',
|
||||||
}
|
'acodec': 'mp3' if ext == 'mp3' else 'aac',
|
||||||
if ext == 'mp3':
|
'abr': 96,
|
||||||
fmt['acodec'] = 'mp3'
|
'asr': 44100
|
||||||
fmt['abr'] = 96
|
}
|
||||||
fmt['asr'] = 44100
|
formats.append(fmt)
|
||||||
elif ext == 'mp4':
|
|
||||||
fmt['acodec'] = 'aac'
|
|
||||||
fmt['abr'] = 96
|
|
||||||
fmt['asr'] = 44100
|
|
||||||
formats.append(fmt)
|
|
||||||
|
|
||||||
images = []
|
images = [{'id': name, 'url': info['url'], 'height': int_or_none(info.get('height')), 'width': int_or_none(info.get('width'))}
|
||||||
for name, info in track['images'].items():
|
for name, info in track.get('images', {}).items() if name != 'dynamic' and info.get('url')]
|
||||||
image_url = info.get('url')
|
|
||||||
if name == 'dynamic' or not image_url:
|
|
||||||
continue
|
|
||||||
image = {
|
|
||||||
'id': name,
|
|
||||||
'url': image_url,
|
|
||||||
'height': int_or_none(info.get('height')),
|
|
||||||
'width': int_or_none(info.get('width')),
|
|
||||||
}
|
|
||||||
images.append(image)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': compat_str(track.get('id')) or track_id,
|
'id': compat_str(track.get('id', track_id)),
|
||||||
'display_id': track.get('slug') or display_id,
|
'display_id': track.get('slug', display_id),
|
||||||
'title': title,
|
'title': title,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'thumbnails': images,
|
'thumbnails': images
|
||||||
}
|
}
|
Ładowanie…
Reference in New Issue