Commit 8074c41d authored by Pierre Ynard's avatar Pierre Ynard

youtube.lua: helper to extract signature descrambling javascript code

parent f87f4539
...@@ -70,24 +70,33 @@ function buf_iter( s ) ...@@ -70,24 +70,33 @@ function buf_iter( s )
return line return line
end end
-- Helper to search and extract code from javascript stream
function js_extract( js, pattern )
js.i = 0 -- Reset to beginning
for line in buf_iter, js do
local ex = string.match( line, pattern )
if ex then
return ex
end
end
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return nil
end
-- Descramble the URL signature using the javascript code that does that -- Descramble the URL signature using the javascript code that does that
-- in the web page -- in the web page
function js_descramble( sig, js_url ) function js_descramble( sig, js_url )
-- Fetch javascript code -- Fetch javascript code
local js = { stream = vlc.stream( js_url ), lines = {}, i = 0 } local js = { stream = vlc.stream( js_url ), lines = {}, i = 0 }
if not js.stream then if not js.stream then
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return sig return sig
end end
-- Look for the descrambler function's name -- Look for the descrambler function's name
local descrambler = nil -- c&&a.set("signature",br(c));
for line in buf_iter, js do local descrambler = js_extract( js, "%.set%(\"signature\",(.-)%(" )
-- c&&a.set("signature",br(c));
descrambler = string.match( line, "%.set%(\"signature\",(.-)%(" )
if descrambler then break end
end
if not descrambler then if not descrambler then
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return sig return sig
end end
...@@ -95,15 +104,9 @@ function js_descramble( sig, js_url ) ...@@ -95,15 +104,9 @@ function js_descramble( sig, js_url )
-- conveniently preceded by the definition of a helper object -- conveniently preceded by the definition of a helper object
-- that it uses. Example: -- that it uses. Example:
-- var Fo={TR:function(a){a.reverse()},TU:function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c},sH:function(a,b){a.splice(0,b)}};function Go(a){a=a.split("");Fo.sH(a,2);Fo.TU(a,28);Fo.TU(a,44);Fo.TU(a,26);Fo.TU(a,40);Fo.TU(a,64);Fo.TR(a,26);Fo.sH(a,1);return a.join("")}; -- var Fo={TR:function(a){a.reverse()},TU:function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c},sH:function(a,b){a.splice(0,b)}};function Go(a){a=a.split("");Fo.sH(a,2);Fo.TU(a,28);Fo.TU(a,44);Fo.TU(a,26);Fo.TU(a,40);Fo.TU(a,64);Fo.TR(a,26);Fo.sH(a,1);return a.join("")};
local transformations = nil local rules = js_extract( js, "function "..descrambler.."%([^)]*%){(.-)}" )
local rules = nil local transformations = js_extract( js, "var ..={(.-)};function "..descrambler.."%(" )
js.i = 0 -- Reset to beginning
for line in buf_iter, js do
transformations, rules = string.match( line, "var ..={(.-)};function "..descrambler.."%([^)]*%){(.-)}" )
if transformations or rules then break end
end
if not transformations or not rules then if not transformations or not rules then
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return sig return sig
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment