1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2026-01-24 15:51:22 +00:00

add testcase

This commit is contained in:
c-basalt
2025-01-01 13:33:16 -05:00
parent 02001159b8
commit e8eb983583
4 changed files with 61 additions and 41 deletions

View File

@@ -142,7 +142,6 @@ class DenoJSDomJSI(DenoJSI):
callback_varname = f'__callback_{random_string()}'
script = f'''{self._init_script};
{self._override_navigator_js};
import jsdom from "{self._JSDOM_URL}";
let {callback_varname} = (() => {{
const jar = jsdom.CookieJar.deserializeSync({json.dumps(self.serialize_cookie(cookiejar, self._url))});
@@ -151,9 +150,12 @@ class DenoJSDomJSI(DenoJSI):
cookieJar: jar,
pretendToBeVisual: true,
}});
Object.keys(dom.window).filter(key => !['atob', 'btoa'].includes(key)).forEach((key) => {{
try {{window[key] = dom.window[key]}} catch (e) {{}}
Object.keys(dom.window).filter(key => !['atob', 'btoa', 'crypto', 'location'].includes(key))
.filter(key => !(window.location? [] : ['sessionStorage', 'localStorage']).includes(key))
.forEach((key) => {{
try {{window[key] = dom.window[key]}} catch (e) {{ console.error(e) }}
}});
{self._override_navigator_js};
window.screen = {{
availWidth: 1920,
@@ -168,8 +170,8 @@ class DenoJSDomJSI(DenoJSI):
width: 1920,
}}
Object.defineProperty(document.body, 'clientWidth', {{value: 1903}});
Object.defineProperty(document.body, 'clientHeight', {{value: 1035}});
document.domain = location.hostname;
Object.defineProperty(document.body, 'clientHeight', {{value: 2000}});
document.domain = location?.hostname;
delete window.jsdom;
const origLog = console.log;

View File

@@ -164,26 +164,24 @@ class PhantomJSJSI(ExternalJSI):
return new_html, stdout
def execute(self, jscode, video_id=None, note='Executing JS in PhantomJS', html='', cookiejar=None):
if self._url or html or cookiejar:
jscode = '''console.log(page.evaluate(function() {
var %(std_var)s = [];
console.log = function() {
var values = '';
for (var i = 0; i < arguments.length; i++) {
values += arguments[i] + ' ';
}
%(std_var)s.push(values);
jscode = '''console.log(page.evaluate(function() {
var %(std_var)s = [];
console.log = function() {
var values = '';
for (var i = 0; i < arguments.length; i++) {
values += arguments[i] + ' ';
}
%(jscode)s;
return %(std_var)s.join('\\n');
}));
saveAndExit();''' % {
'std_var': f'__stdout__values_{random_string()}',
'jscode': jscode,
%(std_var)s.push(values);
}
return self._execute_html(jscode, self._url, html, cookiejar, video_id=video_id, note=note)[1].strip()
return self._execute(jscode, video_id, note=note).strip()
%(jscode)s;
return %(std_var)s.join('\\n');
}));
saveAndExit();''' % {
'std_var': f'__stdout__values_{random_string()}',
'jscode': jscode,
}
return self._execute_html(jscode, self._url, html, cookiejar, video_id=video_id, note=note)[1].strip()
class PhantomJSwrapper:

View File

@@ -117,7 +117,7 @@ class JSIWrapper:
self.write_debug(f'Allowed JSI keys: {jsi_keys}')
handler_classes = [_JSI_HANDLERS[key] for key in jsi_keys
if _JSI_HANDLERS[key]._SUPPORTED_FEATURES.issuperset(self._features)]
self.write_debug(f'Selected JSI classes for given features: {get_jsi_keys(handler_classes)}, '
self.write_debug(f'Select JSI for features={self._features}: {get_jsi_keys(handler_classes)}, '
f'included: {get_jsi_keys(only_include) or "all"}, excluded: {get_jsi_keys(exclude)}')
self._handler_dict = {