Repository: yt-dlp/yt-dlp

Issue:
Unable to download from ondemandkorea.com
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

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

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I'm running yt-dlp version **2023.10.13** ([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 [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and 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

india

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

yt-dlp --version
2023.10.13



### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
$ yt-dlp -vU 'https://www.ondemandkorea.com/en/player/vod/joint-security-area?contentId=464622'
[debug] Command-line config: ['-vU', 'https://www.ondemandkorea.com/en/player/vod/joint-security-area?contentId=464622']
[debug] Encodings: locale utf-8, fs utf-8, pref utf-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.10.13 [b634ba742] (pip)
[debug] Python 3.11.6 (CPython aarch64 64bit) - Linux-4.19.157-perf-27101688-abA235FXXU4CWH1-aarch64-with-libc (OpenSSL 3.1.3 19 Sep 2023, libc)
[debug] exe versions: ffmpeg 6.0 (setts), ffprobe 6.0
[debug] Optional libraries: Cryptodome-3.19.0, brotli-1.1.0, certifi-2023.07.22, mutagen-1.47.0, sqlite3-3.43.1, websockets-11.0.3
[debug] Proxy map: {}
[debug] Loaded 1890 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.10.13, Current version: stable@2023.10.13
yt-dlp is up to date (stable@2023.10.13)
[generic] Extracting URL: https://www.ondemandkorea.com/en/player/vod/joint-security-area?contentId=464622
[generic] joint-security-area?contentId=464622: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] joint-security-area?contentId=464622: Extracting information
[debug] Looking for embeds
ERROR: Unsupported URL: https://www.ondemandkorea.com/en/player/vod/joint-security-area?contentId=464622
Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 1567, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 1702, in __extract_info
    ie_result = ie.extract(url)
                ^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/yt_dlp/extractor/common.py", line 715, in extract
    ie_result = self._real_extract(url)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/yt_dlp/extractor/generic.py", line 2575, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://www.ondemandkorea.com/en/player/vod/joint-security-area?contentId=464622
