23aead19d3d8d9a6f2318eb3254db2c43ebc8631
[youtube-dl] / youtube_dl / extractor / min20.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 Min20IE(InfoExtractor):
10     _VALID_URL = r'http://www\.20min\.ch/(videotv/\?vid=(?P<video_id>[0-9]+)|.+?-(?P<page_id>[0-9]+)$)'
11     _TESTS = [{
12         'url': 'http://www.20min.ch/schweiz/news/story/-Wir-muessen-mutig-nach-vorne-schauen--22050469',
13         'md5': 'cd4cbb99b94130cff423e967cd275e5e',
14         'info_dict': {
15             'id': '22050469',
16             'ext': 'flv',
17             'title': '«Wir müssen mutig nach vorne schauen»',
18             'description': 'Kein Land sei innovativer als die Schweiz, sagte Johann Schneider-Ammann in seiner Neujahrsansprache. Das Land müsse aber seine Hausaufgaben machen.',
19             'thumbnail': 'http://www.20min.ch/images/content/2/2/0/22050469/10/teaserbreit.jpg'
20         }
21     }, {
22         'url': 'http://www.20min.ch/videotv/?vid=469148&cid=2',
23         'md5': 'b52d6bc6ea6398e6a38f12cfd418149c',
24         'info_dict': {
25             'id': '469148',
26             'ext': 'flv',
27             'title': '85 000 Franken für 15 perfekte Minuten',
28             'description': 'Was die Besucher vom Silvesterzauber erwarten können. (Video: Alice Grosjean/Murat Temel)',
29             'thumbnail': 'http://thumbnails.20min-tv.ch/server063/469148/frame-72-469148.jpg'
30         }
31     }]
32
33     # location of the flv videos, can't be extracted from the web page
34     _BASE_URL = "http://flv-rr.20min-tv.ch/videos/"
35
36     def _real_extract(self, url):
37         mobj = re.match(self._VALID_URL, url)
38         video_id = mobj.group('page_id')
39         if video_id is None:
40             # URL from the videoportal
41             video_id = mobj.group('video_id')
42         webpage = self._download_webpage(url, video_id)
43         title = self._html_search_regex(r'<h1>.*<span>(.+?)</span></h1>', webpage, 'title')
44         flash_id = self._search_regex(r"so\.addVariable\(\"file1\",\"([0-9]+)\"\)", webpage, 'flash_id')
45
46         description = self._html_search_regex(r'<meta name="description" content="(.+?)" />', webpage, 'description')
47         thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)" />', webpage, 'thumbnail')
48         url = self._BASE_URL + flash_id + "m.flv"
49
50         return {
51             'id': video_id,
52             'url': url,
53             'title': title,
54             'description': description,
55             'thumbnail': thumbnail
56         }