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