]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/dlf.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / dlf.py
CommitLineData
b423b6a4
ND
1import re
2
3from .common import InfoExtractor
4from ..utils import (
5 determine_ext,
6 extract_attributes,
7 int_or_none,
8 traverse_obj,
9 url_or_none,
10)
11
12
13class DLFBaseIE(InfoExtractor):
14 _VALID_URL_BASE = r'https?://(?:www\.)?deutschlandfunk\.de/'
15 _BUTTON_REGEX = r'(<button[^>]+alt="Anhören"[^>]+data-audio-diraid[^>]*>)'
16
17 def _parse_button_attrs(self, button, audio_id=None):
18 attrs = extract_attributes(button)
19 audio_id = audio_id or attrs['data-audio-diraid']
20
21 url = traverse_obj(
22 attrs, 'data-audio-download-src', 'data-audio', 'data-audioreference',
23 'data-audio-src', expected_type=url_or_none)
24 ext = determine_ext(url)
25
26 return {
27 'id': audio_id,
28 'extractor_key': DLFIE.ie_key(),
29 'extractor': DLFIE.IE_NAME,
30 **traverse_obj(attrs, {
31 'title': (('data-audiotitle', 'data-audio-title', 'data-audio-download-tracking-title'), {str}),
32 'duration': (('data-audioduration', 'data-audio-duration'), {int_or_none}),
33 'thumbnail': ('data-audioimage', {url_or_none}),
34 'uploader': 'data-audio-producer',
35 'series': 'data-audio-series',
36 'channel': 'data-audio-origin-site-name',
37 'webpage_url': ('data-audio-download-tracking-path', {url_or_none}),
38 }, get_all=False),
39 'formats': (self._extract_m3u8_formats(url, audio_id, fatal=False)
add96eb9 40 if ext == 'm3u8' else [{'url': url, 'ext': ext, 'vcodec': 'none'}]),
b423b6a4
ND
41 }
42
43
44class DLFIE(DLFBaseIE):
45 IE_NAME = 'dlf'
46 _VALID_URL = DLFBaseIE._VALID_URL_BASE + r'[\w-]+-dlf-(?P<id>[\da-f]{8})-100\.html'
47 _TESTS = [
48 # Audio as an HLS stream
49 {
50 'url': 'https://www.deutschlandfunk.de/tanz-der-saiteninstrumente-das-wild-strings-trio-aus-slowenien-dlf-03a3eb19-100.html',
51 'info_dict': {
52 'id': '03a3eb19',
53 'title': r're:Tanz der Saiteninstrumente [-/] Das Wild Strings Trio aus Slowenien',
54 'ext': 'm4a',
55 'duration': 3298,
56 'thumbnail': 'https://assets.deutschlandfunk.de/FALLBACK-IMAGE-AUDIO/512x512.png?t=1603714364673',
57 'uploader': 'Deutschlandfunk',
58 'series': 'On Stage',
add96eb9 59 'channel': 'deutschlandfunk',
b423b6a4
ND
60 },
61 'params': {
add96eb9 62 'skip_download': 'm3u8',
b423b6a4 63 },
add96eb9 64 'skip': 'This webpage no longer exists',
b423b6a4
ND
65 }, {
66 'url': 'https://www.deutschlandfunk.de/russische-athleten-kehren-zurueck-auf-die-sportbuehne-ein-gefaehrlicher-tueroeffner-dlf-d9cc1856-100.html',
67 'info_dict': {
68 'id': 'd9cc1856',
69 'title': 'Russische Athleten kehren zurück auf die Sportbühne: Ein gefährlicher Türöffner',
70 'ext': 'mp3',
71 'duration': 291,
72 'thumbnail': 'https://assets.deutschlandfunk.de/FALLBACK-IMAGE-AUDIO/512x512.png?t=1603714364673',
73 'uploader': 'Deutschlandfunk',
74 'series': 'Kommentare und Themen der Woche',
add96eb9 75 'channel': 'deutschlandfunk',
76 },
b423b6a4
ND
77 },
78 ]
79
80 def _real_extract(self, url):
81 audio_id = self._match_id(url)
82 webpage = self._download_webpage(url, audio_id)
83
84 return self._parse_button_attrs(
85 self._search_regex(self._BUTTON_REGEX, webpage, 'button'), audio_id)
86
87
88class DLFCorpusIE(DLFBaseIE):
89 IE_NAME = 'dlf:corpus'
90 IE_DESC = 'DLF Multi-feed Archives'
91 _VALID_URL = DLFBaseIE._VALID_URL_BASE + r'(?P<id>(?![\w-]+-dlf-[\da-f]{8})[\w-]+-\d+)\.html'
92 _TESTS = [
93 # Recorded news broadcast with referrals to related broadcasts
94 {
95 'url': 'https://www.deutschlandfunk.de/fechten-russland-belarus-ukraine-protest-100.html',
96 'info_dict': {
97 'id': 'fechten-russland-belarus-ukraine-protest-100',
98 'title': r're:Wiederzulassung als neutrale Athleten [-/] Was die Rückkehr russischer und belarussischer Sportler beim Fechten bedeutet',
add96eb9 99 'description': 'md5:91340aab29c71aa7518ad5be13d1e8ad',
b423b6a4
ND
100 },
101 'playlist_mincount': 5,
102 'playlist': [{
103 'info_dict': {
104 'id': '1fc5d64a',
105 'title': r're:Wiederzulassung als neutrale Athleten [-/] Was die Rückkehr russischer und belarussischer Sportler beim Fechten bedeutet',
106 'ext': 'mp3',
107 'duration': 252,
108 'thumbnail': 'https://assets.deutschlandfunk.de/aad16241-6b76-4a09-958b-96d0ee1d6f57/512x512.jpg?t=1679480020313',
109 'uploader': 'Deutschlandfunk',
110 'series': 'Sport',
add96eb9 111 'channel': 'deutschlandfunk',
112 },
b423b6a4
ND
113 }, {
114 'info_dict': {
115 'id': '2ada145f',
116 'title': r're:(?:Sportpolitik / )?Fechtverband votiert für Rückkehr russischer Athleten',
117 'ext': 'mp3',
118 'duration': 336,
119 'thumbnail': 'https://assets.deutschlandfunk.de/FILE_93982766f7317df30409b8a184ac044a/512x512.jpg?t=1678547581005',
120 'uploader': 'Deutschlandfunk',
121 'series': 'Deutschlandfunk Nova',
add96eb9 122 'channel': 'deutschlandfunk-nova',
123 },
b423b6a4
ND
124 }, {
125 'info_dict': {
126 'id': '5e55e8c9',
127 'title': r're:Wiederzulassung von Russland und Belarus [-/] "Herumlavieren" des Fechter-Bundes sorgt für Unverständnis',
128 'ext': 'mp3',
129 'duration': 187,
130 'thumbnail': 'https://assets.deutschlandfunk.de/a595989d-1ed1-4a2e-8370-b64d7f11d757/512x512.jpg?t=1679173825412',
131 'uploader': 'Deutschlandfunk',
132 'series': 'Sport am Samstag',
add96eb9 133 'channel': 'deutschlandfunk',
134 },
b423b6a4
ND
135 }, {
136 'info_dict': {
137 'id': '47e1a096',
138 'title': r're:Rückkehr Russlands im Fechten [-/] "Fassungslos, dass es einfach so passiert ist"',
139 'ext': 'mp3',
140 'duration': 602,
141 'thumbnail': 'https://assets.deutschlandfunk.de/da4c494a-21cc-48b4-9cc7-40e09fd442c2/512x512.jpg?t=1678562155770',
142 'uploader': 'Deutschlandfunk',
143 'series': 'Sport am Samstag',
add96eb9 144 'channel': 'deutschlandfunk',
145 },
b423b6a4
ND
146 }, {
147 'info_dict': {
148 'id': '5e55e8c9',
149 'title': r're:Wiederzulassung von Russland und Belarus [-/] "Herumlavieren" des Fechter-Bundes sorgt für Unverständnis',
150 'ext': 'mp3',
151 'duration': 187,
152 'thumbnail': 'https://assets.deutschlandfunk.de/a595989d-1ed1-4a2e-8370-b64d7f11d757/512x512.jpg?t=1679173825412',
153 'uploader': 'Deutschlandfunk',
154 'series': 'Sport am Samstag',
add96eb9 155 'channel': 'deutschlandfunk',
156 },
157 }],
b423b6a4
ND
158 },
159 # Podcast feed with tag buttons, playlist count fluctuates
160 {
161 'url': 'https://www.deutschlandfunk.de/kommentare-und-themen-der-woche-100.html',
162 'info_dict': {
163 'id': 'kommentare-und-themen-der-woche-100',
164 'title': 'Meinung - Kommentare und Themen der Woche',
165 'description': 'md5:2901bbd65cd2d45e116d399a099ce5d5',
166 },
167 'playlist_mincount': 10,
168 },
169 # Podcast feed with no description
170 {
171 'url': 'https://www.deutschlandfunk.de/podcast-tolle-idee-100.html',
172 'info_dict': {
173 'id': 'podcast-tolle-idee-100',
174 'title': 'Wissenschaftspodcast - Tolle Idee! - Was wurde daraus?',
175 },
176 'playlist_mincount': 11,
177 },
178 ]
179
180 def _real_extract(self, url):
181 playlist_id = self._match_id(url)
182 webpage = self._download_webpage(url, playlist_id)
183
184 return {
185 '_type': 'playlist',
186 'id': playlist_id,
187 'description': self._html_search_meta(
188 ['description', 'og:description', 'twitter:description'], webpage, default=None),
189 'title': self._html_search_meta(
190 ['og:title', 'twitter:title'], webpage, default=None),
191 'entries': map(self._parse_button_attrs, re.findall(self._BUTTON_REGEX, webpage)),
192 }