]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rbmaradio.py
[youtube] Prefer UTC upload date for videos (#2223)
[yt-dlp.git] / yt_dlp / extractor / rbmaradio.py
1 from __future__ import unicode_literals
2
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7 clean_html,
8 int_or_none,
9 unified_timestamp,
10 update_url_query,
11 )
12
13
14 class RBMARadioIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?(?:rbmaradio|redbullradio)\.com/shows/(?P<show_id>[^/]+)/episodes/(?P<id>[^/?#&]+)'
16 _TEST = {
17 'url': 'https://www.rbmaradio.com/shows/main-stage/episodes/ford-lopatin-live-at-primavera-sound-2011',
18 'md5': '6bc6f9bcb18994b4c983bc3bf4384d95',
19 'info_dict': {
20 'id': 'ford-lopatin-live-at-primavera-sound-2011',
21 'ext': 'mp3',
22 'title': 'Main Stage - Ford & Lopatin at Primavera Sound',
23 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
24 'thumbnail': r're:^https?://.*\.jpg',
25 'duration': 2452,
26 'timestamp': 1307103164,
27 'upload_date': '20110603',
28 },
29 }
30
31 def _real_extract(self, url):
32 mobj = self._match_valid_url(url)
33 show_id = mobj.group('show_id')
34 episode_id = mobj.group('id')
35
36 webpage = self._download_webpage(url, episode_id)
37
38 episode = self._parse_json(
39 self._search_regex(
40 r'__INITIAL_STATE__\s*=\s*({.+?})\s*</script>',
41 webpage, 'json data'),
42 episode_id)['episodes'][show_id][episode_id]
43
44 title = episode['title']
45
46 show_title = episode.get('showTitle')
47 if show_title:
48 title = '%s - %s' % (show_title, title)
49
50 formats = [{
51 'url': update_url_query(episode['audioURL'], query={'cbr': abr}),
52 'format_id': compat_str(abr),
53 'abr': abr,
54 'vcodec': 'none',
55 } for abr in (96, 128, 192, 256)]
56 self._check_formats(formats, episode_id)
57
58 description = clean_html(episode.get('longTeaser'))
59 thumbnail = self._proto_relative_url(episode.get('imageURL', {}).get('landscape'))
60 duration = int_or_none(episode.get('duration'))
61 timestamp = unified_timestamp(episode.get('publishedAt'))
62
63 return {
64 'id': episode_id,
65 'title': title,
66 'description': description,
67 'thumbnail': thumbnail,
68 'duration': duration,
69 'timestamp': timestamp,
70 'formats': formats,
71 }