]> git.sesse.net Git - vlc/blob - share/lua/playlist/appletrailers.lua
Update lua playlist scripts to new API. (untested)
[vlc] / share / lua / playlist / appletrailers.lua
1 --[[
2    Translate trailers.apple.com video webpages URLs to the corresponding
3    movie URL
4
5  $Id$
6  Copyright © 2007 the VideoLAN team
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 --]]
22
23 -- Probe function.
24 function probe()
25     return vlc.access == "http"
26         and string.match( vlc.path, "trailers.apple.com" ) 
27 end
28
29 -- Parse function.
30 function parse()
31     p = {}
32     while true
33     do 
34         line = vlc.readline()
35         if not line then break end
36         if string.match( line, "http://movies.apple.com/movies/.*%.mov" )
37         or string.match( line, "http://images.apple.com/movies/.*%.mov" )
38         then
39             if string.match( line, "http://movies.apple.com/movies/.*%.mov" ) then
40                 path = vlc.strings.decode_uri( string.gsub( line, "^.*(http://movies.apple.com/movies/.*%.mov).*$", "%1" ) )
41             elseif string.match( line, "http://images.apple.com/movies/.*%.mov" ) then
42                 path = vlc.strings.decode_uri( string.gsub( line, "^.*(http://images.apple.com/movies/.*%.mov).*$", "%1" ) )
43             end
44             if string.match( path, "480p" ) then
45                 extraname = " (480p)"
46             elseif string.match( path, "720p" ) then
47                 extraname = " (720p)"
48             elseif string.match( path, "1080p" ) then
49                 extraname = " (1080p)"
50             else
51                 extraname = ""
52             end
53             table.insert( p, { path = path; name = title..extraname; description = description; url = vlc.path } )
54         end
55         if string.match( line, "<title>" )
56         then
57             title = vlc.strings.decode_uri( string.gsub( line, "^.*<title>([^<]*).*$", "%1" ) )
58         end
59         if string.match( line, "<meta name=\"Description\"" )
60         then
61             description = vlc.strings.resolve_xml_special_chars( string.gsub( line, "^.*name=\"Description\" content=\"([^\"]*)\".*$", "%1" ) )
62         end
63     end
64     return p
65 end