mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-05 12:58:29 +00:00
update
This commit is contained in:
parent
63c5218ab1
commit
37a3bc2a4a
@ -1,9 +1,10 @@
|
|||||||
from .jsinterp import JSInterpreter
|
from .jsinterp import JSInterpreter
|
||||||
from .external import PhantomJSwrapper, DenoWrapper
|
from .external import PhantomJSwrapper, DenoWrapper, PuppeteerWrapper
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
JSInterpreter,
|
JSInterpreter,
|
||||||
PhantomJSwrapper,
|
PhantomJSwrapper,
|
||||||
DenoWrapper,
|
DenoWrapper,
|
||||||
|
PuppeteerWrapper,
|
||||||
]
|
]
|
||||||
|
@ -112,18 +112,21 @@ def _execute(cls, jscode, extractor=None, video_id=None, note='', flags=[], time
|
|||||||
extractor.report_warning(f'JS console error msg:\n{stderr.strip()}', video_id=video_id)
|
extractor.report_warning(f'JS console error msg:\n{stderr.strip()}', video_id=video_id)
|
||||||
return stdout.strip()
|
return stdout.strip()
|
||||||
|
|
||||||
def execute(self, jscode, video_id=None, *, note='Executing JS in Deno', flags=[], jit_less=True, base_js=None):
|
def execute(self, jscode, video_id=None, *, note='Executing JS in Deno', flags=[], base_js=None):
|
||||||
"""Execute JS directly in Deno runtime and return stdout"""
|
"""Execute JS directly in Deno runtime and return stdout"""
|
||||||
|
|
||||||
base_js = base_js if base_js is not None else 'delete window.Deno; global = window;'
|
base_js = base_js if base_js is not None else 'delete window.Deno; global = window;'
|
||||||
|
|
||||||
if jit_less:
|
|
||||||
flags = [*flags, '--v8-flags=--jitless']
|
|
||||||
|
|
||||||
return self._execute(base_js + jscode, extractor=self.extractor, video_id=video_id, note=note,
|
return self._execute(base_js + jscode, extractor=self.extractor, video_id=video_id, note=note,
|
||||||
flags=flags, timeout=self.timeout)
|
flags=flags, timeout=self.timeout)
|
||||||
|
|
||||||
|
|
||||||
|
class DenoJITlessJSI(DenoWrapper):
|
||||||
|
def execute(self, jscode, video_id=None, *, note='Executing JS in Deno', flags=[], base_js=None):
|
||||||
|
return super().execute(jscode, video_id, note=note, base_js=base_js,
|
||||||
|
flags=[*flags, '--v8-flags=--jitless,--noexpose-wasm'])
|
||||||
|
|
||||||
|
|
||||||
class PuppeteerWrapper:
|
class PuppeteerWrapper:
|
||||||
_PACKAGE_VERSION = '16.2.0'
|
_PACKAGE_VERSION = '16.2.0'
|
||||||
_HEADLESS = False
|
_HEADLESS = False
|
||||||
@ -176,9 +179,9 @@ def _deno_execute(self, jscode, note=None):
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
}}''', note=note, flags=['--allow-all'], base_js='')
|
}}''', note=note, flags=['--allow-all'], base_js='')
|
||||||
|
|
||||||
def evaluate(self, jscode, video_id=None, note='Executing JS in Puppeteer', url='about:blank'):
|
def execute(self, jscode, video_id=None, note='Executing JS in Puppeteer', url='about:blank'):
|
||||||
self.extractor.to_screen(f'{format_field(video_id, None, "%s: ")}{note}')
|
self.extractor.to_screen(f'{format_field(video_id, None, "%s: ")}{note}')
|
||||||
return json.loads(self._deno_execute(f'''
|
return self._deno_execute(f'''
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
window.setTimeout(async () => {{
|
window.setTimeout(async () => {{
|
||||||
console.error('Puppeteer execution timed out');
|
console.error('Puppeteer execution timed out');
|
||||||
@ -187,26 +190,21 @@ def evaluate(self, jscode, video_id=None, note='Executing JS in Puppeteer', url=
|
|||||||
}}, {int(self.timeout)});
|
}}, {int(self.timeout)});
|
||||||
page.resourceTimeout = {int(self.timeout)};
|
page.resourceTimeout = {int(self.timeout)};
|
||||||
|
|
||||||
|
// drop network requests
|
||||||
await page.setRequestInterception(true);
|
await page.setRequestInterception(true);
|
||||||
page.on("request", request => request.abort());
|
page.on("request", request => request.abort());
|
||||||
|
// capture console output
|
||||||
|
page.on("console", msg => {{
|
||||||
|
msg.type() === 'log' && console.log(msg.text());
|
||||||
|
msg.type() === 'error' && console.error(msg.text());
|
||||||
|
}});
|
||||||
|
|
||||||
const url = {json.dumps(str(url))};
|
const url = {json.dumps(str(url))};
|
||||||
await page.evaluate(`window.history.replaceState('', '', ${{JSON.stringify(url)}})`);
|
await page.evaluate(`window.history.replaceState('', '', ${{JSON.stringify(url)}})`);
|
||||||
|
|
||||||
console.log(JSON.stringify(await page.evaluate({json.dumps(str(jscode))})));
|
await page.evaluate({json.dumps(str(jscode))});
|
||||||
await browser.close();
|
await browser.close();
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
'''))
|
|
||||||
|
|
||||||
def execute(self, jscode, **args):
|
|
||||||
return self.evaluate('''
|
|
||||||
(() => {{
|
|
||||||
const results = [];
|
|
||||||
const origConsole = console;
|
|
||||||
const console = new Proxy(console, { get: (target, prop, receiver) => {
|
|
||||||
if (prop === 'log') return (...data) => data.forEach(i => results.push(i));
|
|
||||||
return target[prop]}})
|
|
||||||
}})();
|
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user