]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/iprima.py
[YoutubeDL] Ensure dir existence for each requested format (closes #14116)
[yt-dlp.git] / youtube_dl / extractor / iprima.py
CommitLineData
369e7e3f 1# coding: utf-8
7881a644 2from __future__ import unicode_literals
3
4import re
f406c787 5import time
7881a644 6
7from .common import InfoExtractor
1cc79574 8from ..utils import (
369e7e3f
S
9 determine_ext,
10 js_to_json,
82642235 11)
7881a644 12
13
14class IPrimaIE(InfoExtractor):
f406c787 15 _VALID_URL = r'https?://play\.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,
973f2532 36 }]
7881a644 37
38 def _real_extract(self, url):
369e7e3f 39 video_id = self._match_id(url)
7881a644 40
41 webpage = self._download_webpage(url, video_id)
42
f406c787 43 video_id = self._search_regex(r'data-product="([^"]+)">', webpage, 'real id')
82642235 44
82f66218
S
45 playerpage = self._download_webpage(
46 'http://play.iprima.cz/prehravac/init',
47 video_id, note='Downloading player', query={
48 '_infuse': 1,
49 '_ts': round(time.time()),
50 'productId': video_id,
51 }, headers={'Referer': url})
7881a644 52
369e7e3f 53 formats = []
7881a644 54
369e7e3f
S
55 def extract_formats(format_url, format_key=None, lang=None):
56 ext = determine_ext(format_url)
57 new_formats = []
58 if format_key == 'hls' or ext == 'm3u8':
59 new_formats = self._extract_m3u8_formats(
60 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
61 m3u8_id='hls', fatal=False)
62 elif format_key == 'dash' or ext == 'mpd':
63 return
64 new_formats = self._extract_mpd_formats(
65 format_url, video_id, mpd_id='dash', fatal=False)
66 if lang:
67 for f in new_formats:
68 if not f.get('language'):
69 f['language'] = lang
70 formats.extend(new_formats)
71
72 options = self._parse_json(
73 self._search_regex(
0bbcc8a1 74 r'(?s)(?:TDIPlayerOptions|playerOptions)\s*=\s*({.+?});\s*\]\]',
369e7e3f
S
75 playerpage, 'player options', default='{}'),
76 video_id, transform_source=js_to_json, fatal=False)
77 if options:
78 for key, tracks in options.get('tracks', {}).items():
79 if not isinstance(tracks, list):
80 continue
81 for track in tracks:
82 src = track.get('src')
83 if src:
84 extract_formats(src, key.lower(), track.get('lang'))
85
86 if not formats:
87 for _, src in re.findall(r'src["\']\s*:\s*(["\'])(.+?)\1', playerpage):
88 extract_formats(src)
91264ce5 89
3c6b3bf2 90 if not formats and '>GEO_IP_NOT_ALLOWED<' in playerpage:
da42ff06 91 self.raise_geo_restricted(countries=['CZ'])
3c6b3bf2 92
91264ce5 93 self._sort_formats(formats)
7881a644 94
95 return {
f406c787 96 'id': video_id,
97 'title': self._og_search_title(webpage),
7881a644 98 'thumbnail': self._og_search_thumbnail(webpage),
99 'formats': formats,
f406c787 100 'description': self._og_search_description(webpage),
91264ce5 101 }