[vlc-commits] youtube.lua: properly search for signature descrambling helper object

Pierre Ynard git at videolan.org
Sun Nov 22 21:35:40 CET 2015


vlc/vlc-2.2 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Wed Nov 11 22:51:08 2015 +0100| [75a10cb64532097f4b28e8fb382f652e1b31f5d9] | committer: Jean-Baptiste Kempf

youtube.lua: properly search for signature descrambling helper object

It is not anymore conveniently located before its use. Also, update look
up of descrambling rules.

(cherry picked from commit 0c48277273d776080c893154124fa3537dc6485f)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=75a10cb64532097f4b28e8fb382f652e1b31f5d9
---

 share/lua/playlist/youtube.lua |   34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index b0bdb52..a50a624 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -82,10 +82,13 @@ function buf_iter( s )
 end
 
 -- Helper to search and extract code from javascript stream
-function js_extract( js, pattern )
+function js_extract( js, pattern, alt )
     js.i = 0 -- Reset to beginning
     for line in buf_iter, js do
         local ex = string.match( line, pattern )
+        if not ex and alt then
+            ex = string.match( line, alt )
+        end
         if ex then
             return ex
         end
@@ -106,18 +109,31 @@ function js_descramble( sig, js_url )
 
     -- Look for the descrambler function's name
     -- c&&a.set("signature",br(c));
-    local descrambler = js_extract( js, "%.set%(\"signature\",(.-)%(" )
+    local descrambler = js_extract( js, "%.set%(\"signature\",(.-)%(", nil )
     if not descrambler then
         return sig
     end
 
-    -- Fetch the code of the descrambler function. The function is
-    -- conveniently preceded by the definition of a helper object
-    -- 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("")};
-    local rules = js_extract( js, "function "..descrambler.."%([^)]*%){(.-)}" )
-    local transformations = js_extract( js, "var ..={(.-)};function "..descrambler.."%(" )
-    if not transformations or not rules then
+    -- Fetch the code of the descrambler function
+    -- var Go=function(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 rules = js_extract( js, "var "..descrambler.."=function%([^)]*%){(.-)};",
+                                  -- Legacy/alternate format
+                                  "function "..descrambler.."%([^)]*%){(.-)}" )
+    if not rules then
+        return sig
+    end
+
+    -- Get the name of the helper object providing transformation definitions
+    local helper = string.match( rules, ";(..)%...%(" )
+    if not helper then
+        vlc.msg.err( "Couldn't process youtube video URL, please check for updates to this script" )
+        return sig
+    end
+
+    -- Fetch the helper object code
+    -- 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)}};
+    local transformations = js_extract( js, "var "..helper.."={(.-)};", nil )
+    if not transformations then
         return sig
     end
 



More information about the vlc-commits mailing list