]> git.sesse.net Git - vlc/blob - share/lua/playlist/megavideo.lua
macosx: Fix crashlog opening.
[vlc] / share / lua / playlist / megavideo.lua
1 --[[
2     Translate MegaVideo video webpages URLs to the corresponding FLV URL.
3
4  $Id$
5
6  Copyright © 2008 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, "megavideo.com" ) 
27 end
28
29 -- Parse function.
30 function parse()
31
32     -- we have to get the xml
33     if string.match( vlc.path, "www.megavideo.com.*&v=.*&u=.*" ) then
34         id = string.gsub( vlc.path, "www.megavideo.com.*v=([^&]*).*$", "%1" )
35         path = "http://www.megavideo.com/xml/videolink.php?v=" .. id
36         return { { path = path } }
37     end
38
39     while true
40     do 
41         line = vlc.readline()
42         if not line then break end
43
44         -- we got the xml
45         if string.match( line, "<ROWS><ROW url=\"" )
46         then
47             xml = ""
48             while line do
49                 -- buffer the full xml
50                 xml = xml .. line .. '\n'
51                 line = vlc.readline()
52             end
53             -- now gets the encoded url
54             s = string.gsub( xml, ".*ROW url=\"([^\"]*).*", "%1" )
55             path = ""
56             i = 1
57             while s:byte(i) do
58                 c = s:byte(i)
59                 if c % 4 < 2 then mod = 0 else mod = 4 end
60                 if c < 16 and c > 3 then key = 61 + mod
61                 elseif c < 96 and c > 67 then key = 189 + mod
62                 elseif c < 20 and c > 6 then key = 65
63                 else vlc.msg.err("Oops, please report URL to developers")
64                 end
65                 i = i + 1
66                 path = path .. string.char(key - c)
67             end
68         end
69         if path then break end
70     end
71     if path then
72         return { { path = path } }
73     else
74         return { }
75     end
76 end