]>
Commit | Line | Data |
---|---|---|
369e7e3f | 1 | # coding: utf-8 |
7881a644 | 2 | from __future__ import unicode_literals |
3 | ||
4 | import re | |
f406c787 | 5 | import time |
7881a644 | 6 | |
7 | from .common import InfoExtractor | |
1cc79574 | 8 | from ..utils import ( |
369e7e3f S |
9 | determine_ext, |
10 | js_to_json, | |
82642235 | 11 | ) |
7881a644 | 12 | |
13 | ||
14 | class IPrimaIE(InfoExtractor): | |
90046d77 | 15 | _VALID_URL = r'https?://(?:[^/]+)\.iprima\.cz/(?:[^/]+/)*(?P<id>[^/?#&]+)' |
da42ff06 | 16 | _GEO_BYPASS = False |
7881a644 | 17 | |
18 | _TESTS = [{ | |
f406c787 | 19 | 'url': 'http://play.iprima.cz/gondici-s-r-o-33', |
7881a644 | 20 | 'info_dict': { |
f406c787 | 21 | 'id': 'p136534', |
22 | 'ext': 'mp4', | |
23 | 'title': 'Gondíci s. r. o. (34)', | |
24 | 'description': 'md5:16577c629d006aa91f59ca8d8e7f99bd', | |
7881a644 | 25 | }, |
26 | 'params': { | |
f406c787 | 27 | 'skip_download': True, # m3u8 download |
7881a644 | 28 | }, |
973f2532 | 29 | }, { |
f406c787 | 30 | 'url': 'http://play.iprima.cz/particka/particka-92', |
bc03e585 | 31 | 'only_matching': True, |
da42ff06 S |
32 | }, { |
33 | # geo restricted | |
34 | 'url': 'http://play.iprima.cz/closer-nove-pripady/closer-nove-pripady-iv-1', | |
35 | 'only_matching': True, | |
a2637a2d S |
36 | }, { |
37 | # iframe api.play-backend.iprima.cz | |
38 | 'url': 'https://prima.iprima.cz/my-little-pony/mapa-znameni-2-2', | |
39 | 'only_matching': True, | |
40 | }, { | |
41 | # iframe prima.iprima.cz | |
42 | 'url': 'https://prima.iprima.cz/porady/jak-se-stavi-sen/rodina-rathousova-praha', | |
43 | 'only_matching': True, | |
9235b509 S |
44 | }, { |
45 | 'url': 'http://www.iprima.cz/filmy/desne-rande', | |
46 | 'only_matching': True, | |
90046d77 | 47 | }, { |
48 | 'url': 'https://zoom.iprima.cz/10-nejvetsich-tajemstvi-zahad/posvatna-mista-a-stavby', | |
49 | 'only_matching': True, | |
50 | }, { | |
51 | 'url': 'https://krimi.iprima.cz/mraz-0/sebevrazdy', | |
52 | 'only_matching': True, | |
53 | }, { | |
54 | 'url': 'https://cool.iprima.cz/derava-silnice-nevadi', | |
55 | 'only_matching': True, | |
56 | }, { | |
57 | 'url': 'https://love.iprima.cz/laska-az-za-hrob/slib-dany-bratrovi', | |
58 | 'only_matching': True, | |
59 | }, { | |
60 | 'url': 'https://autosalon.iprima.cz/motorsport/7-epizoda-1', | |
61 | 'only_matching': True, | |
973f2532 | 62 | }] |
7881a644 | 63 | |
64 | def _real_extract(self, url): | |
369e7e3f | 65 | video_id = self._match_id(url) |
7881a644 | 66 | |
09322ccc S |
67 | self._set_cookie('play.iprima.cz', 'ott_adult_confirmed', '1') |
68 | ||
7881a644 | 69 | webpage = self._download_webpage(url, video_id) |
70 | ||
a2637a2d S |
71 | video_id = self._search_regex( |
72 | (r'<iframe[^>]+\bsrc=["\'](?:https?:)?//(?:api\.play-backend\.iprima\.cz/prehravac/embedded|prima\.iprima\.cz/[^/]+/[^/]+)\?.*?\bid=(p\d+)', | |
73 | r'data-product="([^"]+)">'), | |
74 | webpage, 'real id') | |
82642235 | 75 | |
82f66218 S |
76 | playerpage = self._download_webpage( |
77 | 'http://play.iprima.cz/prehravac/init', | |
78 | video_id, note='Downloading player', query={ | |
79 | '_infuse': 1, | |
80 | '_ts': round(time.time()), | |
81 | 'productId': video_id, | |
82 | }, headers={'Referer': url}) | |
7881a644 | 83 | |
369e7e3f | 84 | formats = [] |
7881a644 | 85 | |
369e7e3f S |
86 | def extract_formats(format_url, format_key=None, lang=None): |
87 | ext = determine_ext(format_url) | |
88 | new_formats = [] | |
89 | if format_key == 'hls' or ext == 'm3u8': | |
90 | new_formats = self._extract_m3u8_formats( | |
91 | format_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
92 | m3u8_id='hls', fatal=False) | |
93 | elif format_key == 'dash' or ext == 'mpd': | |
94 | return | |
95 | new_formats = self._extract_mpd_formats( | |
96 | format_url, video_id, mpd_id='dash', fatal=False) | |
97 | if lang: | |
98 | for f in new_formats: | |
99 | if not f.get('language'): | |
100 | f['language'] = lang | |
101 | formats.extend(new_formats) | |
102 | ||
103 | options = self._parse_json( | |
104 | self._search_regex( | |
0bbcc8a1 | 105 | r'(?s)(?:TDIPlayerOptions|playerOptions)\s*=\s*({.+?});\s*\]\]', |
369e7e3f S |
106 | playerpage, 'player options', default='{}'), |
107 | video_id, transform_source=js_to_json, fatal=False) | |
108 | if options: | |
109 | for key, tracks in options.get('tracks', {}).items(): | |
110 | if not isinstance(tracks, list): | |
111 | continue | |
112 | for track in tracks: | |
113 | src = track.get('src') | |
114 | if src: | |
115 | extract_formats(src, key.lower(), track.get('lang')) | |
116 | ||
117 | if not formats: | |
118 | for _, src in re.findall(r'src["\']\s*:\s*(["\'])(.+?)\1', playerpage): | |
119 | extract_formats(src) | |
91264ce5 | 120 | |
3c6b3bf2 | 121 | if not formats and '>GEO_IP_NOT_ALLOWED<' in playerpage: |
da42ff06 | 122 | self.raise_geo_restricted(countries=['CZ']) |
3c6b3bf2 | 123 | |
91264ce5 | 124 | self._sort_formats(formats) |
7881a644 | 125 | |
126 | return { | |
f406c787 | 127 | 'id': video_id, |
128 | 'title': self._og_search_title(webpage), | |
7881a644 | 129 | 'thumbnail': self._og_search_thumbnail(webpage), |
130 | 'formats': formats, | |
f406c787 | 131 | 'description': self._og_search_description(webpage), |
91264ce5 | 132 | } |