]> git.sesse.net Git - vlc/blob - share/lua/playlist/canalplus.lua
1a59956dc3151c9870924d0e85c620d2b8bef57a
[vlc] / share / lua / playlist / canalplus.lua
1 --[[
2  $Id: $
3
4  Copyright © 2007 the VideoLAN team
5
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 --]]
20
21 -- Probe function.
22 function probe()
23     return vlc.access == "http" and string.match( vlc.path, "www.canalplus.fr" )
24 end
25
26 -- Parse function.
27 function parse()
28     p = {}
29     --vlc.msg.dbg( vlc.path )
30     if string.match( vlc.path, "www.canalplus.fr/index.php%?pid=" )
31     then -- This is the HTML page's URL
32         local id, name, description, arturl
33         while true do
34             -- Try to find the video's title
35             local line = vlc.readline()
36             if not line then break end
37             -- vlc.msg.dbg( line )
38             if string.match( line, "aVideos" ) then
39                 if string.match( line, "CONTENT_ID.*=" ) then
40                     id = string.gsub( line, "^.*\"(.-)\".*$", "%1" )
41                 elseif string.match( line, "CONTENT_VNC_TITRE" ) then
42                     arturl = string.gsub( line, "^.*src=\"(.-)\".*$", "%1" )
43                     name = string.gsub( line, "^.*alt=\"(.-)\".*$", "%1" )
44                 elseif string.match( line, "CONTENT_VNC_DESCRIPTION" ) then
45                     description = string.gsub( line, "^.*\"(.-)\".*$", "%1" )
46                 end
47                 if id and string.match( line, "new Array" ) then
48                     add_item( p, id, name, description, arturl )
49                     id = nil
50                     name = nil
51                     arturl = nil
52                     description = nil
53                 end
54             end
55         end
56         if id then
57             add_item( p, id, name, description, arturl )
58         end
59         return p
60     elseif string.match( vlc.path, "embed%-video%-player" ) then
61         while true do
62             local line = vlc.readline()
63             if not line then break end
64             --vlc.msg.dbg( line )
65             if string.match( line, "<hi>" ) then
66                 local path = string.gsub( line, "^.*%[(.-)%].*$", "%1" )
67                 vlc.msg.err("Path is: " .. tostring( path ) )
68                 return { { path = path } }
69             end
70         end
71     end
72 end
73
74 function get_url_param( url, name )
75     return string.gsub( url, "^.*[&?]"..name.."=([^&]*).*$", "%1" )
76 end
77
78 function add_item( p, id, name, description, arturl )
79     --[[vlc.msg.dbg( "id: " .. tostring(id) )
80     vlc.msg.dbg( "name: " .. tostring(name) )
81     vlc.msg.dbg( "arturl: " .. tostring(arturl) )
82     vlc.msg.dbg( "description: " .. tostring(description) )
83     --]]
84     --local path = "http://www.canalplus.fr/flash/xml/configuration/configuration-embed-video-player.php?xmlParam="..id.."-"..get_url_param(vlc.path,"pid")
85     local path = "http://www.canalplus.fr/flash/xml/module/embed-video-player/embed-video-player.php?video_id="..id.."&pid="..get_url_param(vlc.path,"pid")
86     table.insert( p, { path = path; name = name; description = description; arturl = arturl } )
87 end