[tvn24] Add extractor
[youtube-dl] / youtube_dl / extractor / tvn24.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class TVN24IE(InfoExtractor):
8     _VALID_URL = r'http://(?:tvn24bis|(?:www|fakty)\.tvn24)\.pl/.+/(?P<id>[^/]+)\.html'
9     _TEST = {
10         'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html',
11         'md5': 'fbdec753d7bc29d96036808275f2130c',
12         'info_dict': {
13             'id': '1584444',
14             'ext': 'mp4',
15             'title': '"Święta mają być wesołe, dlatego, ludziska, wszyscy pod jemiołę"',
16             'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości "Szkła kontaktowego".',
17             'thumbnail': 're:http://.*[.]jpeg',
18         }
19     }
20
21     def _real_extract(self, url):
22         page_id = self._match_id(url)
23         webpage = self._download_webpage(url, page_id)
24         title = self._og_search_title(webpage)
25         description = self._og_search_description(webpage)
26         thumbnail = self._html_search_regex(r'\bdata-poster="(.+?)"', webpage, 'data-poster')
27         share_params = self._html_search_regex(r'\bdata-share-params="(.+?)"', webpage, 'data-share-params')
28         share_params = self._parse_json(share_params, page_id)
29         video_id = share_params['id']
30         quality_data = self._html_search_regex(r'\bdata-quality="(.+?)"', webpage, 'data-quality')
31         quality_data = self._parse_json(quality_data, page_id)
32         formats = []
33         for format_id, url in quality_data.items():
34             formats.append({
35                 'format_id': format_id,
36                 'height': int(format_id.rstrip('p')),
37                 'url': url,
38                 'ext': 'mp4',
39             })
40         self._sort_formats(formats)
41         return {
42             'id': video_id,
43             'title': title,
44             'description': description,
45             'thumbnail': thumbnail,
46             'formats': formats,
47         }