1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-19 14:38:53 +00:00
This commit is contained in:
c-basalt
2024-12-28 03:56:12 -05:00
parent 5d32d72a83
commit 65e238c45d
4 changed files with 13 additions and 13 deletions

View File

@@ -15,7 +15,7 @@ import urllib.request
from test.helper import FakeYDL, is_download_test from test.helper import FakeYDL, is_download_test
from yt_dlp.extractor import YoutubeIE from yt_dlp.extractor import YoutubeIE
from yt_dlp.jsinterp import NativeJSI from yt_dlp.jsinterp import JSInterpreter
_SIG_TESTS = [ _SIG_TESTS = [
( (
@@ -274,7 +274,7 @@ def signature(jscode, sig_input):
def n_sig(jscode, sig_input): def n_sig(jscode, sig_input):
ie = YoutubeIE(FakeYDL()) ie = YoutubeIE(FakeYDL())
funcname = ie._extract_n_function_name(jscode) funcname = ie._extract_n_function_name(jscode)
jsi = NativeJSI(jscode) jsi = JSInterpreter(jscode)
func = jsi.extract_function_from_code(*ie._fixup_n_function_code(*jsi.extract_function_code(funcname))) func = jsi.extract_function_from_code(*ie._fixup_n_function_code(*jsi.extract_function_code(funcname)))
return func([sig_input]) return func([sig_input])

View File

@@ -20,7 +20,7 @@ import traceback
import urllib.parse import urllib.parse
from .common import InfoExtractor, SearchInfoExtractor from .common import InfoExtractor, SearchInfoExtractor
from ..jsinterp import NativeJSI, PhantomJSwrapper from ..jsinterp import JSInterpreter, PhantomJSwrapper
from ..networking.exceptions import HTTPError, network_exceptions from ..networking.exceptions import HTTPError, network_exceptions
from ..utils import ( from ..utils import (
NO_DEFAULT, NO_DEFAULT,
@@ -3169,7 +3169,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('), r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('),
jscode, 'Initial JS player signature function name', group='sig') jscode, 'Initial JS player signature function name', group='sig')
jsi = NativeJSI(jscode) jsi = JSInterpreter(jscode)
initial_function = jsi.extract_function(funcname) initial_function = jsi.extract_function(funcname)
return lambda s: initial_function([s]) return lambda s: initial_function([s])
@@ -3213,7 +3213,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
try: try:
extract_nsig = self._cached(self._extract_n_function_from_code, 'nsig func', player_url) extract_nsig = self._cached(self._extract_n_function_from_code, 'nsig func', player_url)
ret = extract_nsig(jsi, func_code)(s) ret = extract_nsig(jsi, func_code)(s)
except NativeJSI.Exception as e: except JSInterpreter.Exception as e:
try: try:
jsi = PhantomJSwrapper(self, timeout=5000) jsi = PhantomJSwrapper(self, timeout=5000)
except ExtractorError: except ExtractorError:
@@ -3283,7 +3283,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
player_id = self._extract_player_info(player_url) player_id = self._extract_player_info(player_url)
func_code = self.cache.load('youtube-nsig', player_id, min_ver='2024.07.09') func_code = self.cache.load('youtube-nsig', player_id, min_ver='2024.07.09')
jscode = func_code or self._load_player(video_id, player_url) jscode = func_code or self._load_player(video_id, player_url)
jsi = NativeJSI(jscode) jsi = JSInterpreter(jscode)
if func_code: if func_code:
return jsi, player_id, func_code return jsi, player_id, func_code
@@ -3302,13 +3302,13 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
def extract_nsig(s): def extract_nsig(s):
try: try:
ret = func([s]) ret = func([s])
except NativeJSI.Exception: except JSInterpreter.Exception:
raise raise
except Exception as e: except Exception as e:
raise NativeJSI.Exception(traceback.format_exc(), cause=e) raise JSInterpreter.Exception(traceback.format_exc(), cause=e)
if ret.startswith('enhanced_except_') or ret.endswith(s): if ret.startswith('enhanced_except_') or ret.endswith(s):
raise NativeJSI.Exception('Signature function returned an exception') raise JSInterpreter.Exception('Signature function returned an exception')
return ret return ret
return extract_nsig return extract_nsig
@@ -4156,7 +4156,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
}) })
except ExtractorError as e: except ExtractorError as e:
phantomjs_hint = '' phantomjs_hint = ''
if isinstance(e, NativeJSI.Exception): if isinstance(e, JSInterpreter.Exception):
phantomjs_hint = (f' Install {self._downloader._format_err("PhantomJS", self._downloader.Styles.EMPHASIS)} ' phantomjs_hint = (f' Install {self._downloader._format_err("PhantomJS", self._downloader.Styles.EMPHASIS)} '
f'to workaround the issue. {PhantomJSwrapper.INSTALL_HINT}\n') f'to workaround the issue. {PhantomJSwrapper.INSTALL_HINT}\n')
if player_url: if player_url:

View File

@@ -1,10 +1,10 @@
from .native import JSInterpreter as NativeJSI from .native import JSInterpreter
from .external import PhantomJSwrapper, DenoJSI, PuppeteerJSI from .external import PhantomJSwrapper, DenoJSI, PuppeteerJSI
from .common import _JSI_PREFERENCES, _JSI_HANDLERS, JSInterp from .common import _JSI_PREFERENCES, _JSI_HANDLERS, JSInterp
__all__ = [ __all__ = [
NativeJSI, JSInterpreter,
PhantomJSwrapper, PhantomJSwrapper,
DenoJSI, DenoJSI,
PuppeteerJSI, PuppeteerJSI,

View File

@@ -240,7 +240,7 @@ def _base_preference(handler: JSI, *args):
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from ..YoutubeDL import YoutubeDL from ..YoutubeDL import YoutubeDL
JsiClass = typing.TypeVar('JsiClass', bound=typing.Type[JSI]) JsiClass = typing.TypeVar('JsiClass', bound=type[JSI])
class JSIPreference(typing.Protocol): class JSIPreference(typing.Protocol):
def __call__(self, handler: JSI, method_name: str, *args, **kwargs) -> int: def __call__(self, handler: JSI, method_name: str, *args, **kwargs) -> int: