]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/audioboom.py
[extractor/audioboom] Support direct URLs and refactor (#4803)
[yt-dlp.git] / yt_dlp / extractor / audioboom.py
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 float_or_none,
5 unescapeHTML,
6 traverse_obj,
7 )
8
9
10 class AudioBoomIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?audioboom\.com/(?:boos|posts)/(?P<id>[0-9]+)'
12 _TESTS = [{
13 'url': 'https://audioboom.com/posts/7398103-asim-chaudhry',
14 'md5': '4d68be11c9f9daf3dab0778ad1e010c3',
15 'info_dict': {
16 'id': '7398103',
17 'ext': 'mp3',
18 'title': 'Asim Chaudhry',
19 'description': 'md5:0ed714ae0e81e5d9119cac2f618ad679',
20 'duration': 4000.99,
21 'uploader': 'Sue Perkins: An hour or so with...',
22 'uploader_url': r're:https?://(?:www\.)?audioboom\.com/channel/perkins',
23 }
24 }, { # Direct mp3-file link
25 'url': 'https://audioboom.com/posts/8128496.mp3',
26 'md5': 'e329edf304d450def95c7f86a9165ee1',
27 'info_dict': {
28 'id': '8128496',
29 'ext': 'mp3',
30 'title': 'TCRNo8 / DAILY 03 - In Control',
31 'description': 'md5:44665f142db74858dfa21c5b34787948',
32 'duration': 1689.7,
33 'uploader': 'Lost Dot Podcast: The Trans Pyrenees and Transcontinental Race',
34 'uploader_url': r're:https?://(?:www\.)?audioboom\.com/channels/5003904',
35 }
36 }, {
37 'url': 'https://audioboom.com/posts/4279833-3-09-2016-czaban-hour-3?t=0',
38 'only_matching': True,
39 }]
40
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
43 webpage = self._download_webpage(f'https://audioboom.com/posts/{video_id}', video_id)
44
45 clip_store = self._search_json(
46 r'data-react-class="V5DetailPagePlayer"\s*data-react-props=["\']',
47 webpage, 'clip store', video_id, fatal=False, transform_source=unescapeHTML)
48 clip = traverse_obj(clip_store, ('clips', 0), expected_type=dict) or {}
49
50 return {
51 'id': video_id,
52 'url': clip.get('clipURLPriorToLoading') or self._og_search_property('audio', webpage, 'audio url'),
53 'title': clip.get('title') or self._html_search_meta(['og:title', 'og:audio:title', 'audio_title'], webpage),
54 'description': (clip.get('description') or clean_html(clip.get('formattedDescription'))
55 or self._og_search_description(webpage)),
56 'duration': float_or_none(clip.get('duration') or self._html_search_meta('weibo:audio:duration', webpage)),
57 'uploader': clip.get('author') or self._html_search_meta(
58 ['og:audio:artist', 'twitter:audio:artist_name', 'audio_artist'], webpage, 'uploader'),
59 'uploader_url': clip.get('author_url') or self._html_search_regex(
60 r'<div class="avatar flex-shrink-0">\s*<a href="(?P<uploader_url>http[^"]+)"',
61 webpage, 'uploader url', fatal=False),
62 }