]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/heise.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / heise.py
CommitLineData
0ca0f881 1import urllib.parse
2
0155549d 3from .common import InfoExtractor
6202f08e 4from .kaltura import KalturaIE
4d8c4b46 5from .youtube import YoutubeIE
0155549d 6from ..utils import (
0ca0f881 7 NO_DEFAULT,
711ede6e 8 determine_ext,
ecfe6234 9 int_or_none,
0155549d 10 parse_iso8601,
6202f08e 11 smuggle_url,
bad4ccdb 12 xpath_text,
0155549d
M
13)
14
15
16class HeiseIE(InfoExtractor):
bad4ccdb
S
17 _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
18 _TESTS = [{
8e70c1bf 19 # kaltura embed
bad4ccdb 20 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
bad4ccdb 21 'info_dict': {
8e70c1bf 22 'id': '1_kkrq94sm',
bad4ccdb
S
23 'ext': 'mp4',
24 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
8e70c1bf
S
25 'timestamp': 1512734959,
26 'upload_date': '20171208',
bad4ccdb 27 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
0ca0f881 28 'thumbnail': 're:^https?://.*/thumbnail/.*',
29 'duration': 2845,
30 'view_count': int,
8e70c1bf
S
31 },
32 'params': {
33 'skip_download': True,
34 },
4d8c4b46 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',
0ca0f881 42 'title': 'Neu im September 2017 | Netflix',
43 'description': 'md5:d6852d1f96bb80760608eed3b907437c',
4d8c4b46 44 'upload_date': '20170830',
45 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
46 'uploader_id': 'netflixdach',
0ca0f881 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,
4d8c4b46 63 },
64 'params': {
65 'skip_download': True,
66 },
6202f08e 67 }, {
68 'url': 'https://www.heise.de/video/artikel/nachgehakt-Wie-sichert-das-c-t-Tool-Restric-tor-Windows-10-ab-3700244.html',
6202f08e 69 'info_dict': {
70 'id': '1_ntrmio2s',
8e70c1bf
S
71 'ext': 'mp4',
72 'title': "nachgehakt: Wie sichert das c't-Tool Restric'tor Windows 10 ab?",
73 'description': 'md5:47e8ffb6c46d85c92c310a512d6db271',
6202f08e 74 'timestamp': 1512470717,
75 'upload_date': '20171205',
0ca0f881 76 'duration': 786,
77 'view_count': int,
78 'thumbnail': 're:^https?://.*/thumbnail/.*',
8e70c1bf
S
79 },
80 'params': {
81 'skip_download': True,
82 },
83 }, {
0ca0f881 84 # FIXME: Video m3u8 fails to download; issue with Kaltura extractor
8e70c1bf
S
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',
6202f08e 88 'ext': 'mp4',
8e70c1bf
S
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',
6202f08e 93 },
94 'params': {
95 'skip_download': True,
96 },
0ca0f881 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',
108 }
bad4ccdb
S
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,
118 }]
0155549d 119
0155549d 120 def _real_extract(self, url):
5a8b7755 121 video_id = self._match_id(url)
5a8b7755 122 webpage = self._download_webpage(url, video_id)
ecfe6234 123
8e70c1bf
S
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
4d8c4b46 136
8e70c1bf
S
137 title = extract_title(default=None)
138 description = self._og_search_description(
139 webpage, default=None) or self._html_search_meta(
140 'description', webpage)
4d8c4b46 141
cb3e4a29 142 def _make_kaltura_result(kaltura_url):
8e70c1bf
S
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,
149 }
150
cb3e4a29
S
151 kaltura_url = KalturaIE._extract_url(webpage)
152 if kaltura_url:
153 return _make_kaltura_result(kaltura_url)
154
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('kaltura:2238431:%s' % kaltura_id)
160
43aebb7d 161 yt_urls = tuple(YoutubeIE._extract_embed_urls(url, webpage))
8e70c1bf
S
162 if yt_urls:
163 return self.playlist_from_matches(
164 yt_urls, video_id, title, ie=YoutubeIE.ie_key())
165
166 title = extract_title()
0ca0f881 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')
6202f08e 173
0ca0f881 174 sequenz_id = self._search_regex(
175 r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
176 webpage, 'sequenz ID')
177 api_params = {
bad4ccdb
S
178 'container': container_id,
179 'sequenz': sequenz_id,
0ca0f881 180 }
181 doc = self._download_xml(
182 'http://www.heise.de/videout/feed', video_id, query=api_params)
0155549d
M
183
184 formats = []
ecfe6234
PH
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))
711ede6e
PH
189 video_url = source_node.attrib['file']
190 ext = determine_ext(video_url, '')
ecfe6234 191 formats.append({
711ede6e 192 'url': video_url,
ecfe6234 193 'format_note': label,
711ede6e 194 'format_id': '%s_%s' % (ext, label),
ecfe6234
PH
195 'height': height,
196 })
0155549d 197
bad4ccdb
S
198 return {
199 'id': video_id,
200 'title': title,
201 'description': description,
3089bc74
S
202 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image')
203 or self._og_search_thumbnail(webpage)),
bad4ccdb
S
204 'timestamp': parse_iso8601(
205 self._html_search_meta('date', webpage)),
206 'formats': formats,
207 }