]> git.sesse.net Git - vlc/blob - share/luaplaylist/test.lua
234f205742dabd1d80c52c91cec12713b5bfa140
[vlc] / share / luaplaylist / test.lua
1 -- $Id$
2
3 if vlc.access ~= "http"
4 then
5     return false
6 end 
7
8 url = nil
9 title = nil
10
11 function get_url_param( url, name )
12     return string.gsub( vlc.path, "^.*"..name.."=([^&]*).*$", "%1" )
13 end
14
15 if string.match( vlc.path, "youtube.com" ) 
16 then
17     if string.match( vlc.path, "watch%?v=" )
18     then
19         url = string.gsub( vlc.path, "^(.*)watch%?v=([^&]*).*$", "http://%1v/%2" )
20         while not title
21         do
22             line = vlc.readline()
23             if not line
24             then
25                 break
26             end
27             if string.match( line, "<meta name=\"title\"" )
28             then
29                 title = string.gsub( line, "^.*content=\"([^\"]*).*$", "%1" )
30             end
31         end
32     elseif string.match( vlc.path, "watch_fullscreen%?video_id=" ) or string.match( vlc.path, "p.swf" ) or string.match( vlc.path, "player2.swf" )
33     then
34         video_id = get_url_param( vlc.path, "video_id" )
35         t = get_url_param( vlc.path, "t" )
36         url = "http://www.youtube.com/get_video.php?video_id="..video_id.."&t="..t
37         if string.match( vlc.path, "title=" )
38         then
39             title = get_url_param( vlc.path, "title" )
40         end
41     end
42 elseif string.match( vlc.path, "dailymotion.com" )
43 then
44     len, str = vlc.peek( 9 )
45     if str == "<!DOCTYPE"
46     then
47         while not url
48         do
49             line = vlc.readline()
50             if string.match( line, "param name=\"flashvars\" value=\"url=" )
51             then
52                 url = vlc.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\"url=([^&]*).*$", "%1" ) )
53             end
54         end
55     end
56 elseif string.match( vlc.path, "video.google.com" ) and string.match( vlc.path, "videoplay" )
57 then
58     url = string.gsub( vlc.path, "^.*(docid=[^&]*).*$", "http://video.google.com/videogvp?%1" )
59 elseif string.match( vlc.path, "metacafe.com" )
60 then
61     if string.match( vlc.path, "watch/" )
62     then
63         url = string.gsub( vlc.path, "^.*watch/(.*[^/])/?$", "http://www.metacafe.com/fplayer/%1.swf" )
64     elseif string.match( vlc.path, "mediaURL=" )
65     then
66         url = string.gsub( vlc.path, "^.*mediaURL=([^&]*).*$", "%1" )
67     end
68 end
69
70 if url == nil
71 then
72     return false
73 else
74     return true, url, title
75 end