]> git.sesse.net Git - vlc/blob - share/lua/playlist/extreme.lua
Lua: extreme.com playlist parser.
[vlc] / share / lua / playlist / extreme.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, "extreme.com/." )
38         or string.match( vlc.path, "freecaster.tv/." )
39         or string.match( vlc.path, "player.extreme.com/info/.")
40 end
41
42 -- Parse function.
43 function parse()
44     if (string.match( vlc.path, "extreme\.com/." ) or string.match( vlc.path, "freecaster\.tv/." )) and not string.match( vlc.path, "player.extreme.com/info/") then
45         while true do
46             line = vlc.readline()
47             if not line then break end
48             -- Try to find id of the video
49             if string.match( line, "http://player.extreme.com/FCPlayer.swf" ) then
50                 _,_,vid = string.find( line, "id=(.*)\"" )
51                 break
52             end
53         end
54         return { { path = "http://player.extreme.com/info/" .. vid; name = "extreme.com video"; } }
55     end
56
57     if string.match( vlc.path, "player.extreme.com/info/." ) then
58         prefres = get_prefres()
59         gostraight = true
60         while true do
61             line = vlc.readline()
62             if not line then break end
63             -- Try to find the video's title
64             if string.match( line, "title>(.*)<" ) then
65                 _,_,name = string.find( line, "<title>(.*)<" )
66             end
67
68             -- Try to find image for thumbnail
69             if string.match( line, "<path>(*.)</path>" ) then
70                 _,_,arturl = string.find( line, "<path>(*.)</path>" )
71             end
72
73             -- Try to find out if its a freecaster streaming or just a link to some
74             -- other video streaming website
75             -- FIXME: I was unable to find any http-based freecaster streams,
76             -- but I remember there were some a few months back.
77             -- Right now we assume everything is streamed using RTMP, so we feed them to avio.
78             if string.match( line, "<streams type=\"5\" server=\"(.*)\">" )
79                 then
80                 _,_,rtmpserver = string.find( line, "<streams type=\"5\" server=\"(.*)\">" )
81                 gostraight = false
82             end
83
84             -- if we're going outside, we need to find out the path
85             if gostraight then
86                 if string.match( line, ">(.*)</stream>" ) then
87                     _,_,path = string.find( line, "bitrate=\"0\" duration=\"\">(.*)</stream>" )
88                 end
89             end
90
91             -- and if we're using freecaster, use appropriate resolution
92             if not gostraight then
93                 if string.match( line, "height=\"(.*)\" duration" ) then
94                     _,_,height = string.find( line, "height=\"(%d+)\" duration" )
95                     _,_,playpath  = string.find( line, "\">(.*)</stream>" )
96                     if ( prefres < 0 or tonumber( height ) <= prefres ) then
97                         path = "avio://" .. rtmpserver .. " playpath=" .. playpath
98                     end
99                 end
100             end
101         end
102
103         return { { path = path; name = name; arturl = arturl } }
104
105     end
106
107 end