from __future__ import annotations import collections import dataclasses import enum import functools import hashlib import json from yt_dlp.dependencies import yt_dlp_ejs as _has_ejs from yt_dlp.extractor.youtube.jsc._builtin import vendor from yt_dlp.extractor.youtube.jsc.provider import ( JsChallengeProvider, JsChallengeProviderError, JsChallengeProviderRejectedRequest, JsChallengeProviderResponse, JsChallengeResponse, JsChallengeType, NChallengeOutput, SigChallengeOutput, ) from yt_dlp.extractor.youtube.pot._provider import configuration_arg from yt_dlp.extractor.youtube.pot.provider import provider_bug_report_message from yt_dlp.utils._jsruntime import JsRuntimeInfo if _has_ejs: import yt_dlp_ejs.yt.solver TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Callable, Generator from yt_dlp.extractor.youtube.jsc.provider import JsChallengeRequest _EJS_WIKI_URL = 'https://github.com/yt-dlp/yt-dlp/wiki/EJS' class ScriptType(enum.Enum): LIB = 'lib' CORE = 'core' class ScriptVariant(enum.Enum): UNKNOWN = 'unknown' MINIFIED = 'minified' UNMINIFIED = 'unminified' DENO_NPM = 'deno_npm' BUN_NPM = 'bun_npm' class ScriptSource(enum.Enum): PYPACKAGE = 'python package' # PyPI, PyInstaller exe, zipimport binary, etc CACHE = 'cache' # GitHub release assets (cached) WEB = 'web' # GitHub release assets (downloaded) BUILTIN = 'builtin' # vendored (full core script; import-only lib script + NPM cache) @dataclasses.dataclass class Script: type: ScriptType variant: ScriptVariant source: ScriptSource version: str code: str @functools.cached_property def hash(self, /) -> str: return hashlib.sha3_512(self.code.encode()).hexdigest() def __str__(self, /): return f'