]> git.sesse.net Git - vlc/blob - share/luaplaylist/megavideo.lua
8c5763c5f4876d40c1edc60b824db63a90c22412
[vlc] / share / luaplaylist / 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
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
60                     if c < 16 and c > 3 then key = 61
61                     elseif c < 96 and c > 67 then key = 189
62                     elseif c < 20 and c > 6 then key = 65
63                     else vlc.msg_err("Oops, please report URL to developers")
64                     end
65                 else
66                     if c < 16 and c > 3 then key = 65
67                     elseif c < 96 and c > 67 then key = 193
68                     elseif c < 20 and c > 6 then key = 65
69                     else vlc.msg_err("Oops, please report URL to developers")
70                     end
71                 end
72                 i = i + 1
73                 path = path .. string.char(key - c)
74             end
75         end
76         if path then break end
77     end
78     print( path )
79     if path then
80         return { { path = path } }
81     else
82         return { }
83     end
84 end