]> git.sesse.net Git - vlc/blob - share/lua/playlist/appletrailers.lua
ad6437fd956c4ddc55a720bd377736bf448671d8
[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 function find( haystack, needle )
30     local _,_,r = string.find( haystack, needle )
31     return r
32 end
33
34 -- Parse function.
35 function parse()
36     local playlist = {}
37     local description = ''
38     local art_url = ''
39
40     while true
41     do 
42         line = vlc.readline()
43         if not line then break end
44
45         if string.match( line, "class=\".-first" ) then
46             description = find( line, "h%d.->(.-)</h%d")
47         end
48         if string.match( line, 'img src=') then
49             for img in string.gmatch(line, '<img src="(http://.*\.jpg)" ') do
50                 art_url = img
51             end
52             for i,value in pairs(playlist) do
53                 if value.arturl == '' then
54                     playlist[i].arturl = art_url
55                 else break end
56             end
57         end
58         if string.match( line, "class=\"hd\".-\.mov") then
59             for urlline,resolution in string.gmatch(line, "class=\"hd\".-href=\"(.-.mov)\".-(%d+.-p)") do
60                 urlline = string.gsub( urlline, "_"..resolution, "_h"..resolution )
61                 table.insert( playlist, { path = urlline,
62                                           name = description .. " (" .. resolution .. ")",
63                                           arturl = art_url,
64                                           options = {":http-user-agent=QuickTime/7.2", ":demux=avformat,ffmpeg",":play-and-pause"} } )
65             end
66         end
67     end
68     return playlist
69 end