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