]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/heise.py
New upstream version 2019.09.28
[youtubedl] / youtube_dl / extractor / heise.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .kaltura import KalturaIE
6 from .youtube import YoutubeIE
7 from ..utils import (
8 determine_ext,
9 int_or_none,
10 NO_DEFAULT,
11 parse_iso8601,
12 smuggle_url,
13 xpath_text,
14 )
15
16
17 class HeiseIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
19 _TESTS = [{
20 # kaltura embed
21 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
22 'info_dict': {
23 'id': '1_kkrq94sm',
24 'ext': 'mp4',
25 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
26 'timestamp': 1512734959,
27 'upload_date': '20171208',
28 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
29 },
30 'params': {
31 'skip_download': True,
32 },
33 }, {
34 # YouTube embed
35 'url': 'http://www.heise.de/newsticker/meldung/Netflix-In-20-Jahren-vom-Videoverleih-zum-TV-Revolutionaer-3814130.html',
36 'md5': 'e403d2b43fea8e405e88e3f8623909f1',
37 'info_dict': {
38 'id': '6kmWbXleKW4',
39 'ext': 'mp4',
40 'title': 'NEU IM SEPTEMBER | Netflix',
41 'description': 'md5:2131f3c7525e540d5fd841de938bd452',
42 'upload_date': '20170830',
43 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
44 'uploader_id': 'netflixdach',
45 },
46 'params': {
47 'skip_download': True,
48 },
49 }, {
50 'url': 'https://www.heise.de/video/artikel/nachgehakt-Wie-sichert-das-c-t-Tool-Restric-tor-Windows-10-ab-3700244.html',
51 'info_dict': {
52 'id': '1_ntrmio2s',
53 'ext': 'mp4',
54 'title': "nachgehakt: Wie sichert das c't-Tool Restric'tor Windows 10 ab?",
55 'description': 'md5:47e8ffb6c46d85c92c310a512d6db271',
56 'timestamp': 1512470717,
57 'upload_date': '20171205',
58 },
59 'params': {
60 'skip_download': True,
61 },
62 }, {
63 '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',
64 'info_dict': {
65 'id': '1_59mk80sf',
66 'ext': 'mp4',
67 'title': "c't uplink 20.8: Staubsaugerroboter Xiaomi Vacuum 2, AR-Brille Meta 2 und Android rooten",
68 'description': 'md5:f50fe044d3371ec73a8f79fcebd74afc',
69 'timestamp': 1517567237,
70 'upload_date': '20180202',
71 },
72 'params': {
73 'skip_download': True,
74 },
75 }, {
76 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
77 'only_matching': True,
78 }, {
79 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
80 'only_matching': True,
81 }, {
82 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
83 'only_matching': True,
84 }]
85
86 def _real_extract(self, url):
87 video_id = self._match_id(url)
88 webpage = self._download_webpage(url, video_id)
89
90 def extract_title(default=NO_DEFAULT):
91 title = self._html_search_meta(
92 ('fulltitle', 'title'), webpage, default=None)
93 if not title or title == "c't":
94 title = self._search_regex(
95 r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
96 webpage, 'title', default=None)
97 if not title:
98 title = self._html_search_regex(
99 r'<h1[^>]+\bclass=["\']article_page_title[^>]+>(.+?)<',
100 webpage, 'title', default=default)
101 return title
102
103 title = extract_title(default=None)
104 description = self._og_search_description(
105 webpage, default=None) or self._html_search_meta(
106 'description', webpage)
107
108 def _make_kaltura_result(kaltura_url):
109 return {
110 '_type': 'url_transparent',
111 'url': smuggle_url(kaltura_url, {'source_url': url}),
112 'ie_key': KalturaIE.ie_key(),
113 'title': title,
114 'description': description,
115 }
116
117 kaltura_url = KalturaIE._extract_url(webpage)
118 if kaltura_url:
119 return _make_kaltura_result(kaltura_url)
120
121 kaltura_id = self._search_regex(
122 r'entry-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'kaltura id',
123 default=None, group='id')
124 if kaltura_id:
125 return _make_kaltura_result('kaltura:2238431:%s' % kaltura_id)
126
127 yt_urls = YoutubeIE._extract_urls(webpage)
128 if yt_urls:
129 return self.playlist_from_matches(
130 yt_urls, video_id, title, ie=YoutubeIE.ie_key())
131
132 title = extract_title()
133
134 container_id = self._search_regex(
135 r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
136 webpage, 'container ID')
137
138 sequenz_id = self._search_regex(
139 r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
140 webpage, 'sequenz ID')
141
142 doc = self._download_xml(
143 'http://www.heise.de/videout/feed', video_id, query={
144 'container': container_id,
145 'sequenz': sequenz_id,
146 })
147
148 formats = []
149 for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
150 label = source_node.attrib['label']
151 height = int_or_none(self._search_regex(
152 r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
153 video_url = source_node.attrib['file']
154 ext = determine_ext(video_url, '')
155 formats.append({
156 'url': video_url,
157 'format_note': label,
158 'format_id': '%s_%s' % (ext, label),
159 'height': height,
160 })
161 self._sort_formats(formats)
162
163 return {
164 'id': video_id,
165 'title': title,
166 'description': description,
167 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image')
168 or self._og_search_thumbnail(webpage)),
169 'timestamp': parse_iso8601(
170 self._html_search_meta('date', webpage)),
171 'formats': formats,
172 }