[tagesschau] Modernize
[youtube-dl] / youtube_dl / extractor / tagesschau.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8
9 class TagesschauIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:www\.)?tagesschau\.de/multimedia/video/video(?P<id>-?[0-9]+)\.html'
11
12     _TESTS = [{
13         'url': 'http://www.tagesschau.de/multimedia/video/video1399128.html',
14         'md5': 'bcdeac2194fb296d599ce7929dfa4009',
15         'info_dict': {
16             'id': '1399128',
17             'ext': 'mp4',
18             'title': 'Harald Range, Generalbundesanwalt, zu den Ermittlungen',
19             'description': 'md5:69da3c61275b426426d711bde96463ab',
20             'thumbnail': 're:^http:.*\.jpg$',
21         },
22     }]
23
24     _FORMATS = {
25         's': {'width': 256, 'height': 144, 'quality': 1},
26         'm': {'width': 512, 'height': 288, 'quality': 2},
27         'l': {'width': 960, 'height': 544, 'quality': 3},
28     }
29
30     def _real_extract(self, url):
31         video_id = self._match_id(url)
32         display_id = video_id.lstrip('-')
33         webpage = self._download_webpage(url, display_id)
34
35         playerpage = self._download_webpage(
36             'http://www.tagesschau.de/multimedia/video/video%s~player_autoplay-true.html' % video_id,
37             display_id, 'Downloading player page')
38
39         medias = re.findall(
40             r'"(http://media.+?)", type:"video/(.+?)", quality:"(.+?)"',
41             playerpage)
42
43         formats = []
44         for url, ext, res in medias:
45             f = {
46                 'format_id': res + '_' + ext,
47                 'url': url,
48                 'ext': ext,
49             }
50             f.update(self._FORMATS.get(res, {}))
51             formats.append(f)
52
53         self._sort_formats(formats)
54
55         thumbnail = re.findall(r'"(/multimedia/.+?\.jpg)"', playerpage)[-1]
56
57         return {
58             'id': display_id,
59             'title': self._og_search_title(webpage).strip(),
60             'thumbnail': 'http://www.tagesschau.de' + thumbnail,
61             'formats': formats,
62             'description': self._og_search_description(webpage).strip(),
63         }