```



Discussion:
https://odkmedia.io/odx/api/v3/playback/463950/?did=0bca6495-ffb7-4984-935e-5d2e5809838b
api, 463950 is contentId from the url
not sure where the `did` comes from but it doesnt seem to be required
needs `Service-Name` header set by the site (`odk`)
There already is an `OnDemandKoreaIE`, just looks like it needs a total rewrite

Resolving patch:
diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py
--- a/yt_dlp/extractor/_extractors.py
+++ b/yt_dlp/extractor/_extractors.py
@@ -1387,7 +1387,10 @@
 from .oktoberfesttv import OktoberfestTVIE
 from .olympics import OlympicsReplayIE
 from .on24 import On24IE
-from .ondemandkorea import OnDemandKoreaIE
+from .ondemandkorea import (
+    OnDemandKoreaIE,
+    OnDemandKoreaProgramIE,
+)
 from .onefootball import OneFootballIE
 from .onenewsnz import OneNewsNZIE
 from .oneplace import OnePlacePodcastIE
diff --git a/yt_dlp/extractor/ondemandkorea.py b/yt_dlp/extractor/ondemandkorea.py
--- a/yt_dlp/extractor/ondemandkorea.py
+++ b/yt_dlp/extractor/ondemandkorea.py
@@ -1,87 +1,167 @@
+import functools
 import re
+import uuid
 
 from .common import InfoExtractor
+from ..networking import HEADRequest
 from ..utils import (
     ExtractorError,
-    js_to_json,
+    OnDemandPagedList,
+    float_or_none,
+    int_or_none,
+    join_nonempty,
+    parse_age_limit,
+    parse_qs,
+    unified_strdate,
+    url_or_none,
 )
+from ..utils.traversal import traverse_obj
 
 
 class OnDemandKoreaIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?P<id>[^/]+)\.html'
+    _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?:en/)?player/vod/[a-z0-9-]+\?(?:[^#]+&)?contentId=(?P<id>\d+)'
     _GEO_COUNTRIES = ['US', 'CA']
+
     _TESTS = [{
-        'url': 'https://www.ondemandkorea.com/ask-us-anything-e351.html',
+        'url': 'https://www.ondemandkorea.com/player/vod/ask-us-anything?contentId=686471',
+        'md5': 'e2ff77255d989e3135bde0c5889fbce8',
         'info_dict': {
-            'id': 'ask-us-anything-e351',
+            'id': '686471',
             'ext': 'mp4',
-            'title': 'Ask Us Anything : Jung Sung-ho, Park Seul-gi, Kim Bo-min, Yang Seung-won - 09/24/2022',
-            'description': 'A talk show/game show with a school theme where celebrity guests appear as “transfer students.”',
-            'thumbnail': r're:^https?://.*\.jpg$',
+            'title': 'Ask Us Anything: Jung Sung-ho, Park Seul-gi, Kim Bo-min, Yang Seung-won',
+            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)',
+            'duration': 5486.955,
+            'release_date': '20220924',
+            'series': 'Ask Us Anything',
+            'series_id': 11790,
+            'episode_number': 351,
+            'episode': 'Jung Sung-ho, Park Seul-gi, Kim Bo-min, Yang Seung-won',
         },
-        'params': {
-            'skip_download': 'm3u8 download'
-        }
     }, {
-        'url': 'https://www.ondemandkorea.com/work-later-drink-now-e1.html',
+        'url': 'https://www.ondemandkorea.com/player/vod/breakup-probation-a-week?contentId=1595796',
+        'md5': '57266c720006962be7ff415b24775caa',
         'info_dict': {
-            'id': 'work-later-drink-now-e1',
+            'id': '1595796',
             'ext': 'mp4',
-            'title': 'Work Later, Drink Now : E01',
-            'description': 'Work Later, Drink First follows three women who find solace in a glass of liquor at the end of the day. So-hee, who gets comfort from a cup of soju af',
-            'thumbnail': r're:^https?://.*\.png$',
-            'subtitles': {
-                'English': 'mincount:1',
-            },
+            'title': 'Breakup Probation, A Week: E08',
+            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)',
+            'duration': 1586.0,
+            'release_date': '20231001',
+            'series': 'Breakup Probation, A Week',
+            'series_id': 22912,
+            'episode_number': 8,
+            'episode': 'E08',
         },
-        'params': {
-            'skip_download': 'm3u8 download'
-        }
+    }, {
+        'url': 'https://www.ondemandkorea.com/player/vod/the-outlaws?contentId=369531',
+        'md5': 'fa5523b87aa1f6d74fc622a97f2b47cd',
+        'info_dict': {
+            'id': '369531',
+            'ext': 'mp4',
+            'release_date': '20220519',
+            'duration': 7267.0,
+            'title': 'The Outlaws: Main Movie',
+            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)',
+            'age_limit': 18,
+        },
+    }, {
+        'url': 'https://www.ondemandkorea.com/en/player/vod/capture-the-moment-how-is-that-possible?contentId=1605006',
+        'only_matching': True,
     }]
 
     def _real_extract(self, url):
         video_id = self._match_id(url)
-        webpage = self._download_webpage(url, video_id, fatal=False)
-
-        if not webpage:
-            # Page sometimes returns captcha page with HTTP 403
-            raise ExtractorError(
-                'Unable to access page. You may have been blocked.',
-                expected=True)
-
-        if 'msg_block_01.png' in webpage:
-            self.raise_geo_restricted(
-                msg='This content is not available in your region',
-                countries=self._GEO_COUNTRIES)
-
-        if 'This video is only available to ODK PLUS members.' in webpage:
-            raise ExtractorError(
-                'This video is only available to ODK PLUS members.',
-                expected=True)
-
-        if 'ODK PREMIUM Members Only' in webpage:
-            raise ExtractorError(
-                'This video is only available to ODK PREMIUM members.',
-                expected=True)
-
-        title = self._search_regex(
-            r'class=["\']episode_title["\'][^>]*>([^<]+)',
-            webpage, 'episode_title', fatal=False) or self._og_search_title(webpage)
-
-        jw_config = self._parse_json(
-            self._search_regex((
-                r'(?P<options>{\s*[\'"]tracks[\'"].*?})[)\];]+$',
-                r'playlist\s*=\s*\[(?P<options>.+)];?$',
-                r'odkPlayer\.init.*?(?P<options>{[^;]+}).*?;',
-            ), webpage, 'jw config', flags=re.MULTILINE | re.DOTALL, group='options'),
-            video_id, transform_source=js_to_json)
-        info = self._parse_jwplayer_data(
-            jw_config, video_id, require_title=False, m3u8_id='hls',
-            base_url=url)
-
-        info.update({
-            'title': title,
-            'description': self._og_search_description(webpage),
-            'thumbnail': self._og_search_thumbnail(webpage)
-        })
-        return info
+
+        data = self._download_json(
+            f'https://odkmedia.io/odx/api/v3/playback/{video_id}/', video_id, fatal=False,
+            headers={'service-name': 'odk'}, query={'did': str(uuid.uuid4())}, expected_status=(403, 404))
+        if not traverse_obj(data, ('result', {dict})):
+            msg = traverse_obj(data, ('messages', '__default'), 'title', expected_type=str)
+            raise ExtractorError(msg or 'Got empty response from playback API', expected=True)
+
+        data = data['result']
+
+        def try_geo_bypass(url):
+            return traverse_obj(url, ({parse_qs}, 'stream_url', 0, {url_or_none})) or url
+
+        def try_upgrade_quality(url):
+            mod_url = re.sub(r'_720(p?)\.m3u8', r'_1080\1.m3u8', url)
+            return mod_url if mod_url != url and self._request_webpage(
+                HEADRequest(mod_url), video_id, note='Checking for higher quality format',
+                errnote='No higher quality format found', fatal=False) else url
+
+        formats = []
+        for m3u8_url in traverse_obj(data, (('sources', 'manifest'), ..., 'url', {url_or_none}, {try_geo_bypass})):
+            formats.extend(self._extract_m3u8_formats(try_upgrade_quality(m3u8_url), video_id, fatal=False))
+
+        subtitles = {}
+        for track in traverse_obj(data, ('text_tracks', lambda _, v: url_or_none(v['url']))):
+            subtitles.setdefault(track.get('language', 'und'), []).append({
+                'url': track['url'],
+                'ext': track.get('codec'),
+                'name': track.get('label'),
+            })
+
+        def if_series(key=None):
+            return lambda obj: obj[key] if key and obj['kind'] == 'series' else None
+
+        return {
+            'id': video_id,
+            'title': join_nonempty(
+                ('episode', 'program', 'title'),
+                ('episode', 'title'), from_dict=data, delim=': '),
+            **traverse_obj(data, {
+                'thumbnail': ('episode', 'images', 'thumbnail', {url_or_none}),
+                'release_date': ('episode', 'release_date', {lambda x: x.replace('-', '')}, {unified_strdate}),
+                'duration': ('duration', {functools.partial(float_or_none, scale=1000)}),
+                'age_limit': ('age_rating', 'name', {lambda x: x.replace('R', '')}, {parse_age_limit}),
+                'series': ('episode', {if_series(key='program')}, 'title'),
+                'series_id': ('episode', {if_series(key='program')}, 'id'),
+                'episode': ('episode', {if_series(key='title')}),
+                'episode_number': ('episode', {if_series(key='number')}, {int_or_none}),
+            }, get_all=False),
+            'formats': formats,
+            'subtitles': subtitles,
+        }
+
+
+class OnDemandKoreaProgramIE(InfoExtractor):
+    _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?:en/)?player/vod/(?P<id>[a-z0-9-]+)(?:$|#)'
+    _GEO_COUNTRIES = ['US', 'CA']
+
+    _TESTS = [{
+        'url': 'https://www.ondemandkorea.com/player/vod/uskn-news',
+        'info_dict': {
+            'id': 'uskn-news',
+        },
+        'playlist_mincount': 755,
+    }, {
+        'url': 'https://www.ondemandkorea.com/en/player/vod/the-land',
+        'info_dict': {
+            'id': 'the-land',
+        },
+        'playlist_count': 52,
+    }]
+
+    _PAGE_SIZE = 100
+
+    def _fetch_page(self, display_id, page):
+        page += 1
+        page_data = self._download_json(
+            f'https://odkmedia.io/odx/api/v3/program/{display_id}/episodes/', display_id,
+            headers={'service-name': 'odk'}, query={
+                'page': page,
+                'page_size': self._PAGE_SIZE,
+            }, note=f'Downloading page {page}', expected_status=404)
+        for episode in traverse_obj(page_data, ('result', 'results', ...)):
+            yield self.url_result(
+                f'https://www.ondemandkorea.com/player/vod/{display_id}?contentId={episode["id"]}',
+                ie=OnDemandKoreaIE, video_title=episode.get('title'))
+
+    def _real_extract(self, url):
+        display_id = self._match_id(url)
+
+        entries = OnDemandPagedList(functools.partial(
+            self._fetch_page, display_id), self._PAGE_SIZE)
+
+        return self.playlist_result(entries, display_id)


Test patch: