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

Code before:
            'h264': 2,
            'low': 1,
        }
        formats.extend([
            {
                'format_id': quality,
                'url': quality_meta.get('hlsaddr')[0],
                'ext': 'mp4',
                'vcodec': vcodec,
                'quality': quality_priority[quality],
            },
            {
                'format_id': f'{quality}-rtmp',
                'url': quality_meta.get('streamaddr')[0],
                'ext': 'mp4',
                'vcodec': vcodec,
                'quality': quality_priority[quality] - 5,
            },
            {
                'format_id': f'{quality}-audioonly',
                'url': quality_meta.get('hlsaddr_audioonly')[0],
                'ext': 'aac',
                'vcodec': 'none',
                'quality': quality_priority[quality] - 10,
            },
        ])

    def _real_extract(self, url):
        video_id = self._match_id(url)
        html = self._download_webpage(url, video_id)

        title = clean_html(get_element_by_id('livetitle', html.replace('<SPAN', '<span').replace('SPAN>', 'span>')))
        description = self._html_search_meta('Description', html)
        thumbnail = self._html_search_meta(['og:image', 'twitter:image'], html)

        is_live_stream = 'var timeshift = false;' in html
        is_vod = 'var timeshift = true;' in html

        if is_live_stream:
            qualities = [
                ('high', 'Z'),
                ('low', 'ForceLow'),
            ]
            formats = []
            for (desc, code) in qualities:
                quality_meta = self._get_quality_meta(video_id, desc, code)
                self._add_quality_formats(formats, quality_meta)
                if desc == 'high' and quality_meta.get('vcodec')[0] == 'HEVC':
                    h264_meta = self._get_quality_meta(video_id, desc, code, force_h264='1')
                    self._add_quality_formats(formats, h264_meta)


Review comment (suggestion):
From my testing, RTMP doesn't work. Can you report something different?
```suggestion
        vcodec = traverse_obj(quality_meta, ('vcodec', 0))
        quality = traverse_obj(quality_meta, ('now_quality', 0))
        quality_priority = {
            'high': 3,
            'h264': 2,
            'low': 1,
        }.get(quality, 0)
        if traverse_obj(quality_meta, ('hlsaddr', 0, {url_or_none})):
            formats.append({
                'format_id': quality,
                'url': quality_meta['hlsaddr'][0],
                'ext': 'mp4',
                'vcodec': vcodec,
                'quality': quality_priority,
            })
        if traverse_obj(quality_meta, ('hlsaddr_audioonly', 0, {url_or_none})):
            formats.append({
                'format_id': f'{quality}-audioonly',
                'url': quality_meta['hlsaddr_audioonly'][0],
                'ext': 'm4a',
                'vcodec': 'none',
                'quality': quality_priority,
            })
```

Code after:
        'info_dict': {
            'id': '102338092',
            'ext': 'mp4',
            'title': 'Among Usで遊びます！！',
            'description': 'VTuberになりましたねんねこ㌨ですよろしくお願いします',
            'timestamp': 1704603118,
            'upload_date': '20240107',
            'thumbnail': r're:^https?://.*',
        },
    }, {
        'url': 'https://live.erinn.biz/live.php?h878049531',
        'only_matching': True,
    }]

    def _get_quality_meta(self, video_id, desc, code, force_h264=None):
        desc += ' (force_h264)' if force_h264 else ''
        qs = self._download_webpage(
            'https://live.erinn.biz/live.player.fplayer.php', video_id,
            f'Downloading {desc} quality metadata', f'Unable to download {desc} quality metadata',
            query=filter_dict({
                'hash': video_id,
                'action': f'get{code}liveByAjax',
                'force_h264': force_h264,
            }))
        return urllib.parse.parse_qs(qs)

    def _add_quality_formats(self, formats, quality_meta):
        vcodec = traverse_obj(quality_meta, ('vcodec', 0, {str}))
        quality = traverse_obj(quality_meta, ('now_quality', 0, {str}))
        quality_priority = qualities(('low', 'h264', 'high'))(quality)
        if traverse_obj(quality_meta, ('hlsaddr', 0, {url_or_none})):
            formats.append({
                'format_id': quality,
                'url': quality_meta['hlsaddr'][0],
                'ext': 'mp4',
                'vcodec': vcodec,
                'quality': quality_priority,
            })
        if traverse_obj(quality_meta, ('hlsaddr_audioonly', 0, {url_or_none})):
            formats.append({
                'format_id': join_nonempty(quality, 'audioonly'),
                'url': quality_meta['hlsaddr_audioonly'][0],
                'ext': 'm4a',
                'vcodec': 'none',
                'quality': quality_priority,
            })

    def _real_extract(self, url):
        video_id = self._match_id(url)
        html = self._download_webpage(url, video_id)