]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/heise.py
Prepare to release.
[youtubedl] / youtube_dl / extractor / heise.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 determine_ext,
7 int_or_none,
8 parse_iso8601,
9 xpath_text,
10 )
11
12
13 class HeiseIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
15 _TESTS = [{
16 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
17 'md5': 'ffed432483e922e88545ad9f2f15d30e',
18 'info_dict': {
19 'id': '2404147',
20 'ext': 'mp4',
21 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
22 'format_id': 'mp4_720p',
23 'timestamp': 1411812600,
24 'upload_date': '20140927',
25 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
26 'thumbnail': r're:^https?://.*/gallery/$',
27 }
28 }, {
29 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
30 'only_matching': True,
31 }, {
32 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
33 'only_matching': True,
34 }, {
35 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
36 'only_matching': True,
37 }]
38
39 def _real_extract(self, url):
40 video_id = self._match_id(url)
41 webpage = self._download_webpage(url, video_id)
42
43 container_id = self._search_regex(
44 r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
45 webpage, 'container ID')
46 sequenz_id = self._search_regex(
47 r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
48 webpage, 'sequenz ID')
49
50 title = self._html_search_meta('fulltitle', webpage, default=None)
51 if not title or title == "c't":
52 title = self._search_regex(
53 r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
54 webpage, 'title')
55
56 doc = self._download_xml(
57 'http://www.heise.de/videout/feed', video_id, query={
58 'container': container_id,
59 'sequenz': sequenz_id,
60 })
61
62 formats = []
63 for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
64 label = source_node.attrib['label']
65 height = int_or_none(self._search_regex(
66 r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
67 video_url = source_node.attrib['file']
68 ext = determine_ext(video_url, '')
69 formats.append({
70 'url': video_url,
71 'format_note': label,
72 'format_id': '%s_%s' % (ext, label),
73 'height': height,
74 })
75 self._sort_formats(formats)
76
77 description = self._og_search_description(
78 webpage, default=None) or self._html_search_meta(
79 'description', webpage)
80
81 return {
82 'id': video_id,
83 'title': title,
84 'description': description,
85 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image') or
86 self._og_search_thumbnail(webpage)),
87 'timestamp': parse_iso8601(
88 self._html_search_meta('date', webpage)),
89 'formats': formats,
90 }