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

Code before:
        return self._download_json(
            f'https://rutube.ru/api/play/options/{video_id}/',
            video_id, 'Downloading options JSON',
            'Unable to download options JSON',
            headers=self.geo_verification_headers(), query=query)

    def _extract_formats_and_subtitles(self, options, video_id):
        formats = []
        subtitles = {}
        for format_id, format_url in options['video_balancer'].items():
            ext = determine_ext(format_url)
            if ext == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    format_url, video_id, 'mp4', m3u8_id=format_id, fatal=False)
                formats.extend(fmts)
                self._merge_subtitles(subs, target=subtitles)
            elif ext == 'f4m':
                formats.extend(self._extract_f4m_formats(
                    format_url, video_id, f4m_id=format_id, fatal=False))
            else:
                formats.append({
                    'url': format_url,
                    'format_id': format_id,
                })
        for hls_url in traverse_obj(options, ('live_streams', 'hls', ..., 'url', {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(hls_url, video_id, ext='mp4', fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)
        for caption in traverse_obj(options, ('captions', lambda _, v: url_or_none(v['file']))):
            subtitles.setdefault(caption.get('code') or 'ru', []).append({
                'url': caption['file'],
                'name': caption.get('langTitle'),
            })
        return formats, subtitles

    def _download_and_extract_formats_and_subtitles(self, video_id, query=None):
        return self._extract_formats_and_subtitles(
            self._download_api_options(video_id, query=query), video_id)


class RutubeIE(RutubeBaseIE):
    IE_NAME = 'rutube'
    IE_DESC = 'Rutube videos'
    _VALID_URL = r'https?://rutube\.ru/(?:(?:live/)?video(?:/private)?|(?:play/)?embed)/(?P<id>[\da-z]{32})'
    _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//rutube\.ru/(?:play/)?embed/[\da-z]{32}.*?)\1']

    _TESTS = [{
        'url': 'https://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/',
        'md5': '3d73fdfe5bb81b9aef139e22ef3de26a',
        'info_dict': {
            'id': '3eac3b4561676c17df9132a9a1e62e3e',

Review comment (refactor):
I know this is basically old code, but would be good to add an `m3u8_id`
```suggestion
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                hls_url, video_id, 'mp4', fatal=False, m3u8_id='hls')
```

Code after:
        return self._download_json(
            f'https://rutube.ru/api/play/options/{video_id}/',
            video_id, 'Downloading options JSON',
            'Unable to download options JSON',
            headers=self.geo_verification_headers(), query=query)

    def _extract_formats_and_subtitles(self, options, video_id):
        formats = []
        subtitles = {}
        for format_id, format_url in options['video_balancer'].items():
            ext = determine_ext(format_url)
            if ext == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    format_url, video_id, 'mp4', m3u8_id=format_id, fatal=False)
                formats.extend(fmts)
                self._merge_subtitles(subs, target=subtitles)
            elif ext == 'f4m':
                formats.extend(self._extract_f4m_formats(
                    format_url, video_id, f4m_id=format_id, fatal=False))
            else:
                formats.append({
                    'url': format_url,
                    'format_id': format_id,
                })
        for hls_url in traverse_obj(options, ('live_streams', 'hls', ..., 'url', {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                hls_url, video_id, 'mp4', fatal=False, m3u8_id='hls')
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)
        for caption in traverse_obj(options, ('captions', lambda _, v: url_or_none(v['file']))):
            subtitles.setdefault(caption.get('code') or 'ru', []).append({
                'url': caption['file'],
                'name': caption.get('langTitle'),
            })
        return formats, subtitles

    def _download_and_extract_formats_and_subtitles(self, video_id, query=None):
        return self._extract_formats_and_subtitles(
            self._download_api_options(video_id, query=query), video_id)


class RutubeIE(RutubeBaseIE):
    IE_NAME = 'rutube'
    IE_DESC = 'Rutube videos'
    _VALID_URL = r'https?://rutube\.ru/(?:(?:live/)?video(?:/private)?|(?:play/)?embed)/(?P<id>[\da-z]{32})'
    _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//rutube\.ru/(?:play/)?embed/[\da-z]{32}.*?)\1']

    _TESTS = [{
        'url': 'https://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/',
        'md5': '3d73fdfe5bb81b9aef139e22ef3de26a',
        'info_dict': {