]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/heise.py
[heise] Add support for description
[yt-dlp.git] / 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 get_meta_content,
7 parse_iso8601,
8 )
9
10
11 class HeiseIE(InfoExtractor):
12 _VALID_URL = r'''(?x)
13 https?://(?:www\.)?heise\.de/video/artikel/
14 .+?(?P<id>[0-9]+)\.html(?:$|[?#])
15 '''
16 _TEST = {
17 'url': (
18 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html'
19 ),
20 'md5': 'ffed432483e922e88545ad9f2f15d30e',
21 'info_dict': {
22 'id': '2404147',
23 'ext': 'mp4',
24 'title': (
25 "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone"
26 ),
27 'format_id': 'mp4_720',
28 'timestamp': 1411812600,
29 'upload_date': '20140927',
30 'description': 'In uplink-Episode 3.3 geht es darum, wie man sich von Cloud-Anbietern emanzipieren kann, worauf man beim Kauf einer Tastatur achten sollte und was Smartphones über uns verraten.',
31 }
32 }
33
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
36
37 webpage = self._download_webpage(url, video_id)
38 json_url = self._search_regex(
39 r'json_url:\s*"([^"]+)"', webpage, 'json URL')
40 config = self._download_json(json_url, video_id)
41
42 info = {
43 'id': video_id,
44 'thumbnail': config.get('poster'),
45 'timestamp': parse_iso8601(get_meta_content('date', webpage)),
46 'description': self._og_search_description(webpage),
47 }
48
49 title = get_meta_content('fulltitle', webpage)
50 if title:
51 info['title'] = title
52 elif config.get('title'):
53 info['title'] = config['title']
54 else:
55 info['title'] = self._og_search_title(webpage)
56
57 formats = []
58 for t, rs in config['formats'].items():
59 if not rs or not hasattr(rs, 'items'):
60 self._downloader.report_warning(
61 'formats: {0}: no resolutions'.format(t))
62 continue
63
64 for height_str, obj in rs.items():
65 format_id = '{0}_{1}'.format(t, height_str)
66
67 if not obj or not obj.get('url'):
68 self._downloader.report_warning(
69 'formats: {0}: no url'.format(format_id))
70 continue
71
72 formats.append({
73 'url': obj['url'],
74 'format_id': format_id,
75 'height': self._int(height_str, 'height'),
76 })
77
78 self._sort_formats(formats)
79 info['formats'] = formats
80
81 return info