Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/ondemandkorea.py (Python)

Code before:
        data = self._download_json(f'https://odkmedia.io/odx/api/v3/playback/{video_id}/', video_id,
                                   fatal=False, headers={'service-name': 'odk'},
                                   query={'did': random_uuidv4()}, expected_status=(403, 404))
        if not data.get('result'):
            raise ExtractorError(traverse_obj(data, ('messages', '__default'), 'title'), expected=True)

        potential_urls = traverse_obj(data, ('result', ('sources', 'manifest'), ..., 'url'))
        # Try to bypass geo-restricted ad proxy
        potential_urls = [
            alt_url if (alt_url := traverse_obj(url, ({parse_qs}, 'stream_url', 0, {url_or_none}))) else url
            for url in potential_urls
        ]
        # Try to upgrade quality
        potential_urls = [
            mod_url if self._request_webpage(
                HEADRequest(mod_url := re.sub(r'_720(p?)\.m3u8', r'_1080\1.m3u8', url)), video_id,
                note='Checking if higher quality format is available', fatal=False) else url
            for url in potential_urls
        ]

        formats = []
        for url in potential_urls:
            formats.extend(self._extract_m3u8_formats(url, video_id, fatal=False))

        subtitles = {}
        for track in traverse_obj(data, ('result', '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'),
            })

        return {
            'id': video_id,
            'title': join_nonempty(
                ('result', 'episode', 'program', 'title'),
                ('result', 'episode', 'title'), from_dict=data, delim=': '),
            **traverse_obj(data, ('result', {
                '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', {lambda x: x['program'] if x['kind'] == 'series' else None}, 'title'),
                'series_id': ('episode', {lambda x: x['program'] if x['kind'] == 'series' else None}, 'id'),
                'episode': ('episode', {lambda x: x['title'] if x['kind'] == 'series' else None},),
                'episode_number': ('episode', {lambda x: x['number'] if x['kind'] == 'series' else None}, {int_or_none}),
            }), get_all=False),
            'formats': formats,
            'subtitles': subtitles,
        }


Review comment (suggestion):
if the `data['result']` suggestion from above is applied
```suggestion
        for track in traverse_obj(data, ('text_tracks', lambda _, v: url_or_none(v['url']))):
```

Code after:
    def _real_extract(self, url):
        video_id = self._match_id(url)

        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),