]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/audioboom.py
Prepare to upload.
[youtubedl] / youtube_dl / extractor / audioboom.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import float_or_none
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/boos/4279833-3-09-2016-czaban-hour-3?t=0',
12 'md5': '63a8d73a055c6ed0f1e51921a10a5a76',
13 'info_dict': {
14 'id': '4279833',
15 'ext': 'mp3',
16 'title': '3/09/2016 Czaban Hour 3',
17 'description': 'Guest: Nate Davis - NFL free agency, Guest: Stan Gans',
18 'duration': 2245.72,
19 'uploader': 'SB Nation A.M.',
20 'uploader_url': r're:https?://(?:www\.)?audioboom\.com/channel/steveczabanyahoosportsradio',
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._search_regex(
36 r'data-new-clip-store=(["\'])(?P<json>{.*?"clipId"\s*:\s*%s.*?})\1' % video_id,
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._og_search_title(webpage)
51 description = from_clip('description') or self._og_search_description(webpage)
52
53 duration = float_or_none(from_clip('duration') or self._html_search_meta(
54 'weibo:audio:duration', webpage))
55
56 uploader = from_clip('author') or self._og_search_property(
57 'audio:artist', webpage, 'uploader', fatal=False)
58 uploader_url = from_clip('author_url') or self._html_search_meta(
59 'audioboo:channel', webpage, 'uploader url')
60
61 return {
62 'id': video_id,
63 'url': audio_url,
64 'title': title,
65 'description': description,
66 'duration': duration,
67 'uploader': uploader,
68 'uploader_url': uploader_url,
69 }