]>
Commit | Line | Data |
---|---|---|
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, | |
9 | ) | |
10 | ||
11 | ||
12 | class YleAreenaIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://areena\.yle\.fi/(?P<id>[\d-]+)' | |
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 | 'thumbnail': 'http://cfvod.kaltura.com/p/1955031/sp/195503100/thumbnail/entry_id/1_l38iz9ur/version/100021', | |
50 | 'uploader_id': 'ovp@yle.fi', | |
51 | 'duration': 319, | |
52 | 'view_count': int, | |
53 | 'upload_date': '20211202', | |
54 | 'release_date': '20211215', | |
55 | 'timestamp': 1638448202, | |
56 | 'subtitles': {}, | |
57 | 'age_limit': 0, | |
58 | 'webpage_url': 'https://areena.yle.fi/1-2158940' | |
59 | } | |
60 | }, | |
61 | { | |
62 | 'url': 'https://areena.yle.fi/1-64829589', | |
63 | 'info_dict': { | |
64 | 'id': '1-64829589', | |
65 | 'ext': 'mp4', | |
66 | 'title': 'HKO & Mälkki & Tanner', | |
67 | 'description': 'md5:b4f1b1af2c6569b33f75179a86eea156', | |
68 | 'series': 'Helsingin kaupunginorkesterin konsertteja', | |
69 | 'thumbnail': r're:^https?://.+\.jpg$', | |
70 | 'release_date': '20230120', | |
71 | }, | |
72 | 'params': { | |
73 | 'skip_download': 'm3u8', | |
74 | }, | |
75 | }, | |
76 | ] | |
77 | ||
78 | def _real_extract(self, url): | |
79 | video_id = self._match_id(url) | |
80 | info = self._search_json_ld(self._download_webpage(url, video_id), video_id, default={}) | |
81 | video_data = self._download_json( | |
82 | f'https://player.api.yle.fi/v1/preview/{video_id}.json?app_id=player_static_prod&app_key=8930d72170e48303cf5f3867780d549b', | |
83 | video_id, headers={ | |
84 | 'origin': 'https://areena.yle.fi', | |
85 | 'referer': 'https://areena.yle.fi/', | |
86 | 'content-type': 'application/json' | |
87 | }) | |
88 | ||
89 | # Example title: 'K1, J2: Pouchit | Modernit miehet' | |
90 | series, season_number, episode_number, episode = self._search_regex( | |
91 | r'K(?P<season_no>[\d]+),\s*J(?P<episode_no>[\d]+):?\s*\b(?P<episode>[^|]+)\s*|\s*(?P<series>.+)', | |
92 | info.get('title') or '', 'episode metadata', group=('season_no', 'episode_no', 'episode', 'series'), | |
93 | default=(None, None, None, None)) | |
94 | description = traverse_obj(video_data, ('data', 'ongoing_ondemand', 'description', 'fin'), expected_type=str) | |
95 | ||
96 | subtitles = {} | |
97 | for sub in traverse_obj(video_data, ('data', 'ongoing_ondemand', 'subtitles', ...)): | |
98 | if url_or_none(sub.get('uri')): | |
99 | subtitles.setdefault(sub.get('language') or 'und', []).append({ | |
100 | 'url': sub['uri'], | |
101 | 'ext': 'srt', | |
102 | 'name': sub.get('kind'), | |
103 | }) | |
104 | ||
105 | kaltura_id = traverse_obj(video_data, ('data', 'ongoing_ondemand', 'kaltura', 'id'), expected_type=str) | |
106 | if kaltura_id: | |
107 | info_dict = { | |
108 | '_type': 'url_transparent', | |
109 | 'url': smuggle_url(f'kaltura:1955031:{kaltura_id}', {'source_url': url}), | |
110 | 'ie_key': KalturaIE.ie_key(), | |
111 | } | |
112 | else: | |
113 | info_dict = { | |
114 | 'id': video_id, | |
115 | 'formats': self._extract_m3u8_formats( | |
116 | video_data['data']['ongoing_ondemand']['manifest_url'], video_id, 'mp4', m3u8_id='hls'), | |
117 | } | |
118 | ||
119 | return { | |
120 | **info_dict, | |
121 | 'title': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'title', 'fin'), expected_type=str) | |
122 | or episode or info.get('title')), | |
123 | 'description': description, | |
124 | 'series': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'series', 'title', 'fin'), expected_type=str) | |
125 | or series), | |
126 | 'season_number': (int_or_none(self._search_regex(r'Kausi (\d+)', description, 'season number', default=None)) | |
127 | or int_or_none(season_number)), | |
128 | 'episode_number': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'episode_number'), expected_type=int_or_none) | |
129 | or int_or_none(episode_number)), | |
130 | 'thumbnails': traverse_obj(info, ('thumbnails', ..., {'url': 'url'})), | |
131 | 'age_limit': traverse_obj(video_data, ('data', 'ongoing_ondemand', 'content_rating', 'age_restriction'), expected_type=int_or_none), | |
132 | 'subtitles': subtitles, | |
133 | 'release_date': unified_strdate(traverse_obj(video_data, ('data', 'ongoing_ondemand', 'start_time'), expected_type=str)), | |
134 | } |