test.lua 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
-- $Id$

if vlc.access ~= "http"
then
	return false
end 

url = nil
title = nil

function get_url_param( url, name )
	return string.gsub( vlc.path, "^.*"..name.."=([^&]*).*$", "%1" )
end

if string.match( vlc.path, "youtube.com" ) 
then
	if string.match( vlc.path, "watch%?v=" )
	then
		url = string.gsub( vlc.path, "^(.*)watch%?v=([^&]*).*$", "http://%1v/%2" )
		while not title
		do
			line = vlc.readline()
			if not line
			then
				break
			end
			if string.match( line, "<meta name=\"title\"" )
			then
				title = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
			end
		end
	elseif string.match( vlc.path, "watch_fullscreen%?video_id=" ) or string.match( vlc.path, "p.swf" ) or string.match( vlc.path, "player2.swf" )
	then
		video_id = get_url_param( vlc.path, "video_id" )
		t = get_url_param( vlc.path, "t" )
		url = "http://www.youtube.com/get_video.php?video_id="..video_id.."&t="..t
		if string.match( vlc.path, "title=" )
		then
			title = get_url_param( vlc.path, "title" )
		end
	end
elseif string.match( vlc.path, "dailymotion.com" )
then
	len, str = vlc.peek( 9 )
	if str == "<!DOCTYPE"
	then
		while not url
		do
			line = vlc.readline()
			if string.match( line, "param name=\"flashvars\" value=\"url=" )
			then
				url = vlc.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\"url=([^&]*).*$", "%1" ) )
			end
		end
	end
elseif string.match( vlc.path, "video.google.com" ) and string.match( vlc.path, "videoplay" )
then
	url = string.gsub( vlc.path, "^.*(docid=[^&]*).*$", "http://video.google.com/videogvp?%1" )
elseif string.match( vlc.path, "metacafe.com" )
then
	if string.match( vlc.path, "watch/" )
	then
		url = string.gsub( vlc.path, "^.*watch/(.*[^/])/?$", "http://www.metacafe.com/fplayer/%1.swf" )
	elseif string.match( vlc.path, "mediaURL=" )
	then
		url = string.gsub( vlc.path, "^.*mediaURL=([^&]*).*$", "%1" )
	end
end

if url == nil
then
	return false
else
	return true, url, title
end