]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/heise.py
New upstream version 2017.09.24
[youtubedl] / youtube_dl / extractor / heise.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .youtube import YoutubeIE
6 from ..utils import (
7 determine_ext,
8 int_or_none,
9 parse_iso8601,
10 xpath_text,
11 )
12
13
14 class HeiseIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
16 _TESTS = [{
17 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
18 'md5': 'ffed432483e922e88545ad9f2f15d30e',
19 'info_dict': {
20 'id': '2404147',
21 'ext': 'mp4',
22 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
23 'format_id': 'mp4_720p',
24 'timestamp': 1411812600,
25 'upload_date': '20140927',
26 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
27 'thumbnail': r're:^https?://.*/gallery/$',
28 }
29 }, {
30 # YouTube embed
31 'url': 'http://www.heise.de/newsticker/meldung/Netflix-In-20-Jahren-vom-Videoverleih-zum-TV-Revolutionaer-3814130.html',
32 'md5': 'e403d2b43fea8e405e88e3f8623909f1',
33 'info_dict': {
34 'id': '6kmWbXleKW4',
35 'ext': 'mp4',
36 'title': 'NEU IM SEPTEMBER | Netflix',
37 'description': 'md5:2131f3c7525e540d5fd841de938bd452',
38 'upload_date': '20170830',
39 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
40 'uploader_id': 'netflixdach',
41 },
42 'params': {
43 'skip_download': True,
44 },
45 }, {
46 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
47 'only_matching': True,
48 }, {
49 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
50 'only_matching': True,
51 }, {
52 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
53 'only_matching': True,
54 }]
55
56 def _real_extract(self, url):
57 video_id = self._match_id(url)
58 webpage = self._download_webpage(url, video_id)
59
60 title = self._html_search_meta('fulltitle', webpage, default=None)
61 if not title or title == "c't":
62 title = self._search_regex(
63 r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
64 webpage, 'title')
65
66 yt_urls = YoutubeIE._extract_urls(webpage)
67 if yt_urls:
68 return self.playlist_from_matches(yt_urls, video_id, title, ie=YoutubeIE.ie_key())
69
70 container_id = self._search_regex(
71 r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
72 webpage, 'container ID')
73 sequenz_id = self._search_regex(
74 r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
75 webpage, 'sequenz ID')
76
77 doc = self._download_xml(
78 'http://www.heise.de/videout/feed', video_id, query={
79 'container': container_id,
80 'sequenz': sequenz_id,
81 })
82
83 formats = []
84 for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
85 label = source_node.attrib['label']
86 height = int_or_none(self._search_regex(
87 r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
88 video_url = source_node.attrib['file']
89 ext = determine_ext(video_url, '')
90 formats.append({
91 'url': video_url,
92 'format_note': label,
93 'format_id': '%s_%s' % (ext, label),
94 'height': height,
95 })
96 self._sort_formats(formats)
97
98 description = self._og_search_description(
99 webpage, default=None) or self._html_search_meta(
100 'description', webpage)
101
102 return {
103 'id': video_id,
104 'title': title,
105 'description': description,
106 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image') or
107 self._og_search_thumbnail(webpage)),
108 'timestamp': parse_iso8601(
109 self._html_search_meta('date', webpage)),
110 'formats': formats,
111 }