static int vlclua_stream_new_inner( lua_State *L, stream_t *p_stream )
{
if( !p_stream )
- return luaL_error( L, "Error when opening stream" );
+ {
+ lua_pushnil( L );
+ lua_pushliteral( L, "Error when opening stream" );
+ return 2;
+ }
stream_t **pp_stream = lua_newuserdata( L, sizeof( stream_t * ) );
*pp_stream = p_stream;
Stream
------
stream( url ): Instantiate a stream object for specific url.
+memory_stream( string ): Instantiate a stream object containing a specific string.
+ Those two functions return the stream object upon success and nil if an
+ error occured, in that case, the second return value will be an error message.
s = vlc.stream( "http://www.videolan.org/" )
s:read( 128 ) -- read up to 128 characters. Return 0 if no more data is available (FIXME?).
-- Search IMDb
local url = "http://www.imdb.com/find?s=all&q="
local title = string.gsub(txt:get_text(), " ", "+")
- local s = vlc.stream(url .. title)
+ local s, msg = vlc.stream(url .. title)
+ if not s then
+ vlc.msg.warn(msg)
+ return
+ end
-- Fetch HTML data
local data = s:read(65000)
-- userLink:set_text("<a href=\"url\">" .. url .. "</a>")
- local s = vlc.stream(url)
+ local s, msg = vlc.stream(url)
+ if not s then
+ vlc.msg.warn(msg)
+ return
+ end
+
data = s:read(65000)
text = "<h1>" .. titles[sel].title .. " (" .. titles[sel].year .. ")</h1>"
text = text .. actors .. "</table>"
text = text .. "<h2>Plot Summary</h2>"
- s = vlc.stream(url .. "plotsummary")
+ s, msg = vlc.stream(url .. "plotsummary")
+ if not s then
+ vlc.msg.warn(msg)
+ return
+ end
data = s:read(65000)
-- We read only the first summary
l = nil
vlc.msg.dbg( query )
local s = vlc.stream( query )
+ if not s then return nil end
local page = s:read( 65653 )
-- FIXME: multiple results may be available
return nil
end
fd = vlc.stream( "http://images.google.com/images?q=" .. get_query( title ) )
+ if not fd then return nil end
+
page = fd:read( 65653 )
fd = nil
_, _, arturl = string.find( page, "imgurl=([^&]+)" )
end
local fd = vlc.stream("http://services.tvrage.com/feeds/search.php?show=" .. get_query(showName))
+ if not fd then return nil end
local page = fd:read( 65653 )
fd = nil
_, _, showid = string.find( page, "<showid>(.-)</showid>" )
end
fd = vlc.stream("http://services.tvrage.com/feeds/full_show_info.php?sid=" .. showid)
+ if not fd then return nil end
page = fd:read( 65653 )
fd = nil
_, _, season = string.find(page, "<Season no=\""..seasonNumber.."\">(.-)</Season>")
-- text content (string)
--]]
-local function parsexml(stream)
+local function parsexml(stream, errormsg)
+ if not stream then return nil, errormsg end
local xml = vlc.xml()
local reader = xml:create_reader(stream)
end
function main()
- local fd = vlc.stream( "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u" )
+ local fd, msg = vlc.stream( "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u" )
+ if not fd then
+ vlc.msg.warn(msg)
+ return nil
+ end
local line= fd:readline()
if line ~= "#EXTM3U" then
return nil