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

Code before:


def _fix_embedded_ytcfg(ytcfg):
    ytcfg['INNERTUBE_CONTEXT'].setdefault('thirdParty', {}).update({
        'embedUrl': 'https://www.youtube.com/',  # Can be any valid URL
    })


def build_innertube_clients():
    # From highest to lowest priority
    BASE_CLIENTS = ('tv', 'web', 'mweb', 'android', 'ios')
    priority = qualities(BASE_CLIENTS[::-1])

    for client, ytcfg in tuple(INNERTUBE_CLIENTS.items()):
        ytcfg.setdefault('INNERTUBE_HOST', 'www.youtube.com')
        ytcfg.setdefault('REQUIRE_JS_PLAYER', True)
        ytcfg.setdefault('GVS_PO_TOKEN_POLICY', {})
        for protocol in StreamingProtocol:
            ytcfg['GVS_PO_TOKEN_POLICY'].setdefault(protocol, GvsPoTokenPolicy())
        ytcfg.setdefault('PLAYER_PO_TOKEN_POLICY', PlayerPoTokenPolicy())
        ytcfg.setdefault('SUBS_PO_TOKEN_POLICY', SubsPoTokenPolicy())
        ytcfg.setdefault('REQUIRE_AUTH', False)
        ytcfg.setdefault('SUPPORTS_COOKIES', False)
        ytcfg.setdefault('PLAYER_PARAMS', None)
        ytcfg.setdefault('AUTHENTICATED_USER_AGENT', None)
        ytcfg.setdefault('SUPPORTS_AD_PLAYBACK_CONTEXT', False)
        ytcfg['INNERTUBE_CONTEXT']['client'].setdefault('hl', 'en')

        _, base_client, variant = _split_innertube_client(client)
        ytcfg['priority'] = 10 * priority(base_client)

        if variant == 'embedded':
            _fix_embedded_ytcfg(ytcfg)


build_innertube_clients()


class BadgeType(enum.Enum):
    AVAILABILITY_UNLISTED = enum.auto()
    AVAILABILITY_PRIVATE = enum.auto()
    AVAILABILITY_PUBLIC = enum.auto()
    AVAILABILITY_PREMIUM = enum.auto()
    AVAILABILITY_SUBSCRIPTION = enum.auto()
    LIVE_NOW = enum.auto()
    VERIFIED = enum.auto()


CONFIGURATION_ARG_KEY = 'youtube'



Review comment (security):
```suggestion
        ytcfg.setdefault('SUPPORTS_COOKIES', False)
        ytcfg.setdefault('SUPPORTS_AD_PLAYBACK_CONTEXT', False)
        ytcfg.setdefault('PLAYER_PARAMS', None)
        ytcfg.setdefault('AUTHENTICATED_USER_AGENT', None)
```

Code after:


def _fix_embedded_ytcfg(ytcfg):
    ytcfg['INNERTUBE_CONTEXT'].setdefault('thirdParty', {}).update({
        'embedUrl': 'https://www.youtube.com/',  # Can be any valid URL
    })


def build_innertube_clients():
    # From highest to lowest priority
    BASE_CLIENTS = ('tv', 'web', 'mweb', 'android', 'ios')
    priority = qualities(BASE_CLIENTS[::-1])

    for client, ytcfg in tuple(INNERTUBE_CLIENTS.items()):
        ytcfg.setdefault('INNERTUBE_HOST', 'www.youtube.com')
        ytcfg.setdefault('REQUIRE_JS_PLAYER', True)
        ytcfg.setdefault('GVS_PO_TOKEN_POLICY', {})
        for protocol in StreamingProtocol:
            ytcfg['GVS_PO_TOKEN_POLICY'].setdefault(protocol, GvsPoTokenPolicy())
        ytcfg.setdefault('PLAYER_PO_TOKEN_POLICY', PlayerPoTokenPolicy())
        ytcfg.setdefault('SUBS_PO_TOKEN_POLICY', SubsPoTokenPolicy())
        ytcfg.setdefault('REQUIRE_AUTH', False)
        ytcfg.setdefault('SUPPORTS_COOKIES', False)
        ytcfg.setdefault('SUPPORTS_AD_PLAYBACK_CONTEXT', False)
        ytcfg.setdefault('PLAYER_PARAMS', None)
        ytcfg.setdefault('AUTHENTICATED_USER_AGENT', None)
        ytcfg['INNERTUBE_CONTEXT']['client'].setdefault('hl', 'en')

        _, base_client, variant = _split_innertube_client(client)
        ytcfg['priority'] = 10 * priority(base_client)

        if variant == 'embedded':
            _fix_embedded_ytcfg(ytcfg)


build_innertube_clients()


class BadgeType(enum.Enum):
    AVAILABILITY_UNLISTED = enum.auto()
    AVAILABILITY_PRIVATE = enum.auto()
    AVAILABILITY_PUBLIC = enum.auto()
    AVAILABILITY_PREMIUM = enum.auto()
    AVAILABILITY_SUBSCRIPTION = enum.auto()
    LIVE_NOW = enum.auto()
    VERIFIED = enum.auto()


CONFIGURATION_ARG_KEY = 'youtube'