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

Code before:
            # For SHD
            'host': self._HOST,
            'referer': self._REFERER,
            'ehost': video_url,
            'appVer': self._APP_VERSION,
            'platform': self._PLATFORM,
            # For VQQ
            'guid': guid,
            'flowid': ''.join(random.choices(string.digits + string.ascii_lowercase, k=32)),
        }

        return self._search_json(r'QZOutputJson=', self._download_webpage(
            self._API_URL, video_id, query=query), 'api_response', video_id)

    def _extract_video_formats_and_subtitles(self, api_response, video_id):
        video_response = api_response['vl']['vi'][0]
        video_width, video_height = video_response.get('vw'), video_response.get('vh')

        formats, subtitles = [], {}
        for video_format in video_response['ul']['ui']:
            if video_format.get('hls') or determine_ext(video_format['url']) == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    video_format['url'] + traverse_obj(video_format, ('hls', 'pt'), default=''),
                    video_id, 'mp4', fatal=False)
                for f in fmts:
                    f.update({'width': video_width, 'height': video_height})

                formats.extend(fmts)
                self._merge_subtitles(subs, target=subtitles)
            else:
                formats.append({
                    'url': f'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}',
                    'width': video_width,
                    'height': video_height,
                    'ext': 'mp4',
                })

        return formats, subtitles

    def _extract_video_native_subtitles(self, api_response, subtitles_format):
        subtitles = {}
        for subtitle in traverse_obj(api_response, ('sfl', 'fi')) or ():
            subtitles.setdefault(subtitle['lang'].lower(), []).append({
                'url': subtitle['url'],
                'ext': subtitles_format,
                'protocol': 'm3u8_native' if determine_ext(subtitle['url']) == 'm3u8' else 'http',
            })

        return subtitles

    def _extract_all_video_formats_and_subtitles(self, url, video_id, series_id):

Review comment (bug):
This will fail if the field doesn't exist, use instead `float_or_none(format_response.get('audiobandwidth'), scale=1000)`

https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#mandatory-and-optional-metafields

```bash
[debug] Command-line config: ['https://wetv.vip/en/play/7csb8h9c79p8idi-Lie%20To%20Love', '--verbose', '-F']
[debug] User config: []
[debug] System config: []
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2023.01.02 [d83b0ad80] (source)
[debug] Lazy loading extractors is disabled
[debug] Git HEAD: f49f600fe
[debug] Python 3.10.7 (CPython x86_64 64bit) - Linux-5.19.0-26-generic-x86_64-with-glibc2.36 (OpenSSL 3.0.5 5 Jul 2022, glibc 2.36)
[debug] exe versions: ffmpeg N-108931-g4dda3b1653-20221104 (setts), ffprobe N-108931-g4dda3b1653-20221104, phantomjs broken, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.15.0, certifi-2022.09.24, mutagen-1.46.0, sqlite3-2.6.0, websockets-10.4
[debug] Proxy map: {}
[debug] Loaded 1756 extractors
[WeTvSeries] Extracting URL: https://wetv.vip/en/play/7csb8h9c79p8idi-Lie%20To%20Love
[WeTvSeries] 7csb8h9c79p8idi: Downloading webpage
[download] Downloading playlist: Lie To Love
[WeTvSeries] Playlist Lie To Love: Downloading 32 items of 32
[download] Downloading item 1 of 32
[wetv:episode] Extracting URL: https://wetv.vip/play/7csb8h9c79p8idi/a0041yw44yk
[wetv:episode] a0041yw44yk: Downloading webpage
[wetv:episode] a0041yw44yk: Downloading webpage
ERROR: unsupported operand type(s) for /: 'NoneType' and 'int'
Traceback (most recent call last):
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/YoutubeDL.py", line 1502, in wrapper
    return func(self, *args, **kwargs)
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/YoutubeDL.py", line 1578, in __extract_info
    ie_result = ie.extract(url)
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/extractor/common.py", line 680, in extract
    ie_result = self._real_extract(url)
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/extractor/tencent.py", line 381, in _real_extract
    return self._extract_episode(url)
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/extractor/tencent.py", line 301, in _extract_episode
    formats, subtitles = self._extract_all_video_formats_and_subtitles(url, video_id, series_id)
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/extractor/tencent.py", line 132, in _extract_all_video_formats_and_subtitles
    fmts, subs = self._extract_video_formats_and_subtitles(api_response, video_id)
  File "/home/amish/Documents/Programming/yt-dlp/yt_dlp/extractor/tencent.py", line 75, in _extract_video_formats_and_subtitles
    abr, vbr, is_hdr, format_name = format_response.get('audiobandwidth') / 1000, format_response.get('bandwidth') / 1000, format_response.get('name') == 'hdr10', f'{format_response.get("sname")} ({format_response.get("resolution")})'
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
```

Code after:
            'cid': series_id,
            'cKey': ckey,
            'encryptVer': '8.1',
            'spcaptiontype': '1' if subtitle_format == 'vtt' else '0',
            'sphls': '2' if video_format == 'hls' else '0',
            'dtype': '3' if video_format == 'hls' else '0',
            'defn': video_quality,
            'spsrt': '2',  # Enable subtitles
            'sphttps': '1',  # Enable HTTPS
            'otype': 'json',
            'spwm': '1',
            'hevclv': '28',  # Enable HEVC
            'drm': '40',  # Enable DRM
            # For HDR
            'spvideo': '4',
            'spsfrhdr': '100',
            # For SHD
            'host': self._HOST,
            'referer': self._REFERER,
            'ehost': video_url,
            'appVer': self._APP_VERSION,
            'platform': self._PLATFORM,
            # For VQQ
            'guid': guid,
            'flowid': ''.join(random.choices(string.digits + string.ascii_lowercase, k=32)),
        }

        return self._search_json(r'QZOutputJson=', self._download_webpage(
            self._API_URL, video_id, query=query), 'api_response', video_id)

    def _extract_video_formats_and_subtitles(self, api_response, video_id):
        video_response = api_response['vl']['vi'][0]

        formats, subtitles = [], {}
        for video_format in video_response['ul']['ui']:
            if video_format.get('hls') or determine_ext(video_format['url']) == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    video_format['url'] + traverse_obj(video_format, ('hls', 'pt'), default=''),
                    video_id, 'mp4', fatal=False)

                formats.extend(fmts)
                self._merge_subtitles(subs, target=subtitles)
            else:
                formats.append({
                    'url': f'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}',
                    'ext': 'mp4',
                })

        identifier = video_response.get('br')
        format_response = traverse_obj(
            api_response, ('fl', 'fi', lambda _, v: v['br'] == identifier),