]> git.sesse.net Git - vlc/blob - share/lua/sd/freebox.lua
metachannels: fix search function too
[vlc] / share / lua / sd / freebox.lua
1 --[[
2  $Id$
3
4  Copyright © 2010 VideoLAN and AUTHORS
5
6  Authors: Fabio Ritrovato <sephiroth87 at videolan dot 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 descriptor()
24     return { title="Freebox TV" }
25 end
26
27 function main()
28     local logos = {}
29
30     -- fetch urls for basic channels logos
31     local fd, msg = vlc.stream( "http://free.fr/adsl/pages/television/services-de-television/acces-a-plus-250-chaines/bouquet-basique.html" )
32     if not fd then
33         vlc.msg.warn(msg)
34         -- not fatal
35     else
36         local channel, logourl
37         local line = fd:readline()
38         while line ~= nil do
39             if( string.find( line, "tv%-chaine%-" ) ) then
40                 _, _, channel, logourl = string.find( line, "\"tv%-chaine%-(%d+)\".*<img%s*src=\"([^\"]*)\"" )
41                 -- fix spaces
42                 logourl = string.gsub( logourl, " ", "%%20" )
43                 logos[channel] = "http://free.fr" .. logourl
44             end
45             line = fd:readline()
46         end
47     end
48
49     -- fetch urls for optional channels logos
50     local fd, msg = vlc.stream( "http://www.free.fr/adsl/pages/television/services-de-television/acces-a-plus-250-chaines/en-option.html" )
51     if not fd then
52         vlc.msg.warn(msg)
53         -- not fatal
54     else
55         local channel, logourl
56         local line = fd:readline()
57         while line ~= nil do
58             if( string.find( line, "tv%-chaine%-" ) ) then
59                 _, _, channel, logourl = string.find( line, "\"tv%-chaine%-(%d+)\".*<img%s*src=\"([^\"]*)\"" )
60                 -- fix spaces
61                 logourl = string.gsub( logourl, " ", "%%20" )
62                 logos[channel] = "http://free.fr" .. logourl
63             end
64             line = fd:readline()
65         end
66     end
67
68     -- fetch the playlist
69     fd, msg = vlc.stream( "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u" )
70     if not fd then
71         vlc.msg.warn(msg)
72         return nil
73     end
74     local line=  fd:readline()
75     if line ~= "#EXTM3U" then
76         return nil
77     end
78     line = fd:readline()
79     local duration, artist, name, arturl
80     local options={"deinterlace=1"}
81     while line ~= nil do
82         if( string.find( line, "#EXTINF" ) ) then
83             _, _, duration, artist, name = string.find( line, ":(%w+),(%w+)%s*-%s*(.+)" )
84             arturl = logos[artist]
85         elseif( string.find( line, "#EXTVLCOPT" ) ) then
86             _, _, option = string.find( line, ":(.+)" )
87             table.insert( options, option )
88         else
89             vlc.sd.add_item( {path=line,duration=duration,artist=artist,title=name,arturl=arturl,options=options} )
90             duration = nil
91             artist = nil
92             name = nil
93             arturl = nil
94             options={"deinterlace=1"}
95         end
96         line = fd:readline()
97     end
98 end