]> git.sesse.net Git - vlc/blob - share/luaplaylist/appletrailers.lua
3297f9186454a890aa5e94f6a18ed17d4978f689
[vlc] / share / luaplaylist / appletrailers.lua
1 -- $Id$
2
3 --[[
4     Translate trailers.apple.com video webpages URLs to the corresponding
5     movie URL
6 --]]
7
8 -- Probe function.
9 function probe()
10     return vlc.access == "http"
11         and string.match( vlc.path, "trailers.apple.com" ) 
12 end
13
14 -- Parse function.
15 function parse()
16     p = {}
17     while true
18     do 
19         line = vlc.readline()
20         if not line then break end
21         if string.match( line, "http://movies.apple.com/movies/.*%.mov" )
22         or string.match( line, "http://images.apple.com/movies/.*%.mov" )
23         then
24             if string.match( line, "http://movies.apple.com/movies/.*%.mov" ) then
25                 path = vlc.decode_uri( string.gsub( line, "^.*(http://movies.apple.com/movies/.*%.mov).*$", "%1" ) )
26             elseif string.match( line, "http://images.apple.com/movies/.*%.mov" ) then
27                 path = vlc.decode_uri( string.gsub( line, "^.*(http://images.apple.com/movies/.*%.mov).*$", "%1" ) )
28             end
29             if string.match( path, "480p" ) then
30                 extraname = " (480p)"
31             elseif string.match( path, "720p" ) then
32                 extraname = " (720p)"
33             elseif string.match( path, "1080p" ) then
34                 extraname = " (1080p)"
35             else
36                 extraname = ""
37             end
38             table.insert( p, { path = path; name = title..extraname; description = description; url = vlc.path } )
39         end
40         if string.match( line, "<title>" )
41         then
42             title = vlc.decode_uri( string.gsub( line, "^.*<title>([^<]*).*$", "%1" ) )
43         end
44         if string.match( line, "<meta name=\"Description\"" )
45         then
46             description = vlc.resolve_xml_special_chars( string.gsub( line, "^.*name=\"Description\" content=\"([^\"]*)\".*$", "%1" ) )
47         end
48     end
49     return p
50 end