]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/audioboom.py
[VideocampusSachsen] Improve extractor (#3604)
[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 )
6
7
8 class AudioBoomIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?audioboom\.com/(?:boos|posts)/(?P<id>[0-9]+)'
10 _TESTS = [{
11 'url': 'https://audioboom.com/posts/7398103-asim-chaudhry',
12 'md5': '7b00192e593ff227e6a315486979a42d',
13 'info_dict': {
14 'id': '7398103',
15 'ext': 'mp3',
16 'title': 'Asim Chaudhry',
17 'description': 'md5:2f3fef17dacc2595b5362e1d7d3602fc',
18 'duration': 4000.99,
19 'uploader': 'Sue Perkins: An hour or so with...',
20 'uploader_url': r're:https?://(?:www\.)?audioboom\.com/channel/perkins',
21 }
22 }, {
23 'url': 'https://audioboom.com/posts/4279833-3-09-2016-czaban-hour-3?t=0',
24 'only_matching': True,
25 }]
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29
30 webpage = self._download_webpage(url, video_id)
31
32 clip = None
33
34 clip_store = self._parse_json(
35 self._html_search_regex(
36 r'data-new-clip-store=(["\'])(?P<json>{.+?})\1',
37 webpage, 'clip store', default='{}', group='json'),
38 video_id, fatal=False)
39 if clip_store:
40 clips = clip_store.get('clips')
41 if clips and isinstance(clips, list) and isinstance(clips[0], dict):
42 clip = clips[0]
43
44 def from_clip(field):
45 if clip:
46 return clip.get(field)
47
48 audio_url = from_clip('clipURLPriorToLoading') or self._og_search_property(
49 'audio', webpage, 'audio url')
50 title = from_clip('title') or self._html_search_meta(
51 ['og:title', 'og:audio:title', 'audio_title'], webpage)
52 description = from_clip('description') or clean_html(from_clip('formattedDescription')) or self._og_search_description(webpage)
53
54 duration = float_or_none(from_clip('duration') or self._html_search_meta(
55 'weibo:audio:duration', webpage))
56
57 uploader = from_clip('author') or self._html_search_meta(
58 ['og:audio:artist', 'twitter:audio:artist_name', 'audio_artist'], webpage, 'uploader')
59 uploader_url = from_clip('author_url') or self._html_search_meta(
60 'audioboo:channel', webpage, 'uploader url')
61
62 return {
63 'id': video_id,
64 'url': audio_url,
65 'title': title,
66 'description': description,
67 'duration': duration,
68 'uploader': uploader,
69 'uploader_url': uploader_url,
70 }