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