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

Code before:

        player_data_str = self._html_search_regex(
            r'mtva_player_manager\.player\(document.getElementById\(.*\),\s?(\{.*\}).*\);', webpage, 'player data')
        player_data = self._parse_json(player_data_str, display_id, urllib.parse.unquote)
        video_id = str(player_data['contentId'])
        title = player_data.get('title') or self._og_search_title(webpage, fatal=False) or \
            self._html_search_regex(r'<h\d+\b[^>]+\bclass="article_title">([^<]+)<', webpage, 'title')

        upload_date = unified_strdate(
            '{}-{}-{}'.format(mobj.group('year'), mobj.group('month'), mobj.group('day')))
        if not upload_date:
            upload_date = unified_strdate(self._html_search_regex(
                r'<p+\b[^>]+\bclass="article_date">([^<]+)<', webpage, 'upload date', default=None))

        player_data['video'] = player_data.pop('token')
        player_page = self._download_webpage(
            'https://player.mediaklikk.hu/playernew/player.php', video_id,
            query=player_data, headers={'Referer': url})
        player_json = self._search_json(
            r'\bpl\.setup\s*\(', player_page, 'player json', video_id, end_pattern=r'\);')
        playlist_url = traverse_obj(
            player_json, ('playlist', lambda _, v: v['type'] == 'hls', 'file', {url_or_none}), get_all=False)
        if not playlist_url:
            raise ExtractorError('Unable to extract playlist url')

        formats = self._extract_m3u8_formats(playlist_url, video_id)

        return {
            'id': video_id,
            'title': title,
            'display_id': display_id,
            'formats': formats,
            'upload_date': upload_date,
            'thumbnail': player_data.get('bgImage') or self._og_search_thumbnail(webpage),
        }


Review comment (refactor):
we could do this pre-emptively
```suggestion
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(playlist_url, video_id)
```
and then make sure to return `subtitles` below

Code after:
            'id': '6713233',
            'title': 'Futball Fesztivál a Margitszigeten',
            'display_id': 'futball-fesztival-a-margitszigeten',
            'ext': 'mp4',
            'upload_date': '20230909',
            'thumbnail': 'https://petofilive.hu/wp-content/uploads/sites/4/2023/09/Clipboard11-2.jpg',
        },
        'skip': 'Webpage redirects to video list page',
    }]

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        display_id = mobj.group('id')
        webpage = self._download_webpage(url, display_id)

        player_data_str = self._html_search_regex(
            r'mtva_player_manager\.player\(document.getElementById\(.*\),\s?(\{.*\}).*\);', webpage, 'player data')
        player_data = self._parse_json(player_data_str, display_id, urllib.parse.unquote)
        video_id = str(player_data['contentId'])
        title = player_data.get('title') or self._og_search_title(webpage, fatal=False) or \
            self._html_search_regex(r'<h\d+\b[^>]+\bclass="article_title">([^<]+)<', webpage, 'title')

        upload_date = unified_strdate(
            '{}-{}-{}'.format(mobj.group('year'), mobj.group('month'), mobj.group('day')))
        if not upload_date:
            upload_date = unified_strdate(self._html_search_regex(
                r'<p+\b[^>]+\bclass="article_date">([^<]+)<', webpage, 'upload date', default=None))

        player_data['video'] = player_data.pop('token')
        player_page = self._download_webpage(
            'https://player.mediaklikk.hu/playernew/player.php', video_id,
            query=player_data, headers={'Referer': url})
        player_json = self._search_json(
            r'\bpl\.setup\s*\(', player_page, 'player json', video_id, end_pattern=r'\);')
        playlist_url = traverse_obj(
            player_json, ('playlist', lambda _, v: v['type'] == 'hls', 'file', {url_or_none}), get_all=False)
        if not playlist_url:
            raise ExtractorError('Unable to extract playlist url')

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(playlist_url, video_id)

        return {
            'id': video_id,
            'title': title,
            'display_id': display_id,
            'formats': formats,
            'subtitles': subtitles,
            'upload_date': upload_date,
            'thumbnail': player_data.get('bgImage') or self._og_search_thumbnail(webpage),
        }