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

Code before:
                    'expand': 'all',
                    'ff': 'idp,ldp,rpt',
                    'geoLocation': 'dk',
                    'isDeviceAbroad': 'false',
                    'lang': 'da',
                    'segments': 'drtv,optedout',
                    'sub': 'Anonymous',
                })
        video_id = try_call(lambda: item['customId'].rsplit(':', 1)[-1]) or item_id
        stream_data = self._download_json(
            f'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id,
            note='Downloading stream data', query={
                'delivery': 'stream',
                'device': 'web_browser',
                'ff': 'idp,ldp,rpt',
                'lang': 'da',
                'resolution': 'HD-1080',
                'sub': 'Anonymous',
            },
            headers={
                'authorization': f'Bearer {self._TOKEN}',
            })

        formats = []
        subtitles = {}
        for fmt in traverse_obj(stream_data, (lambda _, x: x['url'], {dict})):
            format_id = fmt.get('format', 'na')
            access_service = fmt.get('accessService')
            preference = None
            subtitle_suffix = ''
            if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
                preference = -1
                format_id += f'-{access_service}'
                subtitle_suffix = f'-{access_service}'
            elif access_service == 'StandardVideo':
                preference = 1
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                fmt.get('url'), video_id, preference=preference, m3u8_id=format_id, fatal=False)
            formats.extend(fmts)

            api_subtitles = traverse_obj(fmt, ('subtitles', lambda _, v: url_or_none(v['link']), {dict}))
            if not api_subtitles:
                self._merge_subtitles(subs, target=subtitles)

            for sub_track in api_subtitles:
                lang = sub_track.get('language') or 'da'
                subtitles.setdefault(self.SUBTITLE_LANGS.get(lang, lang) + subtitle_suffix, []).append({
                    'url': sub_track['link'],
                    'ext': mimetype2ext(sub_track.get('format')) or 'vtt'
                })


Review comment (suggestion):
this is enough to determine it's a dict
```suggestion
        for fmt in traverse_obj(stream_data, (lambda _, x: x['url'])):
```
&nbsp;
More importantly, I'm not a fan of using `fmt` as the variable name here... can be easily confused with fmts/formats.
`stream` would be better IMO

Code after:
                note='Attempting to download backup item data', query={
                    'device': 'web_browser',
                    'expand': 'all',
                    'ff': 'idp,ldp,rpt',
                    'geoLocation': 'dk',
                    'isDeviceAbroad': 'false',
                    'lang': 'da',
                    'segments': 'drtv,optedout',
                    'sub': 'Anonymous',
                })

        video_id = try_call(lambda: item['customId'].rsplit(':', 1)[-1]) or item_id
        stream_data = self._download_json(
            f'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id,
            note='Downloading stream data', query={
                'delivery': 'stream',
                'device': 'web_browser',
                'ff': 'idp,ldp,rpt',
                'lang': 'da',
                'resolution': 'HD-1080',
                'sub': 'Anonymous',
            }, headers={'authorization': f'Bearer {self._TOKEN}'})

        formats = []
        subtitles = {}
        for stream in traverse_obj(stream_data, (lambda _, x: x['url'])):
            format_id = stream.get('format', 'na')
            access_service = stream.get('accessService')
            preference = None
            subtitle_suffix = ''
            if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
                preference = -1
                format_id += f'-{access_service}'
                subtitle_suffix = f'-{access_service}'
            elif access_service == 'StandardVideo':
                preference = 1
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                stream.get('url'), video_id, preference=preference, m3u8_id=format_id, fatal=False)
            formats.extend(fmts)

            api_subtitles = traverse_obj(stream, ('subtitles', lambda _, v: url_or_none(v['link']), {dict}))
            if not api_subtitles:
                self._merge_subtitles(subs, target=subtitles)

            for sub_track in api_subtitles:
                lang = sub_track.get('language') or 'da'
                subtitles.setdefault(self.SUBTITLE_LANGS.get(lang, lang) + subtitle_suffix, []).append({
                    'url': sub_track['link'],
                    'ext': mimetype2ext(sub_track.get('format')) or 'vtt'
                })