]> git.sesse.net Git - vlc/blob - share/lua/playlist/appletrailers.lua
Use var_InheritString for --decklink-video-connection.
[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-2010 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 function sort(a, b)
35     if(a == nil) then return false end
36     if(b == nil) then return false end
37
38     local str_a
39     local str_b
40
41     if(string.find(a.name, '%(') == 1) then
42         str_a = tonumber(string.sub(a.name, 2, string.find(a.name, 'p') - 1))
43         str_b = tonumber(string.sub(b.name, 2, string.find(b.name, 'p') - 1))
44     else
45         str_a = string.sub(a.name, 1, string.find(a.name, '%(') - 2)
46         str_b = string.sub(b.name, 1, string.find(b.name, '%(') - 2)
47         if(str_a == str_b) then
48             str_a = tonumber(string.sub(a.name, string.len(str_a) + 3, string.find(a.name, 'p', string.len(str_a) + 3) - 1))
49             str_b = tonumber(string.sub(b.name, string.len(str_b) + 3, string.find(b.name, 'p', string.len(str_b) + 3) - 1))
50         end
51     end
52     if(str_a > str_b) then return false else return true end
53 end
54
55 -- Parse function.
56 function parse()
57     local playlist = {}
58     local description = ''
59     local art_url = ''
60
61     while true
62     do 
63         line = vlc.readline()
64         if not line then break end
65
66         if string.match( line, "class=\".-first" ) then
67             description = find( line, "h%d.->(.-)</h%d") .. ' '
68         end
69         if string.match( line, 'img src=') then
70             for img in string.gmatch(line, '<img src="(http://.*\.jpg)" ') do
71                 art_url = img
72             end
73             for i,value in pairs(playlist) do
74                 if value.arturl == '' then
75                     playlist[i].arturl = art_url
76                 else break end
77             end
78         end
79         if string.match( line, "class=\"hd\".-\.mov") then
80             for urlline,resolution in string.gmatch(line, "class=\"hd\".-href=\"(.-.mov)\".-(%d+.-p)") do
81                 urlline = string.gsub( urlline, "_"..resolution, "_h"..resolution )
82                 table.insert( playlist, { path = urlline,
83                                           name = description ..  '(' .. resolution .. ')',
84                                           arturl = art_url,
85                                           options = {":http-user-agent=QuickTime/7.2", ":demux=avformat,ffmpeg",":play-and-pause"} } )
86             end
87         end
88     end
89
90     table.sort(playlist, sort)
91     return playlist
92 end