093a7e551abbf40628cb28d26742b2a1e12bd7cc
[youtube-dl] / youtube_dl / extractor / iprima.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5 import time
6
7 from .common import InfoExtractor
8 from ..utils import (
9     sanitized_Request,
10 )
11
12
13 class IPrimaIE(InfoExtractor):
14     _VALID_URL = r'https?://play\.iprima\.cz/(?:.+/)?(?P<id>[^?#]+)'
15
16     _TESTS = [{
17         'url': 'http://play.iprima.cz/gondici-s-r-o-33',
18         'info_dict': {
19             'id': 'p136534',
20             'ext': 'mp4',
21             'title': 'Gondíci s. r. o. (34)',
22             'description': 'md5:16577c629d006aa91f59ca8d8e7f99bd',
23         },
24         'params': {
25             'skip_download': True,  # m3u8 download
26         },
27     }, {
28         'url': 'http://play.iprima.cz/particka/particka-92',
29         'only_matching': True,
30     }]
31
32     def _real_extract(self, url):
33         mobj = re.match(self._VALID_URL, url)
34         video_id = mobj.group('id')
35
36         webpage = self._download_webpage(url, video_id)
37
38         video_id = self._search_regex(r'data-product="([^"]+)">', webpage, 'real id')
39
40         req = sanitized_Request('http://play.iprima.cz/prehravac/init?_infuse=1'
41             '&_ts=%s&productId=%s' % (round(time.time()), 'p22201'))
42         req.add_header('Referer', url)
43         playerpage = self._download_webpage(req, video_id, note='Downloading player')
44
45         m3u8_url = self._search_regex(r"'src': '([^']+\.m3u8)'", playerpage, 'm3u8 url')
46
47         formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
48
49         self._sort_formats(formats)
50
51         return {
52             'id': video_id,
53             'title': self._og_search_title(webpage),
54             'thumbnail': self._og_search_thumbnail(webpage),
55             'formats': formats,
56             'description': self._og_search_description(webpage),
57         }