]> git.sesse.net Git - vlc/blob - share/lua/playlist/zapiks.lua
koreus.lua: decode title and description
[vlc] / share / lua / playlist / zapiks.lua
1 --[[
2  $Id$
3
4  Copyright © 2011 the VideoLAN team
5
6  Authors: Konstantin Pavlov (thresh@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 function get_prefres()
24     local prefres = -1
25     if vlc.var and vlc.var.inherit then
26         prefres = vlc.var.inherit(nil, "preferred-resolution")
27         if prefres == nil then
28             prefres = -1
29         end
30     end
31     return prefres
32 end
33
34 -- Probe function.
35 function probe()
36     return vlc.access == "http"
37         and string.match( vlc.path, "zapiks.fr/(.*).html" )
38             or string.match( vlc.path, "zapiks.fr/view/." )
39             or string.match( vlc.path, "26in.fr/videos/." )
40 end
41
42 -- Parse function.
43 function parse()
44     if string.match ( vlc.path, "zapiks.fr/(.+).html" ) or string.match( vlc.path, "26in.fr/videos/" ) then
45         while true do
46             line = vlc.readline()
47             if not line then break end
48             -- Try to find video id number
49             if string.match( line, "video_src(.+)file=(%d+)\"" ) then
50                 _,_,id = string.find( line, "file=(%d+)")
51             end
52             -- Try to find title
53             if string.match( line, "(.*)</title>" ) then
54                 _,_,name = string.find( line, "(.*)</title>" )
55             end
56         end
57         return { { path = "http://www.zapiks.fr/view/index.php?file=" .. id, name = name } }
58     end
59
60     if string.match ( vlc.path, "zapiks.fr/view/." ) then
61         prefres = get_prefres()
62         while true do
63             line = vlc.readline()
64             if not line then break end
65             -- Try to find URL of video
66             if string.match( line, "<file>(.*)</file>" ) then
67                 _,_,path = string.find ( line, "<file>(.*)</file>" )
68             end
69             -- Try to find image for arturl
70             if string.match( line, "<image>(.*)</image>" ) then
71                 _,_,arturl = string.find( line, "<image>(.*)</image>" )
72             end
73             if string.match( line, "title=\"(.*)\"" ) then
74                 _,_,name = string.find( line, "title=\"(.*)\"" )
75             end
76             -- Try to find whether video is HD actually
77             if( prefres <0 or prefres >= 720 ) then
78                 if string.match( line, "<hd.file>(.*)</hd.file>" ) then
79                     _,_,path = string.find( line, "<hd.file>(.*)</hd.file>" )
80                 end
81             end
82         end
83         return { { path = path; name = name; arturl = arturl } }
84     end
85     vlc.msg.err( "Could not extract the video URL from zapiks.fr" )
86     return {}
87 end