[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / yle_areena.py
blobef9e96804c56bfaf34ccf6f07cc6a5ef56790e23
1 from .common import InfoExtractor
2 from .kaltura import KalturaIE
3 from ..utils import (
4 int_or_none,
5 smuggle_url,
6 traverse_obj,
7 unified_strdate,
8 url_or_none,
12 class YleAreenaIE(InfoExtractor):
13 _VALID_URL = r'https?://areena\.yle\.fi/(?P<id>[\d-]+)'
14 _GEO_COUNTRIES = ['FI']
15 _TESTS = [
17 'url': 'https://areena.yle.fi/1-4371942',
18 'md5': '932edda0ecf5dfd6423804182d32f8ac',
19 'info_dict': {
20 'id': '0_a3tjk92c',
21 'ext': 'mp4',
22 'title': 'Pouchit',
23 'description': 'md5:01071d7056ceec375f63960f90c35366',
24 'series': 'Modernit miehet',
25 'season': 'Season 1',
26 'season_number': 1,
27 'episode': 'Episode 2',
28 'episode_number': 2,
29 'thumbnail': 'http://cfvod.kaltura.com/p/1955031/sp/195503100/thumbnail/entry_id/0_a3tjk92c/version/100061',
30 'uploader_id': 'ovp@yle.fi',
31 'duration': 1435,
32 'view_count': int,
33 'upload_date': '20181204',
34 'release_date': '20190106',
35 'timestamp': 1543916210,
36 'subtitles': {'fin': [{'url': r're:^https?://', 'ext': 'srt'}]},
37 'age_limit': 7,
38 'webpage_url': 'https://areena.yle.fi/1-4371942',
42 'url': 'https://areena.yle.fi/1-2158940',
43 'md5': 'cecb603661004e36af8c5188b5212b12',
44 'info_dict': {
45 'id': '1_l38iz9ur',
46 'ext': 'mp4',
47 'title': 'Albi haluaa vessan',
48 'description': 'md5:15236d810c837bed861fae0e88663c33',
49 'series': 'Albi Lumiukko',
50 'thumbnail': 'http://cfvod.kaltura.com/p/1955031/sp/195503100/thumbnail/entry_id/1_l38iz9ur/version/100021',
51 'uploader_id': 'ovp@yle.fi',
52 'duration': 319,
53 'view_count': int,
54 'upload_date': '20211202',
55 'release_date': '20211215',
56 'timestamp': 1638448202,
57 'subtitles': {},
58 'age_limit': 0,
59 'webpage_url': 'https://areena.yle.fi/1-2158940',
63 'url': 'https://areena.yle.fi/1-64829589',
64 'info_dict': {
65 'id': '1-64829589',
66 'ext': 'mp4',
67 'title': 'HKO & Mälkki & Tanner',
68 'description': 'md5:b4f1b1af2c6569b33f75179a86eea156',
69 'series': 'Helsingin kaupunginorkesterin konsertteja',
70 'thumbnail': r're:^https?://.+\.jpg$',
71 'release_date': '20230120',
73 'params': {
74 'skip_download': 'm3u8',
79 def _real_extract(self, url):
80 video_id = self._match_id(url)
81 info = self._search_json_ld(self._download_webpage(url, video_id), video_id, default={})
82 video_data = self._download_json(
83 f'https://player.api.yle.fi/v1/preview/{video_id}.json?app_id=player_static_prod&app_key=8930d72170e48303cf5f3867780d549b',
84 video_id, headers={
85 'origin': 'https://areena.yle.fi',
86 'referer': 'https://areena.yle.fi/',
87 'content-type': 'application/json',
90 # Example title: 'K1, J2: Pouchit | Modernit miehet'
91 season_number, episode_number, episode, series = self._search_regex(
92 r'K(?P<season_no>\d+),\s*J(?P<episode_no>\d+):?\s*\b(?P<episode>[^|]+)\s*|\s*(?P<series>.+)',
93 info.get('title') or '', 'episode metadata', group=('season_no', 'episode_no', 'episode', 'series'),
94 default=(None, None, None, None))
95 description = traverse_obj(video_data, ('data', 'ongoing_ondemand', 'description', 'fin'), expected_type=str)
97 subtitles = {}
98 for sub in traverse_obj(video_data, ('data', 'ongoing_ondemand', 'subtitles', ...)):
99 if url_or_none(sub.get('uri')):
100 subtitles.setdefault(sub.get('language') or 'und', []).append({
101 'url': sub['uri'],
102 'ext': 'srt',
103 'name': sub.get('kind'),
106 kaltura_id = traverse_obj(video_data, ('data', 'ongoing_ondemand', 'kaltura', 'id'), expected_type=str)
107 if kaltura_id:
108 info_dict = {
109 '_type': 'url_transparent',
110 'url': smuggle_url(f'kaltura:1955031:{kaltura_id}', {'source_url': url}),
111 'ie_key': KalturaIE.ie_key(),
113 else:
114 formats, subs = self._extract_m3u8_formats_and_subtitles(
115 video_data['data']['ongoing_ondemand']['manifest_url'], video_id, 'mp4', m3u8_id='hls')
116 self._merge_subtitles(subs, target=subtitles)
117 info_dict = {
118 'id': video_id,
119 'formats': formats,
122 return {
123 **info_dict,
124 'title': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'title', 'fin'), expected_type=str)
125 or episode or info.get('title')),
126 'description': description,
127 'series': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'series', 'title', 'fin'), expected_type=str)
128 or series),
129 'season_number': (int_or_none(self._search_regex(r'Kausi (\d+)', description, 'season number', default=None))
130 or int_or_none(season_number)),
131 'episode_number': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'episode_number'), expected_type=int_or_none)
132 or int_or_none(episode_number)),
133 'thumbnails': traverse_obj(info, ('thumbnails', ..., {'url': 'url'})),
134 'age_limit': traverse_obj(video_data, ('data', 'ongoing_ondemand', 'content_rating', 'age_restriction'), expected_type=int_or_none),
135 'subtitles': subtitles or None,
136 'release_date': unified_strdate(traverse_obj(video_data, ('data', 'ongoing_ondemand', 'start_time'), expected_type=str)),