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