Commit f87f4539 authored by Pierre Ynard's avatar Pierre Ynard

youtube.lua: buffering iterator for signature descrambling javascript

parent fea9d0b7
--[[ --[[
$Id$ $Id$
Copyright © 2007-2013 the VideoLAN team Copyright © 2007-2015 the VideoLAN team
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -56,29 +56,39 @@ function get_fmt( fmt_list ) ...@@ -56,29 +56,39 @@ function get_fmt( fmt_list )
return fmt return fmt
end end
-- Buffering iterator to parse through the HTTP stream several times
-- without making several HTTP requests
function buf_iter( s )
s.i = s.i + 1
local line = s.lines[s.i]
if not line then
line = s.stream:readline()
if line then
s.lines[s.i] = line
end
end
return line
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 = vlc.stream( js_url ) local js = { stream = vlc.stream( js_url ), lines = {}, i = 0 }
if not js then if not js.stream then
return sig return sig
end end
local lines = {}
-- Look for the descrambler function's name -- Look for the descrambler function's name
local descrambler = nil local descrambler = nil
while not descrambler do for line in buf_iter, js do
local line = js:readline()
if not line then
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return sig
end
-- Buffer lines for later, so we don't have to make a second
-- HTTP request later
table.insert( lines, line )
-- c&&a.set("signature",br(c)); -- c&&a.set("signature",br(c));
descrambler = string.match( line, "%.set%(\"signature\",(.-)%(" ) descrambler = string.match( line, "%.set%(\"signature\",(.-)%(" )
if descrambler then break end
end
if not descrambler then
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return sig
end end
-- Fetch the code of the descrambler function. The function is -- Fetch the code of the descrambler function. The function is
...@@ -87,18 +97,14 @@ function js_descramble( sig, js_url ) ...@@ -87,18 +97,14 @@ function js_descramble( sig, js_url )
-- 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 transformations = nil
local rules = nil local rules = nil
while not transformations and not rules do js.i = 0 -- Reset to beginning
local line for line in buf_iter, js do
if #lines > 0 then
line = table.remove( lines )
else
line = js:readline()
if not line then
vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
return sig
end
end
transformations, rules = string.match( line, "var ..={(.-)};function "..descrambler.."%([^)]*%){(.-)}" ) transformations, rules = string.match( line, "var ..={(.-)};function "..descrambler.."%([^)]*%){(.-)}" )
if transformations or rules then break end
end
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
end end
-- Parse the helper object to map available transformations -- Parse the helper object to map available transformations
......
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