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

Code before:
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(
                        src, video_id, 'mp4', entry_protocol='m3u8_native',
                        m3u8_id='hls', fatal=False)
                    formats.extend(fmts)
                    self._merge_subtitles(subs, target=subtitles)
                else:
                    formats.append({
                        'url': src,
                        'ext': (mimetype2ext(src_type)
                                or ext if ext in KNOWN_EXTENSIONS else 'mp4'),
                        'http_headers': {
                            'Referer': full_response.geturl(),
                        },
                    })
            # https://docs.videojs.com/player#addRemoteTextTrack
            # https://html.spec.whatwg.org/multipage/media.html#htmltrackelement
            for sub_match in re.finditer(rf'(?s){re.escape(varname)}' r'\.addRemoteTextTrack\(({.+?})\s*(?:,\s*(?:true|false))\)', webpage):
                sub = self._parse_json(
                    sub_match.group(1), video_id, transform_source=js_to_json,
                    fatal=False)
                if not sub or not isinstance(sub, dict):
                    continue
                src = sub.get('src')
                if not src or not isinstance(src, str):
                    continue
                subtitles.setdefault(sub.get('language') or sub.get('srclang') or 'und', []).append({
                    'url': compat_urlparse.urljoin(url, src),
                    'name': sub.get('label'),
                    'http_headers': {
                        'Referer': full_response.geturl(),
                    },
                })
            if formats or subtitles:
                self.report_detected('video.js embed')
                self._sort_formats(formats)
                info_dict['formats'] = formats
                info_dict['subtitles'] = subtitles
                return info_dict

        # Looking for http://schema.org/VideoObject
        json_ld = self._search_json_ld(webpage, video_id, default={})
        if json_ld.get('url') not in (url, None):
            self.report_detected('JSON LD')
            if determine_ext(json_ld['url']) == 'm3u8':
                json_ld['formats'], json_ld['subtitles'] = self._extract_m3u8_formats_and_subtitles(
                    json_ld['url'], video_id, 'mp4')
                json_ld.pop('url')
                self._sort_formats(json_ld['formats'])
            else:
                json_ld['_type'] = 'url_transparent'
                json_ld['url'] = smuggle_url(json_ld['url'], {'force_videoid': video_id, 'to_generic': True})

Review comment (suggestion):
```suggestion
                subtitles.setdefault(dict_get(sub, ('language', 'srclang')) or 'und', []).append({
```

Code after:
                    self._merge_subtitles(subs, target=subtitles)
                elif src_type == 'application/x-mpegurl' or ext == 'm3u8':
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(
                        src, video_id, 'mp4', entry_protocol='m3u8_native',
                        m3u8_id='hls', fatal=False)
                    formats.extend(fmts)
                    self._merge_subtitles(subs, target=subtitles)
                else:
                    formats.append({
                        'url': src,
                        'ext': (mimetype2ext(src_type)
                                or ext if ext in KNOWN_EXTENSIONS else 'mp4'),
                        'http_headers': {
                            'Referer': full_response.geturl(),
                        },
                    })
            # https://docs.videojs.com/player#addRemoteTextTrack
            # https://html.spec.whatwg.org/multipage/media.html#htmltrackelement
            for sub_match in re.finditer(rf'(?s){re.escape(varname)}' r'\.addRemoteTextTrack\(({.+?})\s*,\s*(?:true|false)\)', webpage):
                sub = self._parse_json(
                    sub_match.group(1), video_id, transform_source=js_to_json, fatal=False) or {}
                src = str_or_none(sub.get('src'))
                if not src:
                    continue
                subtitles.setdefault(dict_get(sub, ('language', 'srclang')) or 'und', []).append({
                    'url': compat_urlparse.urljoin(url, src),
                    'name': sub.get('label'),
                    'http_headers': {
                        'Referer': full_response.geturl(),
                    },
                })
            if formats or subtitles:
                self.report_detected('video.js embed')
                self._sort_formats(formats)
                info_dict['formats'] = formats
                info_dict['subtitles'] = subtitles
                return info_dict

        # Looking for http://schema.org/VideoObject
        json_ld = self._search_json_ld(webpage, video_id, default={})
        if json_ld.get('url') not in (url, None):
            self.report_detected('JSON LD')
            if determine_ext(json_ld['url']) == 'm3u8':
                json_ld['formats'], json_ld['subtitles'] = self._extract_m3u8_formats_and_subtitles(
                    json_ld['url'], video_id, 'mp4')
                json_ld.pop('url')
                self._sort_formats(json_ld['formats'])
            else:
                json_ld['_type'] = 'url_transparent'
                json_ld['url'] = smuggle_url(json_ld['url'], {'force_videoid': video_id, 'to_generic': True})
            return merge_dicts(json_ld, info_dict)