Repository: yt-dlp/yt-dlp

Issue:
YleAreena extractor error
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2023.01.06** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

United Kingdom

### Provide a description that is worded well enough to be understood

YleAreena extractor error

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['https://areena.yle.fi/1-64829589', '-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2023.01.06 [6becd25] (pip)
[debug] Python 3.10.9 (CPython x86_64 64bit) - Linux-5.15.89-1-lts-x86_64-with-glibc2.36 (OpenSSL 3.0.7 1 Nov 2022, glibc 2.36)
[debug] exe versions: ffmpeg 5.1.2 (setts), ffprobe 5.1.2, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.16.0, brotli-1.0.9, certifi-2022.12.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-10.4
[debug] Proxy map: {}
[debug] Loaded 1760 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2023.01.06, Current version: 2023.01.06
yt-dlp is up to date (2023.01.06)
[YleAreena] Extracting URL: https://areena.yle.fi/1-64829589
[YleAreena] 1-64829589: Downloading webpage
[YleAreena] 1-64829589: Downloading JSON metadata
ERROR: 1-64829589: An extractor error has occurred. (caused by KeyError('kaltura')); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/home/erwin/.local/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 680, in extract
    ie_result = self._real_extract(url)
  File "/home/erwin/.local/lib/python3.10/site-packages/yt_dlp/extractor/yle_areena.py", line 97, in _real_extract
    f'kaltura:1955031:{video_data["data"]["ongoing_ondemand"]["kaltura"]["id"]}',
KeyError: 'kaltura'
```



Discussion:
It seems that not all YleAreena videos are Kaltura videos. Something like this will work as a fix:
```diff
diff --git a/yt_dlp/extractor/yle_areena.py b/yt_dlp/extractor/yle_areena.py
index 98d3b1949..1389cb08a 100644
--- a/yt_dlp/extractor/yle_areena.py
+++ b/yt_dlp/extractor/yle_areena.py
@@ -91,12 +91,7 @@ def _real_extract(self, url):
                     'name': sub.get('kind'),
                 })
 
-        return {
-            '_type': 'url_transparent',
-            'url': smuggle_url(
-                f'kaltura:1955031:{video_data["data"]["ongoing_ondemand"]["kaltura"]["id"]}',
-                {'source_url': url}),
-            'ie_key': KalturaIE.ie_key(),
+        info_dict = {
             'title': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'title', 'fin'), expected_type=str)
                       or episode or info.get('title')),
             'description': description,
@@ -111,3 +106,19 @@ def _real_extract(self, url):
             'subtitles': subtitles,
             'release_date': unified_strdate(traverse_obj(video_data, ('data', 'ongoing_ondemand', 'start_time'), expected_type=str)),
         }
+
+        kaltura_id = traverse_obj(video_data, ('data', 'ongoing_ondemand', 'kaltura', 'id'), expected_type=str)
+        if kaltura_id:
+            info_dict.update({
+                '_type': 'url_transparent',
+                'url': smuggle_url(f'kaltura:1955031:{kaltura_id}', {'source_url': url}),
+                'ie_key': KalturaIE.ie_key(),
+            })
+        else:
+            info_dict.update({
+                'id': video_id,
+                'formats': self._extract_m3u8_formats(
+                    video_data['data']['ongoing_ondemand']['manifest_url'], video_id, 'mp4', m3u8_id='hls'),
+            })
+
+        return info_dict
```
Thanks! This solves the error.

Resolving patch:
diff --git a/yt_dlp/extractor/yle_areena.py b/yt_dlp/extractor/yle_areena.py
--- a/yt_dlp/extractor/yle_areena.py
+++ b/yt_dlp/extractor/yle_areena.py
@@ -61,7 +61,22 @@ class YleAreenaIE(InfoExtractor):
                 'age_limit': 0,
                 'webpage_url': 'https://areena.yle.fi/1-2158940'
             }
-        }
+        },
+        {
+            'url': 'https://areena.yle.fi/1-64829589',
+            'info_dict': {
+                'id': '1-64829589',
+                'ext': 'mp4',
+                'title': 'HKO & Mälkki & Tanner',
+                'description': 'md5:b4f1b1af2c6569b33f75179a86eea156',
+                'series': 'Helsingin kaupunginorkesterin konsertteja',
+                'thumbnail': r're:^https?://.+\.jpg$',
+                'release_date': '20230120',
+            },
+            'params': {
+                'skip_download': 'm3u8',
+            },
+        },
     ]
 
     def _real_extract(self, url):
@@ -91,12 +106,22 @@ def _real_extract(self, url):
                     'name': sub.get('kind'),
                 })
 
+        kaltura_id = traverse_obj(video_data, ('data', 'ongoing_ondemand', 'kaltura', 'id'), expected_type=str)
+        if kaltura_id:
+            info_dict = {
+                '_type': 'url_transparent',
+                'url': smuggle_url(f'kaltura:1955031:{kaltura_id}', {'source_url': url}),
+                'ie_key': KalturaIE.ie_key(),
+            }
+        else:
+            info_dict = {
+                'id': video_id,
+                'formats': self._extract_m3u8_formats(
+                    video_data['data']['ongoing_ondemand']['manifest_url'], video_id, 'mp4', m3u8_id='hls'),
+            }
+
         return {
-            '_type': 'url_transparent',
-            'url': smuggle_url(
-                f'kaltura:1955031:{video_data["data"]["ongoing_ondemand"]["kaltura"]["id"]}',
-                {'source_url': url}),
-            'ie_key': KalturaIE.ie_key(),
+            **info_dict,
             'title': (traverse_obj(video_data, ('data', 'ongoing_ondemand', 'title', 'fin'), expected_type=str)
                       or episode or info.get('title')),
             'description': description,


Test patch: