[YouTube] Improve fix for ae8ba2c

Thx: https://github.com/yt-dlp/yt-dlp/commit/01aba25
This commit is contained in:
dirkf 2023-06-18 00:52:18 +01:00
parent ae8ba2c319
commit 07af47960f
2 changed files with 13 additions and 12 deletions

View file

@ -1569,9 +1569,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')
# temporary (please) hack for player 6ed0d907 #32314 jsi = JSInterpreter(jscode)
ah = 'var AH={LR:function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c},QV:function(a){a.reverse()},pO:function(a,b){a.splice(0,b)}};'
jsi = JSInterpreter(ah + jscode)
initial_function = jsi.extract_function(funcname) initial_function = jsi.extract_function(funcname)

View file

@ -940,15 +940,18 @@ class JSInterpreter(object):
def extract_object(self, objname): def extract_object(self, objname):
_FUNC_NAME_RE = r'''(?:[a-zA-Z$0-9]+|"[a-zA-Z$0-9]+"|'[a-zA-Z$0-9]+')''' _FUNC_NAME_RE = r'''(?:[a-zA-Z$0-9]+|"[a-zA-Z$0-9]+"|'[a-zA-Z$0-9]+')'''
obj = {} obj = {}
obj_m = re.search( fields = None
for obj_m in re.finditer(
r'''(?xs) r'''(?xs)
(?:{0}\s*\.\s*{1}|{1}\s*=\s*\{{\s* {0}\s*\.\s*{1}|{1}\s*=\s*\{{\s*
(?P<fields>({2}\s*:\s*function\s*\(.*?\)\s*\{{.*?}}(?:,\s*)?)*) (?P<fields>({2}\s*:\s*function\s*\(.*?\)\s*\{{.*?}}(?:,\s*)?)*)
}}\s*); }}\s*;
'''.format(_NAME_RE, re.escape(objname), _FUNC_NAME_RE), '''.format(_NAME_RE, re.escape(objname), _FUNC_NAME_RE),
self.code) self.code):
fields = obj_m and obj_m.group('fields') fields = obj_m.group('fields')
if fields is None: if fields:
break
else:
raise self.Exception('Could not find object ' + objname) raise self.Exception('Could not find object ' + objname)
# Currently, it only supports function definitions # Currently, it only supports function definitions
fields_m = re.finditer( fields_m = re.finditer(