--[[
$Id$
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
-- Helper function to get a parameter's value in a URL
function get_url_param( url, name )
local _, _, res = string.find( url, "[&?]"..name.."=([^&]*)" )
return res
end
function get_arturl( path, video_id )
if string.match( vlc.path, "iurl=" ) then
return vlc.strings( get_url_param( vlc.path, "iurl" ) )
end
if not arturl then
return "http://img.youtube.com/vi/"..video_id.."/default.jpg"
end
end
-- Probe function.
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
-- like "fr.youtube.com", "uk.youtube.com" etc..
youtube_site = string.find( vlc.path, ".youtube.com" )
if youtube_site == nil then
return false
end
end
return ( string.match( vlc.path, "watch%?v=" ) -- the html page
or string.match( vlc.path, "watch_fullscreen%?video_id=" ) -- the fullscreen page
or string.match( vlc.path, "p.swf" ) -- the (old?) player url
or string.match( vlc.path, "jp.swf" ) -- the (new?) player url (as of 24/08/2007)
or string.match( vlc.path, "player2.swf" ) ) -- another player url
end
-- Parse function.
function parse()
if string.match( vlc.path, "watch%?v=" )
then -- This is the HTML page's URL
-- fmt is the format of the video: 18 is HQ (mp4)
fmt = get_url_param( vlc.path, "fmt" )
while true do
-- Try to find the video's title
line = vlc.readline()
if not line then break end
if string.match( line, "