1 from .common
import InfoExtractor
2 from .kaltura
import KalturaIE
10 from ..utils
.traversal
import traverse_obj
13 class YleAreenaIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://areena\.yle\.fi/(?P<podcast>podcastit/)?(?P<id>[\d-]+)'
15 _GEO_COUNTRIES
= ['FI']
18 'url': 'https://areena.yle.fi/1-4371942',
19 'md5': 'd87e9a1e74e67e009990ddd413e426b4',
24 'description': 'md5:01071d7056ceec375f63960f90c35366',
25 'series': 'Modernit miehet',
28 'episode': 'Episode 2',
30 'thumbnail': r
're:https://images\.cdn\.yle\.fi/image/upload/.+\.jpg',
32 'release_date': '20190105',
33 'release_timestamp': 1546725660,
38 'url': 'https://areena.yle.fi/1-2158940',
39 'md5': '6369ddc5e07b5fdaeda27a495184143c',
43 'title': 'Albi haluaa vessan',
44 'description': 'Albi haluaa vessan.',
45 'series': 'Albi Lumiukko',
46 'thumbnail': r
're:https://images\.cdn\.yle\.fi/image/upload/.+\.jpg',
48 'release_date': '20211215',
49 'release_timestamp': 1639555200,
54 'url': 'https://areena.yle.fi/1-64829589',
58 'title': 'HKO & Mälkki & Tanner',
59 'description': 'md5:b4f1b1af2c6569b33f75179a86eea156',
60 'series': 'Helsingin kaupunginorkesterin konsertteja',
61 'thumbnail': r
're:https://images\.cdn\.yle\.fi/image/upload/.+\.jpg',
62 'release_date': '20230120',
63 'release_timestamp': 1674242079,
67 'skip_download': 'm3u8',
71 'url': 'https://areena.yle.fi/1-72251830',
75 'title': r
're:Pentulive 2024 | Pentulive \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
76 'description': 'md5:1f118707d9093bf894a34fbbc865397b',
77 'series': 'Pentulive',
78 'thumbnail': r
're:https://images\.cdn\.yle\.fi/image/upload/.+\.jpg',
79 'live_status': 'is_live',
80 'release_date': '20241025',
81 'release_timestamp': 1729875600,
84 'skip_download': 'livestream',
88 'url': 'https://areena.yle.fi/podcastit/1-71022852',
92 'title': 'Värityspäivä',
93 'description': 'md5:c3a02b0455ec71d32cbe09d32ec161e2',
94 'series': 'Murun ja Paukun ikioma kaupunki',
95 'episode': 'Episode 1',
97 'release_date': '20240607',
98 'release_timestamp': 1717736400,
104 def _real_extract(self
, url
):
105 video_id
, is_podcast
= self
._match
_valid
_url
(url
).group('id', 'podcast')
106 json_ld
= self
._search
_json
_ld
(self
._download
_webpage
(url
, video_id
), video_id
, default
={})
107 video_data
= self
._download
_json
(
108 f
'https://player.api.yle.fi/v1/preview/{video_id}.json?app_id=player_static_prod&app_key=8930d72170e48303cf5f3867780d549b',
110 'origin': 'https://areena.yle.fi',
111 'referer': 'https://areena.yle.fi/',
112 'content-type': 'application/json',
115 # Example title: 'K1, J2: Pouchit | Modernit miehet'
116 season_number
, episode_number
, episode
, series
= self
._search
_regex
(
117 r
'K(?P<season_no>\d+),\s*J(?P<episode_no>\d+):?\s*\b(?P<episode>[^|]+)\s*|\s*(?P<series>.+)',
118 json_ld
.get('title') or '', 'episode metadata', group
=('season_no', 'episode_no', 'episode', 'series'),
119 default
=(None, None, None, None))
120 description
= traverse_obj(video_data
, ('ongoing_ondemand', 'description', 'fin', {str}
))
123 for sub
in traverse_obj(video_data
, ('ongoing_ondemand', 'subtitles', lambda _
, v
: url_or_none(v
['uri']))):
124 subtitles
.setdefault(sub
.get('language') or 'und', []).append({
127 'name': sub
.get('kind'),
130 info_dict
, metadata
= {}, {}
131 if is_podcast
and traverse_obj(video_data
, ('ongoing_ondemand', 'media_url', {url_or_none}
)):
132 metadata
= video_data
['ongoing_ondemand']
133 info_dict
['url'] = metadata
['media_url']
134 elif traverse_obj(video_data
, ('ongoing_event', 'manifest_url', {url_or_none}
)):
135 metadata
= video_data
['ongoing_event']
136 metadata
.pop('duration', None) # Duration is not accurate for livestreams
137 info_dict
['live_status'] = 'is_live'
138 elif traverse_obj(video_data
, ('ongoing_ondemand', 'manifest_url', {url_or_none}
)):
139 metadata
= video_data
['ongoing_ondemand']
140 # XXX: Has all externally-hosted Kaltura content been moved to native hosting?
141 elif kaltura_id
:= traverse_obj(video_data
, ('ongoing_ondemand', 'kaltura', 'id', {str}
)):
142 metadata
= video_data
['ongoing_ondemand']
144 '_type': 'url_transparent',
145 'url': smuggle_url(f
'kaltura:1955031:{kaltura_id}', {'source_url': url
}),
146 'ie_key': KalturaIE
.ie_key(),
148 elif traverse_obj(video_data
, ('gone', {dict}
)):
149 self
.raise_no_formats('The content is no longer available', expected
=True, video_id
=video_id
)
150 metadata
= video_data
['gone']
152 raise ExtractorError('Unable to extract content')
154 if not info_dict
.get('url') and metadata
.get('manifest_url'):
155 info_dict
['formats'], subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
156 metadata
['manifest_url'], video_id
, 'mp4', m3u8_id
='hls')
157 self
._merge
_subtitles
(subs
, target
=subtitles
)
160 **traverse_obj(json_ld
, {
162 'thumbnails': ('thumbnails', ..., {'url': 'url'}),
166 'description': description
,
168 'season_number': (int_or_none(self
._search
_regex
(r
'Kausi (\d+)', description
, 'season number', default
=None))
169 or int_or_none(season_number
)),
170 'episode_number': int_or_none(episode_number
),
171 'subtitles': subtitles
or None,
172 **traverse_obj(metadata
, {
173 'title': ('title', 'fin', {str}
),
174 'description': ('description', 'fin', {str}
),
175 'series': ('series', 'title', 'fin', {str}
),
176 'episode_number': ('episode_number', {int_or_none}
),
177 'age_limit': ('content_rating', 'age_restriction', {int_or_none}
),
178 'release_timestamp': ('start_time', {parse_iso8601}
),
179 'duration': ('duration', 'duration_in_seconds', {int_or_none}
),