]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rozhlas.py
[extractor/generic] Detect manifest links via extension
[yt-dlp.git] / yt_dlp / extractor / rozhlas.py
1 from .common import InfoExtractor
2 from ..utils import extract_attributes, int_or_none, remove_start, traverse_obj
3
4
5 class RozhlasIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?prehravac\.rozhlas\.cz/audio/(?P<id>[0-9]+)'
7 _TESTS = [{
8 'url': 'http://prehravac.rozhlas.cz/audio/3421320',
9 'md5': '504c902dbc9e9a1fd50326eccf02a7e2',
10 'info_dict': {
11 'id': '3421320',
12 'ext': 'mp3',
13 'title': 'Echo Pavla Klusáka (30.06.2015 21:00)',
14 'description': 'Osmdesátiny Terryho Rileyho jsou skvělou příležitostí proletět se elektronickými i akustickými díly zakladatatele minimalismu, který je aktivní už přes padesát let'
15 }
16 }, {
17 'url': 'http://prehravac.rozhlas.cz/audio/3421320/embed',
18 'only_matching': True,
19 }]
20
21 def _real_extract(self, url):
22 audio_id = self._match_id(url)
23
24 webpage = self._download_webpage(
25 'http://prehravac.rozhlas.cz/audio/%s' % audio_id, audio_id)
26
27 title = self._html_search_regex(
28 r'<h3>(.+?)</h3>\s*<p[^>]*>.*?</p>\s*<div[^>]+id=["\']player-track',
29 webpage, 'title', default=None) or remove_start(
30 self._og_search_title(webpage), 'Radio Wave - ')
31 description = self._html_search_regex(
32 r'<p[^>]+title=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>.*?</p>\s*<div[^>]+id=["\']player-track',
33 webpage, 'description', fatal=False, group='url')
34 duration = int_or_none(self._search_regex(
35 r'data-duration=["\'](\d+)', webpage, 'duration', default=None))
36
37 return {
38 'id': audio_id,
39 'url': 'http://media.rozhlas.cz/_audio/%s.mp3' % audio_id,
40 'title': title,
41 'description': description,
42 'duration': duration,
43 'vcodec': 'none',
44 }
45
46
47 class RozhlasVltavaIE(InfoExtractor):
48 _VALID_URL = r'https?://(?:\w+\.rozhlas|english\.radio)\.cz/[\w-]+-(?P<id>\d+)'
49 _TESTS = [{
50 'url': 'https://wave.rozhlas.cz/papej-masicko-porcujeme-a-bilancujeme-filmy-a-serialy-ktere-letos-zabily-8891337',
51 'md5': 'ba2fdbc1242fc16771c7695d271ec355',
52 'info_dict': {
53 'id': 8891337,
54 'title': 'md5:21f99739d04ab49d8c189ec711eef4ec',
55 },
56 'playlist_count': 1,
57 'playlist': [{
58 'md5': 'ba2fdbc1242fc16771c7695d271ec355',
59 'info_dict': {
60 'id': '10520988',
61 'ext': 'mp3',
62 'title': 'Papej masíčko! Porcujeme a bilancujeme filmy a seriály, které to letos zabily',
63 'description': 'md5:1c6d29fb9564e1f17fc1bb83ae7da0bc',
64 'duration': 1574,
65 'artist': 'Aleš Stuchlý',
66 'channel_id': 'radio-wave',
67 },
68 }]
69 }, {
70 'url': 'https://wave.rozhlas.cz/poslechnete-si-neklid-podcastovy-thriller-o-vine-strachu-a-vztahu-ktery-zasel-8554744',
71 'info_dict': {
72 'id': 8554744,
73 'title': 'Poslechněte si Neklid. Podcastový thriller o vině, strachu a vztahu, který zašel příliš daleko',
74 },
75 'playlist_count': 5,
76 'playlist': [{
77 'md5': '93d4109cf8f40523699ae9c1d4600bdd',
78 'info_dict': {
79 'id': '9890713',
80 'ext': 'mp3',
81 'title': 'Neklid #1',
82 'description': '1. díl: Neklid: 1. díl',
83 'duration': 1025,
84 'artist': 'Josef Kokta',
85 'channel_id': 'radio-wave',
86 'chapter': 'Neklid #1',
87 'chapter_number': 1,
88 },
89 }, {
90 'md5': 'e9763235be4a6dcf94bc8a5bac1ca126',
91 'info_dict': {
92 'id': '9890716',
93 'ext': 'mp3',
94 'title': 'Neklid #2',
95 'description': '2. díl: Neklid: 2. díl',
96 'duration': 768,
97 'artist': 'Josef Kokta',
98 'channel_id': 'radio-wave',
99 'chapter': 'Neklid #2',
100 'chapter_number': 2,
101 },
102 }, {
103 'md5': '00b642ea94b78cc949ac84da09f87895',
104 'info_dict': {
105 'id': '9890722',
106 'ext': 'mp3',
107 'title': 'Neklid #3',
108 'description': '3. díl: Neklid: 3. díl',
109 'duration': 607,
110 'artist': 'Josef Kokta',
111 'channel_id': 'radio-wave',
112 'chapter': 'Neklid #3',
113 'chapter_number': 3,
114 },
115 }, {
116 'md5': 'faef97b1b49da7df874740f118c19dea',
117 'info_dict': {
118 'id': '9890728',
119 'ext': 'mp3',
120 'title': 'Neklid #4',
121 'description': '4. díl: Neklid: 4. díl',
122 'duration': 621,
123 'artist': 'Josef Kokta',
124 'channel_id': 'radio-wave',
125 'chapter': 'Neklid #4',
126 'chapter_number': 4,
127 },
128 }, {
129 'md5': '6e729fa39b647325b868d419c76f3efa',
130 'info_dict': {
131 'id': '9890734',
132 'ext': 'mp3',
133 'title': 'Neklid #5',
134 'description': '5. díl: Neklid: 5. díl',
135 'duration': 908,
136 'artist': 'Josef Kokta',
137 'channel_id': 'radio-wave',
138 'chapter': 'Neklid #5',
139 'chapter_number': 5,
140 },
141 }]
142 }]
143
144 def _extract_video(self, entry):
145 chapter_number = int_or_none(traverse_obj(entry, ('meta', 'ga', 'contentSerialPart')))
146 return {
147 'id': entry['meta']['ga']['contentId'],
148 'title': traverse_obj(entry, ('meta', 'ga', 'contentName')),
149 'description': entry.get('title'),
150 'duration': entry.get('duration'),
151 'artist': traverse_obj(entry, ('meta', 'ga', 'contentAuthor')),
152 'channel_id': traverse_obj(entry, ('meta', 'ga', 'contentCreator')),
153 'chapter': traverse_obj(entry, ('meta', 'ga', 'contentNameShort')) if chapter_number else None,
154 'chapter_number': chapter_number,
155 'formats': [{
156 'url': audio_link['url'],
157 'ext': audio_link.get('variant'),
158 'format_id': audio_link.get('variant'),
159 'abr': audio_link.get('bitrate'),
160 'acodec': audio_link.get('variant'),
161 'vcodec': 'none',
162 } for audio_link in entry['audioLinks']],
163 }
164
165 def _real_extract(self, url):
166 video_id = self._match_id(url)
167 webpage = self._download_webpage(url, video_id)
168
169 # FIXME: Use get_element_text_and_html_by_tag when it accepts less strict html
170 data = self._parse_json(extract_attributes(self._search_regex(
171 r'(<div class="mujRozhlasPlayer" data-player=\'[^\']+\'>)',
172 webpage, 'player'))['data-player'], video_id)['data']
173
174 return {
175 '_type': 'playlist',
176 'id': data.get('embedId'),
177 'title': traverse_obj(data, ('series', 'title')),
178 'entries': map(self._extract_video, data['playlist']),
179 }