2 French humor site: http://lelombrik.net
6 Copyright © 2007 the VideoLAN team
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 -- Helper function to get a parameter's value in a URL
24 function get_url_param( url, name )
25 return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" )
28 function get_arturl( path, video_id )
29 if string.match( vlc.path, "iurl=" ) then
30 return vlc.decode_uri( get_url_param( vlc.path, "iurl" ) )
33 return "http://img.youtube.com/vi/"..video_id.."/default.jpg"
39 if vlc.access ~= "http" then
42 youtube_site = string.match( string.sub( vlc.path, 1, 8 ), "youtube" )
43 if not youtube_site then
44 -- FIXME we should be using a builtin list of known youtube websites
45 -- like "fr.youtube.com", "uk.youtube.com" etc..
46 youtube_site = string.find( vlc.path, ".youtube.com" )
47 if youtube_site == nil then
51 return ( string.match( vlc.path, "watch%?v=" ) -- the html page
52 or string.match( vlc.path, "watch_fullscreen%?video_id=" ) -- the fullscreen page
53 or string.match( vlc.path, "p.swf" ) -- the (old?) player url
54 or string.match( vlc.path, "jp.swf" ) -- the (new?) player url (as of 24/08/2007)
55 or string.match( vlc.path, "player2.swf" ) ) -- another player url
60 if string.match( vlc.path, "watch%?v=" )
61 then -- This is the HTML page's URL
63 -- Try to find the video's title
65 if not line then break end
66 if string.match( line, "<meta name=\"title\"" ) then
67 name = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
69 if string.match( line, "<meta name=\"description\"" ) then
70 description = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
72 if string.match( line, "subscribe_to_user=" ) then
73 artist = string.gsub( line, ".*subscribe_to_user=([^&]*).*", "%1" )
75 -- var swfArgs = {hl:'en',BASE_YT_URL:'http://youtube.com/',video_id:'XPJ7d8dq0t8',l:'292',t:'OEgsToPDskLFdOYrrlDm3FQPoQBYaCP1',sk:'0gnr-AE6QZJEZmCMd3lq_AC'};
76 if string.match( line, "swfArgs" ) and string.match( line, "video_id" ) then
77 if string.match( line, "BASE_YT_URL" ) then
78 base_yt_url = string.gsub( line, ".*BASE_YT_URL:'([^']*)'.*", "%1" )
80 t = string.gsub( line, ".*t:'([^']*)'.*", "%1" )
82 -- video_id = string.gsub( line, ".*&video_id:'([^']*)'.*", "%1" )
84 if name and description and artist --[[and video_id]] then break end
87 video_id = get_url_param( vlc.path, "v" )
89 if not base_yt_url then
90 base_yt_url = "http://youtube.com/"
92 art_url = get_arturl( vlc.path, video_id )
94 return { { path = base_yt_url .. "get_video?video_id="..video_id.."&t="..t; name = name; description = description; artist = artist; arturl = arturl } }
96 -- This shouldn't happen ... but keep it as a backup.
97 return { { path = "http://www.youtube.com/v/"..video_id; name = name; description = description; artist = artist; arturl = arturl } }
99 else -- This is the flash player's URL
100 if string.match( vlc.path, "title=" ) then
101 name = get_url_param( vlc.path, "title" )
103 video_id = get_url_param( vlc.path, "video_id" )
104 art_url = get_arturl( vlc.path, video_id )
105 if not string.match( vlc.path, "t=" ) then
106 -- This sucks, we're missing "t" which is now mandatory. Let's
107 -- try using another url
108 return { { path = "http://www.youtube.com/v/"..video_id; name = name; arturl = arturl } }
110 return { { path = "http://www.youtube.com/get_video.php?video_id="..video_id.."&t="..get_url_param( vlc.path, "t" ); name = name; arturl = arturl } }