]> git.sesse.net Git - vlc/blob - share/lua/playlist/appletrailers_iphone.lua
lua apple_iphone: strip " - .*" from title and change options
[vlc] / share / lua / playlist / appletrailers_iphone.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/trailers/iphone" ) 
27 end
28
29 function find( haystack, needle )
30     local _,_,r = string.find( haystack, needle )
31     return r
32 end
33
34 -- Parse function.
35 function parse()
36     p = {}
37     path=""
38     arturl=""
39     title=""
40     description=""
41     while true
42     do 
43         line = vlc.readline()
44         if not line then break end
45         for urli in string.gmatch( line, "http://trailers.apple.com/movies/.-%.mov" ) do
46             path = vlc.strings.decode_uri( urli )
47             vlc.msg.err(path)
48         end
49         for urli in string.gmatch( line, "http://.-%/poster.jpg") do
50             arturl = vlc.strings.decode_uri( urli )
51         end
52         if string.match( line, "<title>" )
53         then
54             title = vlc.strings.resolve_xml_special_chars( find( line, "<title>(.-)<" ) )
55             title = string.gsub( title, " %- .*", "" )
56         end
57         if string.match( line, "<meta name=\"Description\"" )
58         then
59             description = vlc.strings.resolve_xml_special_chars( find( line, "name=\"Description\" content=\"(.-)\"" ) )
60         end
61     end
62     for index,resolution in ipairs({"480p","720p","1080p"}) do
63         locationurl = string.gsub( path, "r320i.mov","h"..resolution..".mov")
64         table.insert( p, { path=locationurl ; name=title.." ("..resolution..")"; arturl=arturl; description=description; options={":http-user-agent=Quicktime/7.2.0 vlc lua edition",":play-and-pause",":demux=avformat"};} )
65     end
66     return p
67 end