]> git.sesse.net Git - vlc/blobdiff - share/lua/playlist/youtube.lua
lua: update youtube script to support "html5=True" URLs
[vlc] / share / lua / playlist / youtube.lua
index 452400f16f81823f88c54283006ee3eaa24a0624..8823925658587bafdf08b911ad534245e991f4e3 100644 (file)
@@ -1,7 +1,7 @@
 --[[
  $Id$
 
- Copyright © 2007 the VideoLAN team
+ Copyright © 2007-2009 the VideoLAN team
 
  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
@@ -26,7 +26,7 @@ end
 
 function get_arturl( path, video_id )
     if string.match( vlc.path, "iurl=" ) then
-        return vlc.strings.decode_uri( get_url_param( vlc.path, "iurl" ) )
+        return vlc.strings( get_url_param( vlc.path, "iurl" ) )
     end
     if not arturl then
         return "http://img.youtube.com/vi/"..video_id.."/default.jpg"
@@ -38,6 +38,7 @@ function probe()
     if vlc.access ~= "http" then
         return false
     end
+    options = {":demux=avformat,ffmpeg"}
     youtube_site = string.match( string.sub( vlc.path, 1, 8 ), "youtube" )
     if not youtube_site then
         -- FIXME we should be using a builtin list of known youtube websites
@@ -72,15 +73,20 @@ function parse()
             if string.match( line, "subscribe_to_user=" ) then
                 _,_,artist = string.find( line, "subscribe_to_user=([^&]*)" )
             end
-            -- OLD: var swfArgs = {hl:'en',BASE_YT_URL:'http://youtube.com/',video_id:'XPJ7d8dq0t8',l:'292',t:'OEgsToPDskLFdOYrrlDm3FQPoQBYaCP1',sk:'0gnr-AE6QZJEZmCMd3lq_AC'};
-            -- NEW: var swfArgs = { "BASE_YT_URL": "http://youtube.com", "video_id": "OHVvVmUNBFc", "l": 88, "sk": "WswKuJzDBsdD6oG3IakCXgC", "t": "OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp", "plid": "AARGnwWMrmGkbpOxAAAA4AT4IAA", "tk": "mEL4E7PqHeaZp5OG19NQThHt9mXJU4PbRTOw6lz9osHi4Hixp7RE1w=="};
-            if string.match( line, "swfArgs" ) and string.match( line, "video_id" ) then
+            -- CURRENT: var swfConfig = { [a lot of stuff...], "video_id": "OHVvVmUNBFc", "sk": "WswKuJzDBsdD6oG3IakCXgC", "t": "OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp", "plid": "AARGnwWMrmGkbpOxAAAA4AT4IAA"};
+            -- OLD 1: var swfArgs = {hl:'en',BASE_YT_URL:'http://youtube.com/',video_id:'XPJ7d8dq0t8',l:'292',t:'OEgsToPDskLFdOYrrlDm3FQPoQBYaCP1',sk:'0gnr-AE6QZJEZmCMd3lq_AC'};
+            -- OLD 2: var swfArgs = { "BASE_YT_URL": "http://youtube.com", "video_id": "OHVvVmUNBFc", "l": 88, "sk": "WswKuJzDBsdD6oG3IakCXgC", "t": "OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp", "plid": "AARGnwWMrmGkbpOxAAAA4AT4IAA", "tk": "mEL4E7PqHeaZp5OG19NQThHt9mXJU4PbRTOw6lz9osHi4Hixp7RE1w=="};
+            -- OLD 3: 'SWF_ARGS': { [a lot of stuff...], "video_id": "OHVvVmUNBFc", "sk": "WswKuJzDBsdD6oG3IakCXgC", "t": "OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp", "plid": "AARGnwWMrmGkbpOxAAAA4AT4IAA"};
+            if ( string.match( line, "swfConfig" ) or string.match( line, "SWF_ARGS" ) or string.match( line, "swfArgs" ) ) and string.match( line, "video_id" ) then
                 if string.match( line, "BASE_YT_URL" ) then
                     _,_,base_yt_url = string.find( line, "\"BASE_YT_URL\": \"(.-)\"" )
                 end
                 _,_,t = string.find( line, "\"t\": \"(.-)\"" )
                 -- vlc.msg.err( t )
                 -- video_id = string.gsub( line, ".*&video_id:'([^']*)'.*", "%1" )
+            -- Also available on non-HTML5 pages: var swfHTML = (isIE) ? "<object [...]><param name=\"flashvars\" value=\"rv.2.thumbnailUrl=http%3A%2F%2Fi4.ytimg.com%2Fvi%2F3MLp7YNTznE%2Fdefault.jpg&rv.7.length_seconds=384 [...] &video_id=OHVvVmUNBFc [...] &t=OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp [...]
+            elseif string.match( line, "swfHTML" ) and string.match( line, "video_id" ) then
+                _,_,t = string.find( line, "&t=(.-)&" )
             end
             if name and description and artist --[[and video_id]] then break end
         end
@@ -99,10 +105,10 @@ function parse()
             format = ""
         end
         if t then
-            return { { path = base_yt_url .. "get_video?video_id="..video_id.."&t="..t..format; name = name; description = description; artist = artist; arturl = arturl } }
+            return { { path = base_yt_url .. "get_video?video_id="..video_id.."&t="..t..format; name = name; description = description; artist = artist; arturl = arturl; options = options } }
         else
             -- This shouldn't happen ... but keep it as a backup.
-            return { { path = "http://www.youtube.com/v/"..video_id; name = name; description = description; artist = artist; arturl = arturl } }
+            return { { path = "http://www.youtube.com/v/"..video_id; name = name; description = description; artist = artist; arturl = arturl; options=options } }
         end
     else -- This is the flash player's URL
         if string.match( vlc.path, "title=" ) then
@@ -119,8 +125,8 @@ function parse()
         if not string.match( vlc.path, "t=" ) then
             -- This sucks, we're missing "t" which is now mandatory. Let's
             -- try using another url
-            return { { path = "http://www.youtube.com/v/"..video_id; name = name; arturl = arturl } }
+            return { { path = "http://www.youtube.com/v/"..video_id; name = name; arturl = arturl; options=options } }
         end
-        return { { path = "http://www.youtube.com/get_video.php?video_id="..video_id.."&t="..get_url_param( vlc.path, "t" )..format; name = name; arturl = arturl } }
+        return { { path = "http://www.youtube.com/get_video.php?video_id="..video_id.."&t="..get_url_param( vlc.path, "t" )..format; name = name; arturl = arturl; options=options } }
     end
 end