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

Code before:
from ..utils import (
    ExtractorError,
    HEADRequest,
    UnsupportedError,
    determine_ext,
    int_or_none,
    parse_resolution,
    str_or_none,
    traverse_obj,
    unified_timestamp,
    url_basename,
    urljoin,
    url_or_none,
)


class TrillerBaseIE(InfoExtractor):
    _NETRC_MACHINE = 'triller'
    _API_BASE_URL = 'https://social.triller.co/v1.5'
    _API_HEADERS = {'Origin': 'https://triller.co'}

    def _perform_login(self, username, password):
        if self._API_HEADERS.get('Authorization'):
            return

        self._API_HEADERS['Content-Type'] = 'application/json'
        user_check = traverse_obj(self._download_json(
            f'{self._API_BASE_URL}/api/user/is-valid-username', None, note='Checking username',
            fatal=False, expected_status=400, headers=self._API_HEADERS,
            data=json.dumps({'username': username}, separators=(',', ':')).encode()), 'status')

        if user_check:  # endpoint returns `"status":false` if username exists
            raise ExtractorError('Unable to login: Invalid username', expected=True)

        login = self._download_json(
            f'{self._API_BASE_URL}/user/auth', None, note='Logging in', fatal=False,
            expected_status=400, headers=self._API_HEADERS, data=json.dumps({
                'username': username,
                'password': password,
            }, separators=(',', ':')).encode()) or {}

        if not login.get('auth_token'):
            if login.get('error') == 1008:
                raise ExtractorError('Unable to login: Incorrect password', expected=True)
            raise ExtractorError('Unable to login')

        self._API_HEADERS.pop('Content-Type', None)
        self._API_HEADERS['Authorization'] = f'Bearer {login["auth_token"]}'

    def _get_comments(self, video_id, limit=15):
        comment_info = self._download_json(

Review comment (suggestion):
I don't like how this mutates and then resets the var. I'd rather do:
```suggestion
        headers = {**self._API_HEADERS, 'Content-Type': 'application/json'}
```

Code after:
from ..utils import (
    ExtractorError,
    HEADRequest,
    UnsupportedError,
    determine_ext,
    int_or_none,
    parse_resolution,
    str_or_none,
    traverse_obj,
    unified_timestamp,
    url_basename,
    urljoin,
    url_or_none,
)


class TrillerBaseIE(InfoExtractor):
    _NETRC_MACHINE = 'triller'
    _API_BASE_URL = 'https://social.triller.co/v1.5'
    _API_HEADERS = {'Origin': 'https://triller.co'}

    def _perform_login(self, username, password):
        if self._API_HEADERS.get('Authorization'):
            return

        headers = {**self._API_HEADERS, 'Content-Type': 'application/json'}
        user_check = traverse_obj(self._download_json(
            f'{self._API_BASE_URL}/api/user/is-valid-username', None, note='Checking username',
            fatal=False, expected_status=400, headers=headers,
            data=json.dumps({'username': username}, separators=(',', ':')).encode()), 'status')

        if user_check:  # endpoint returns `"status":false` if username exists
            raise ExtractorError('Unable to login: Invalid username', expected=True)

        login = self._download_json(
            f'{self._API_BASE_URL}/user/auth', None, note='Logging in', fatal=False,
            expected_status=400, headers=headers, data=json.dumps({
                'username': username,
                'password': password,
            }, separators=(',', ':')).encode()) or {}

        if not login.get('auth_token'):
            if login.get('error') == 1008:
                raise ExtractorError('Unable to login: Incorrect password', expected=True)
            raise ExtractorError('Unable to login')

        self._API_HEADERS['Authorization'] = f'Bearer {login["auth_token"]}'

    def _get_comments(self, video_id, limit=15):
        comment_info = self._download_json(
            f'{self._API_BASE_URL}/api/videos/{video_id}/comments_v2',