Add a lua playlist script for trailers.apple.com pages.
[vlc.git] / 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             vlc.msg_err( path )
39             table.insert( p, { path = path; name = title..extraname; description = description; url = vlc.path } )
40         end
41         if string.match( line, "<title>" )
42         then
43             title = vlc.decode_uri( string.gsub( line, "^.*<title>([^<]*).*$", "%1" ) )
44         end
45         if string.match( line, "<meta name=\"Description\"" )
46         then
47             description = vlc.resolve_xml_special_chars( string.gsub( line, "^.*name=\"Description\" content=\"([^\"]*)\".*$", "%1" ) )
48         end
49     end
50     return p
51 end