1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
5 from random import random
8 from .common import InfoExtractor
16 class IPrimaIE(InfoExtractor):
18 _VALID_URL = r'https?://play\.iprima\.cz/(?:[^/]+/)*(?P<id>[^?#]+)'
21 'url': 'http://play.iprima.cz/particka/particka-92',
25 'title': 'Partička (92)',
26 'description': 'md5:74e9617e51bca67c3ecfb2c6f9766f45',
27 'thumbnail': 'http://play.iprima.cz/sites/default/files/image_crops/image_620x349/3/491483_particka-92_image_620x349.jpg',
30 'skip_download': True, # requires rtmpdump
33 'url': 'http://play.iprima.cz/particka/tchibo-particka-jarni-moda',
37 'title': 'Tchibo Partička - Jarní móda',
38 'thumbnail': 're:^http:.*\.jpg$',
41 'skip_download': True, # requires rtmpdump
44 'url': 'http://play.iprima.cz/zpravy-ftv-prima-2752015',
45 'only_matching': True,
48 def _real_extract(self, url):
49 mobj = re.match(self._VALID_URL, url)
50 video_id = mobj.group('id')
52 webpage = self._download_webpage(url, video_id)
54 if re.search(r'Nemáte oprávnění přistupovat na tuto stránku\.\s*</div>', webpage):
56 '%s said: You do not have permission to access this page' % self.IE_NAME, expected=True)
59 'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' %
60 (floor(random() * 1073741824), floor(random() * 1073741824))
63 req = sanitized_Request(player_url)
64 req.add_header('Referer', url)
65 playerpage = self._download_webpage(req, video_id)
67 base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1])
69 zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO')
71 base_url = base_url.replace('token', 'token_' + zoneGEO)
74 for format_id in ['lq', 'hq', 'hd']:
75 filename = self._html_search_regex(
76 r'"%s_id":(.+?),' % format_id, webpage, 'filename')
78 if filename == 'null':
81 real_id = self._search_regex(
82 r'Prima-(?:[0-9]{10}|WEB)-([0-9]+)[-_]',
83 filename, 'real video id')
87 elif format_id == 'hq':
89 elif format_id == 'hd':
91 filename = 'hq/' + filename
94 'format_id': format_id,
97 'play_path': 'mp4:' + filename.replace('"', '')[:-4],
102 self._sort_formats(formats)
106 'title': remove_end(self._og_search_title(webpage), ' | Prima PLAY'),
107 'thumbnail': self._og_search_thumbnail(webpage),
109 'description': self._search_regex(
110 r'<p[^>]+itemprop="description"[^>]*>([^<]+)',
111 webpage, 'description', default=None),