[ie/dropbox] Fix password-protected video extraction (#11636)
[yt-dlp3.git] / yt_dlp / extractor / heise.py
blob01b700b1575e7fa8ac7bc1fe5ab69508fbff06aa
1 import urllib.parse
3 from .common import InfoExtractor
4 from .kaltura import KalturaIE
5 from .youtube import YoutubeIE
6 from ..utils import (
7 NO_DEFAULT,
8 determine_ext,
9 int_or_none,
10 parse_iso8601,
11 smuggle_url,
12 xpath_text,
16 class HeiseIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
18 _TESTS = [{
19 # kaltura embed
20 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
21 'info_dict': {
22 'id': '1_kkrq94sm',
23 'ext': 'mp4',
24 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
25 'timestamp': 1512734959,
26 'upload_date': '20171208',
27 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
28 'thumbnail': 're:^https?://.*/thumbnail/.*',
29 'duration': 2845,
30 'view_count': int,
32 'params': {
33 'skip_download': True,
35 }, {
36 # YouTube embed
37 'url': 'http://www.heise.de/newsticker/meldung/Netflix-In-20-Jahren-vom-Videoverleih-zum-TV-Revolutionaer-3814130.html',
38 'md5': 'e403d2b43fea8e405e88e3f8623909f1',
39 'info_dict': {
40 'id': '6kmWbXleKW4',
41 'ext': 'mp4',
42 'title': 'Neu im September 2017 | Netflix',
43 'description': 'md5:d6852d1f96bb80760608eed3b907437c',
44 'upload_date': '20170830',
45 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
46 'uploader_id': 'netflixdach',
47 'categories': ['Entertainment'],
48 'tags': 'count:27',
49 'age_limit': 0,
50 'availability': 'public',
51 'comment_count': int,
52 'channel_id': 'UCZqgRlLcvO3Fnx_npQJygcQ',
53 'thumbnail': 'https://i.ytimg.com/vi_webp/6kmWbXleKW4/maxresdefault.webp',
54 'uploader_url': 'http://www.youtube.com/user/netflixdach',
55 'playable_in_embed': True,
56 'live_status': 'not_live',
57 'channel_url': 'https://www.youtube.com/channel/UCZqgRlLcvO3Fnx_npQJygcQ',
58 'view_count': int,
59 'channel': 'Netflix Deutschland, Österreich und Schweiz',
60 'channel_follower_count': int,
61 'like_count': int,
62 'duration': 67,
64 'params': {
65 'skip_download': True,
67 }, {
68 'url': 'https://www.heise.de/video/artikel/nachgehakt-Wie-sichert-das-c-t-Tool-Restric-tor-Windows-10-ab-3700244.html',
69 'info_dict': {
70 'id': '1_ntrmio2s',
71 'ext': 'mp4',
72 'title': "nachgehakt: Wie sichert das c't-Tool Restric'tor Windows 10 ab?",
73 'description': 'md5:47e8ffb6c46d85c92c310a512d6db271',
74 'timestamp': 1512470717,
75 'upload_date': '20171205',
76 'duration': 786,
77 'view_count': int,
78 'thumbnail': 're:^https?://.*/thumbnail/.*',
80 'params': {
81 'skip_download': True,
83 }, {
84 # FIXME: Video m3u8 fails to download; issue with Kaltura extractor
85 'url': 'https://www.heise.de/ct/artikel/c-t-uplink-20-8-Staubsaugerroboter-Xiaomi-Vacuum-2-AR-Brille-Meta-2-und-Android-rooten-3959893.html',
86 'info_dict': {
87 'id': '1_59mk80sf',
88 'ext': 'mp4',
89 'title': "c't uplink 20.8: Staubsaugerroboter Xiaomi Vacuum 2, AR-Brille Meta 2 und Android rooten",
90 'description': 'md5:f50fe044d3371ec73a8f79fcebd74afc',
91 'timestamp': 1517567237,
92 'upload_date': '20180202',
94 'params': {
95 'skip_download': True,
97 }, {
98 # videout
99 'url': 'https://www.heise.de/ct/artikel/c-t-uplink-3-8-Anonyme-SIM-Karten-G-Sync-Monitore-Citizenfour-2440327.html',
100 'info_dict': {
101 'id': '2440327',
102 'ext': 'mp4',
103 'title': 'c\'t uplink 3.8: Anonyme SIM-Karten, G-Sync-Monitore, Citizenfour',
104 'thumbnail': 'http://www.heise.de/imagine/yxM2qmol0xV3iFB7qFb70dGvXjc/gallery/',
105 'description': 'md5:fa164d8c8707dff124a9626d39205f5d',
106 'timestamp': 1414825200,
107 'upload_date': '20141101',
109 }, {
110 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
111 'only_matching': True,
112 }, {
113 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
114 'only_matching': True,
115 }, {
116 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
117 'only_matching': True,
120 def _real_extract(self, url):
121 video_id = self._match_id(url)
122 webpage = self._download_webpage(url, video_id)
124 def extract_title(default=NO_DEFAULT):
125 title = self._html_search_meta(
126 ('fulltitle', 'title'), webpage, default=None)
127 if not title or title == "c't":
128 title = self._search_regex(
129 r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
130 webpage, 'title', default=None)
131 if not title:
132 title = self._html_search_regex(
133 r'<h1[^>]+\bclass=["\']article_page_title[^>]+>(.+?)<',
134 webpage, 'title', default=default)
135 return title
137 title = extract_title(default=None)
138 description = self._og_search_description(
139 webpage, default=None) or self._html_search_meta(
140 'description', webpage)
142 def _make_kaltura_result(kaltura_url):
143 return {
144 '_type': 'url_transparent',
145 'url': smuggle_url(kaltura_url, {'source_url': url}),
146 'ie_key': KalturaIE.ie_key(),
147 'title': title,
148 'description': description,
151 kaltura_url = KalturaIE._extract_url(webpage)
152 if kaltura_url:
153 return _make_kaltura_result(kaltura_url)
155 kaltura_id = self._search_regex(
156 r'entry-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'kaltura id',
157 default=None, group='id')
158 if kaltura_id:
159 return _make_kaltura_result(f'kaltura:2238431:{kaltura_id}')
161 yt_urls = tuple(YoutubeIE._extract_embed_urls(url, webpage))
162 if yt_urls:
163 return self.playlist_from_matches(
164 yt_urls, video_id, title, ie=YoutubeIE.ie_key())
166 title = extract_title()
167 api_params = urllib.parse.parse_qs(
168 self._search_regex(r'/videout/feed\.json\?([^\']+)', webpage, 'feed params', default=None) or '')
169 if not api_params or 'container' not in api_params or 'sequenz' not in api_params:
170 container_id = self._search_regex(
171 r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
172 webpage, 'container ID')
174 sequenz_id = self._search_regex(
175 r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
176 webpage, 'sequenz ID')
177 api_params = {
178 'container': container_id,
179 'sequenz': sequenz_id,
181 doc = self._download_xml(
182 'http://www.heise.de/videout/feed', video_id, query=api_params)
184 formats = []
185 for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
186 label = source_node.attrib['label']
187 height = int_or_none(self._search_regex(
188 r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
189 video_url = source_node.attrib['file']
190 ext = determine_ext(video_url, '')
191 formats.append({
192 'url': video_url,
193 'format_note': label,
194 'format_id': f'{ext}_{label}',
195 'height': height,
198 return {
199 'id': video_id,
200 'title': title,
201 'description': description,
202 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image')
203 or self._og_search_thumbnail(webpage)),
204 'timestamp': parse_iso8601(
205 self._html_search_meta('date', webpage)),
206 'formats': formats,