]> git.sesse.net Git - vlc/blob - share/lua/playlist/googlevideo.lua
Do not use obsolescent ctime(_r)
[vlc] / share / lua / playlist / googlevideo.lua
1 --[[
2  $Id$
3
4  Copyright © 2007 the VideoLAN team
5
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 --]]
20
21 function get_url_param( url, name )
22     local _,_,ret = string.find( url, "[&?]"..name.."=([^&]*)" )
23     return ret
24 end
25
26 -- Probe function.
27 function probe()
28     return vlc.access == "http"
29         and string.match( vlc.path, "video.google.com" ) 
30         and ( string.match( vlc.path, "videoplay" )
31             or string.match( vlc.path, "videofeed" ) )
32 end
33
34 function get_arg( line, arg )
35     return string.gsub( line, "^.*"..arg.."=\"(.-)\".*$", "%1" )
36 end
37
38 -- Parse function.
39 function parse()
40     local docid = get_url_param( vlc.path, "docid" ) 
41     if string.match( vlc.path, "videoplay" ) then
42         return { { path = "http://video.google.com/videofeed?docid=" .. docid } }
43     elseif string.match( vlc.path, "videofeed" ) then
44         local path = nil
45         local arturl
46         local duration
47         local name
48         local description
49         while true
50         do
51             local line = vlc.readline()
52             if not line then break end
53             if string.match( line, "media:content.*flv" )
54             then
55                 local _,_,s = string.find( line, "<media:content(.-)/>" )
56                 path = vlc.strings.resolve_xml_special_chars(get_arg( s, "url" ))
57                 duration = get_arg( s, "duration" )
58             end
59             if string.match( line, "media:thumbnail" )
60             then
61                 local _,_,s = string.find( line, "<media:thumbnail(.-)/>" )
62                 arturl = vlc.strings.resolve_xml_special_chars(get_arg( s, "url" ))
63             end
64             if string.match( line, "media:title" )
65             then
66                 _,_,name = string.find( line, "<media:title>(.-)</media:title>" )
67             end
68             if string.match( line, "media:description" )
69             then
70                 _,_,description = string.find( line, "<media:description>(.-)</media:description>" )
71             end
72         end
73         return { { path = path; name = name; arturl = arturl; duration = duration; description = description } }
74     end
75 end