1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2026-02-03 12:36:56 +00:00

patch jsdom for iq

This commit is contained in:
c-basalt
2024-12-31 13:42:36 -05:00
parent b086b8635d
commit 02001159b8
5 changed files with 54 additions and 24 deletions

View File

@@ -1,6 +1,8 @@
# flake8: noqa: F401
from .native import JSInterpreter
from .common import _JSI_PREFERENCES, _JSI_HANDLERS, JSIWrapper
from ._phantomjs import PhantomJSwrapper
from . import _deno
__all__ = [

View File

@@ -70,6 +70,7 @@ class DenoJITlessJSI(DenoJSI):
return DenoJSI.exe_version
@register_jsi
class DenoJSDomJSI(DenoJSI):
_SUPPORTED_FEATURES = {'js', 'wasm', 'location', 'dom', 'cookies'}
_BASE_PREFERENCE = 4
@@ -128,7 +129,7 @@ class DenoJSDomJSI(DenoJSI):
self._run_deno(cmd)
self._JSDOM_IMPORT_CHECKED = True
def execute(self, jscode, video_id=None, note='Executing JS in Deno', html='', cookiejar=None):
def execute(self, jscode, video_id=None, note='Executing JS in Deno with jsdom', html='', cookiejar=None):
self.report_note(video_id, note)
self._ensure_jsdom()
@@ -148,15 +149,35 @@ class DenoJSDomJSI(DenoJSI):
const dom = new jsdom.JSDOM({json.dumps(str(html))}, {{
{'url: %s,' % json.dumps(str(self._url)) if self._url else ''}
cookieJar: jar,
pretendToBeVisual: true,
}});
Object.keys(dom.window).forEach((key) => {{try {{window[key] = dom.window[key]}} catch (e) {{}}}});
Object.keys(dom.window).filter(key => !['atob', 'btoa'].includes(key)).forEach((key) => {{
try {{window[key] = dom.window[key]}} catch (e) {{}}
}});
window.screen = {{
availWidth: 1920,
availHeight: 1040,
width: 1920,
height: 1080,
colorDepth: 24,
isExtended: true,
onchange: null,
orientation: {{angle: 0, type: 'landscape-primary', onchange: null}},
pixelDepth: 24,
width: 1920,
}}
Object.defineProperty(document.body, 'clientWidth', {{value: 1903}});
Object.defineProperty(document.body, 'clientHeight', {{value: 1035}});
document.domain = location.hostname;
delete window.jsdom;
const origLog = console.log;
console.log = () => {{}};
console.info = () => {{}};
return () => {{
const stdout = [];
console.log = (...msg) => stdout.push(msg.map(m => m.toString()).join(' '));
console.log = (...msg) => stdout.push(msg.map(m => '' + m).join(' '));
return () => {{ origLog(JSON.stringify({{
stdout: stdout.join('\\n'), cookies: jar.serializeSync().cookies}})); }}
}}

View File

@@ -81,6 +81,16 @@ def override_navigator_js(user_agent: str) -> str:
'language': 'en-US',
'languages': ['en-US'],
'webdriver': False,
'cookieEnabled': True,
'appCodeName': user_agent.split('/', maxsplit=1)[0],
'appName': 'Netscape',
'appVersion': user_agent.split('/', maxsplit=1)[-1],
'platform': 'Win32',
'product': 'Gecko',
'productSub': '20030107',
'vendor': 'Google Inc.',
'vendorSub': '',
'onLine': True,
}.items()
])

View File

@@ -198,7 +198,7 @@ class PhantomJSwrapper:
return PhantomJSJSI.exe_version
def __init__(self, extractor: InfoExtractor, required_version=None, timeout=10000):
self._jsi = PhantomJSJSI(extractor._downloader, timeout=timeout / 1000)
self._jsi = PhantomJSJSI(extractor._downloader, '', timeout / 1000, {})
if not self._jsi.is_available():
raise ExtractorError(f'PhantomJS not found, {self.INSTALL_HINT}', expected=True)