]>
Commit | Line | Data |
---|---|---|
7881a644 | 1 | # -*- coding: utf-8 -*- |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | from random import random | |
6 | from math import floor | |
7 | ||
8 | from .common import InfoExtractor | |
1cc79574 | 9 | from ..utils import ( |
82642235 | 10 | ExtractorError, |
b5597738 | 11 | remove_end, |
5c2266df | 12 | sanitized_Request, |
82642235 | 13 | ) |
7881a644 | 14 | |
15 | ||
16 | class IPrimaIE(InfoExtractor): | |
b5597738 | 17 | _VALID_URL = r'https?://play\.iprima\.cz/(?:[^/]+/)*(?P<id>[^?#]+)' |
7881a644 | 18 | |
19 | _TESTS = [{ | |
20 | 'url': 'http://play.iprima.cz/particka/particka-92', | |
21 | 'info_dict': { | |
22 | 'id': '39152', | |
23 | 'ext': 'flv', | |
24 | 'title': 'Partička (92)', | |
d23da75b | 25 | 'description': 'md5:74e9617e51bca67c3ecfb2c6f9766f45', |
7881a644 | 26 | 'thumbnail': 'http://play.iprima.cz/sites/default/files/image_crops/image_620x349/3/491483_particka-92_image_620x349.jpg', |
27 | }, | |
28 | 'params': { | |
973f2532 | 29 | 'skip_download': True, # requires rtmpdump |
7881a644 | 30 | }, |
973f2532 PH |
31 | }, { |
32 | 'url': 'http://play.iprima.cz/particka/tchibo-particka-jarni-moda', | |
33 | 'info_dict': { | |
34 | 'id': '9718337', | |
35 | 'ext': 'flv', | |
36 | 'title': 'Tchibo Partička - Jarní móda', | |
973f2532 PH |
37 | 'thumbnail': 're:^http:.*\.jpg$', |
38 | }, | |
39 | 'params': { | |
40 | 'skip_download': True, # requires rtmpdump | |
41 | }, | |
bc03e585 SS |
42 | }, { |
43 | 'url': 'http://play.iprima.cz/zpravy-ftv-prima-2752015', | |
44 | 'only_matching': True, | |
973f2532 | 45 | }] |
7881a644 | 46 | |
47 | def _real_extract(self, url): | |
48 | mobj = re.match(self._VALID_URL, url) | |
bc3be21d | 49 | video_id = mobj.group('id') |
7881a644 | 50 | |
51 | webpage = self._download_webpage(url, video_id) | |
52 | ||
17286a96 | 53 | if re.search(r'Nemáte oprávnění přistupovat na tuto stránku\.\s*</div>', webpage): |
82642235 S |
54 | raise ExtractorError( |
55 | '%s said: You do not have permission to access this page' % self.IE_NAME, expected=True) | |
56 | ||
973f2532 PH |
57 | player_url = ( |
58 | 'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' % | |
2514d263 | 59 | (floor(random() * 1073741824), floor(random() * 1073741824)) |
3cfe7914 | 60 | ) |
7881a644 | 61 | |
5c2266df | 62 | req = sanitized_Request(player_url) |
7881a644 | 63 | req.add_header('Referer', url) |
64 | playerpage = self._download_webpage(req, video_id) | |
65 | ||
66 | base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1]) | |
67 | ||
68 | zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO') | |
7881a644 | 69 | if zoneGEO != '0': |
bc3be21d | 70 | base_url = base_url.replace('token', 'token_' + zoneGEO) |
7881a644 | 71 | |
72 | formats = [] | |
73 | for format_id in ['lq', 'hq', 'hd']: | |
bc3be21d PH |
74 | filename = self._html_search_regex( |
75 | r'"%s_id":(.+?),' % format_id, webpage, 'filename') | |
7881a644 | 76 | |
77 | if filename == 'null': | |
78 | continue | |
79 | ||
bc3be21d | 80 | real_id = self._search_regex( |
973f2532 PH |
81 | r'Prima-(?:[0-9]{10}|WEB)-([0-9]+)[-_]', |
82 | filename, 'real video id') | |
7881a644 | 83 | |
84 | if format_id == 'lq': | |
85 | quality = 0 | |
86 | elif format_id == 'hq': | |
87 | quality = 1 | |
88 | elif format_id == 'hd': | |
89 | quality = 2 | |
bc3be21d | 90 | filename = 'hq/' + filename |
7881a644 | 91 | |
92 | formats.append({ | |
93 | 'format_id': format_id, | |
94 | 'url': base_url, | |
95 | 'quality': quality, | |
bc3be21d | 96 | 'play_path': 'mp4:' + filename.replace('"', '')[:-4], |
7881a644 | 97 | 'rtmp_live': True, |
98 | 'ext': 'flv', | |
91264ce5 PH |
99 | }) |
100 | ||
101 | self._sort_formats(formats) | |
7881a644 | 102 | |
103 | return { | |
104 | 'id': real_id, | |
b5597738 | 105 | 'title': remove_end(self._og_search_title(webpage), ' | Prima PLAY'), |
7881a644 | 106 | 'thumbnail': self._og_search_thumbnail(webpage), |
107 | 'formats': formats, | |
d23da75b S |
108 | 'description': self._search_regex( |
109 | r'<p[^>]+itemprop="description"[^>]*>([^<]+)', | |
110 | webpage, 'description', default=None), | |
91264ce5 | 111 | } |