2007-05-15 00:27:36 +02:00
|
|
|
-- $Id$
|
|
|
|
|
|
|
|
-- Helper function to get a parameter's value in a URL
|
|
|
|
function get_url_param( url, name )
|
|
|
|
return string.gsub( vlc.path, "^.*"..name.."=([^&]*).*$", "%1" )
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Probe function.
|
|
|
|
function probe()
|
|
|
|
return vlc.access == "http"
|
|
|
|
and string.match( vlc.path, "youtube.com" )
|
|
|
|
and ( string.match( vlc.path, "watch%?v=" )
|
|
|
|
or string.match( vlc.path, "watch_fullscreen%?video_id=" )
|
|
|
|
or string.match( vlc.path, "p.swf" )
|
|
|
|
or string.match( vlc.path, "player2.swf" ) )
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Parse function.
|
|
|
|
function parse()
|
|
|
|
if string.match( vlc.path, "watch%?v=" )
|
|
|
|
then -- This is the HTML page's URL
|
|
|
|
while true do
|
|
|
|
-- Try to find the video's title
|
|
|
|
line = vlc.readline()
|
|
|
|
if not line then break end
|
|
|
|
if string.match( line, "<meta name=\"title\"" ) then
|
2007-05-17 22:34:58 +02:00
|
|
|
name = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
|
2007-05-15 00:27:36 +02:00
|
|
|
end
|
2007-05-17 22:34:58 +02:00
|
|
|
if string.match( line, "<meta name=\"description\"" ) then
|
|
|
|
description = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
|
|
|
|
end
|
|
|
|
if string.match( line, "subscribe_to_user=" ) then
|
|
|
|
artist = string.gsub( line, ".*subscribe_to_user=([^&]*).*", "%1" )
|
|
|
|
end
|
2007-08-18 02:57:17 +02:00
|
|
|
if string.match( line, "player2.swf" ) then
|
2007-08-19 21:16:28 +02:00
|
|
|
video_id = string.gsub( line, ".*&video_id=([^\"]*).*", "%1" )
|
2007-08-18 02:57:17 +02:00
|
|
|
end
|
|
|
|
if name and description and artist and video_id then break end
|
2007-05-15 00:27:36 +02:00
|
|
|
end
|
2007-08-18 02:57:17 +02:00
|
|
|
return { { path = "http://www.youtube.com/get_video.php?video_id="..video_id; name = name; description = description; artist = artist } }
|
2007-05-15 00:27:36 +02:00
|
|
|
else -- This is the flash player's URL
|
|
|
|
if string.match( vlc.path, "title=" ) then
|
2007-05-17 22:34:58 +02:00
|
|
|
name = get_url_param( vlc.path, "title" )
|
2007-05-15 00:27:36 +02:00
|
|
|
end
|
2007-05-17 22:34:58 +02:00
|
|
|
return { { path = "http://www.youtube.com/get_video.php?video_id="..get_url_param( vlc.path, "video_id" ).."&t="..get_url_param( vlc.patch, "t" ); name = name } }
|
2007-05-15 00:27:36 +02:00
|
|
|
end
|
|
|
|
end
|