]> git.sesse.net Git - vlc/blob - share/lua/playlist/liveleak.lua
bpg: add libbpg decoder
[vlc] / share / lua / playlist / liveleak.lua
1 --[[
2  $Id$
3
4  Copyright © 2012 VideoLAN and AUTHORS
5
6  Authors: Ludovic Fauvet <etix@videolan.org>
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, "www.liveleak.com/view" )
27 end
28
29 -- Util function
30 function find( haystack, needle )
31     local _,_,r = string.find( haystack, needle )
32     return r
33 end
34
35 -- Parse function.
36 function parse()
37     local p = {}
38     local title
39     local art
40     local video
41
42     while true do
43         line = vlc.readline()
44         if not line then break end
45
46         -- Try to find the title
47         if string.match( line, '<span class="section_title"' ) then
48             title = find( line, '<span class="section_title"[^>]*>(.-)<' )
49             title = string.gsub( title, '&nbsp;', ' ' )
50         end
51
52         -- Try to find the art
53         if string.match( line, 'image:' ) then
54             art = find( line, 'image: "(.-)"' )
55         end
56
57         -- Try to find the video
58         if string.match( line, 'file:' ) then
59             video = find( line, 'file: "(.-)"' )
60         end
61     end
62     if video then
63         table.insert( p, { path = video; name = title; arturl = art; } )
64     end
65     return p
66 end
67