2013-01-11 23:11:33 +00:00
--[==========================================================================[
2013-01-24 23:24:47 +00:00
syncplay.lua : Syncplay interface module for VLC
2013-01-11 23:11:33 +00:00
--[==========================================================================[
2014-05-19 13:49:52 +00:00
Principal author : Etoh
Other contributors : DerGenaue , jb
2013-01-24 23:24:47 +00:00
Project : http : // syncplay.pl /
2014-06-29 17:20:24 +00:00
Version : 0.2 .2
2014-06-02 19:27:53 +00:00
2013-12-22 21:36:36 +00:00
Note :
* This interface module is intended to be used in conjunction with Syncplay .
* Syncplay provides synchronized video playback across multiple media player instances over the net .
* Syncplay allows group of people who all have the same videos to watch them together wherever they are .
* Syncplay is available to download for free from http : // syncplay.pl /
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
--[==========================================================================[
2013-01-24 23:52:01 +00:00
=== Installation instructions ===
2014-01-29 17:49:19 +00:00
Place the syncplay.lua file in the main ( all user ) VLC / lua / intf / sub - directory :
2013-07-19 10:13:59 +00:00
* Window : % ProgramFiles % \ VideoLAN \ VLC \ lua \ intf \
* Linux : / usr / lib / vlc / lua / intf /
* Mac OS X : / Applications / VLC.app / Contents / MacOS / share / lua / intf /
2013-01-24 23:52:01 +00:00
2014-01-29 17:49:19 +00:00
You may also need to re - copy the syncplay.lua file when you update VLC .
2013-01-27 19:56:53 +00:00
2013-01-24 23:24:47 +00:00
=== Commands and responses ===
= Note : ? denotes optional responses ; * denotes mandatory response ; uses \ n terminator .
2013-01-13 22:51:15 +00:00
.
? >> inputstate - change : [ < input / no - input > ]
2013-01-24 23:24:47 +00:00
? >> filepath - change - notification
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
* >> playstate : [ < playing / paused / no - input > ]
* >> position : [ < decimal seconds / no - input > ]
get - interface - version
2013-01-24 23:24:47 +00:00
* >> interface - version : [ syncplay connector version ]
2014-06-02 19:27:53 +00:00
2013-01-24 23:24:47 +00:00
get - duration
* >> duration : [ < duration / no - input > ]
2014-06-02 19:27:53 +00:00
2013-01-24 23:24:47 +00:00
get - filepath
* >> filepath : [ < filepath / no - input > ]
2014-06-02 19:27:53 +00:00
2013-01-24 23:24:47 +00:00
get - filename
* >> filepath : [ < filename / no - input > ]
2014-06-02 19:27:53 +00:00
2014-03-08 16:31:42 +00:00
get - title
* >> title : [ < title / no - input > ]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
set - position : [ decimal seconds ]
? >> play - error : no - input
2014-06-02 19:27:53 +00:00
2014-03-08 16:31:42 +00:00
seek - within - title : [ decimal seconds ]
? >> seek - within - title - error : no - input
2013-01-13 22:51:15 +00:00
set - playstate : [ < playing / paused > ]
? >> set - playstate - error : no - input
set - rate : [ decimal rate ]
? >> set - rate - error : no - input
2014-06-02 19:27:53 +00:00
2014-03-08 16:31:42 +00:00
set - title
? >> set - title - error : no - input
2013-01-13 22:51:15 +00:00
display - osd : [ placement on screen < center / left / right / top / bottom / top - left / top - right / bottom - left / bottom - right > ] , [ duration in seconds ] , [ message ]
? >> display - osd - error : no - input
2013-06-11 13:01:25 +00:00
load - file : [ filepath ]
* >> load - file - attempted
2013-01-13 22:51:15 +00:00
close - vlc
[ Unknown command ]
* >> [ Unknown command ] - error : unknown - command
2013-01-11 23:11:33 +00:00
--]==========================================================================]
2013-07-04 15:56:22 +00:00
local modulepath = config [ " modulepath " ]
if ( modulepath ~= nil ) and ( modulepath ~= " " ) then
-- Workaround for when the script is not being run from the usual VLC intf folder.
package.path = modulepath
pcall ( require , " common " )
else
require " common "
end
2013-01-27 19:56:53 +00:00
2014-06-29 17:20:24 +00:00
local connectorversion = " 0.2.2 "
2014-05-19 13:49:52 +00:00
local durationdelay = 500000 -- Pause for get_duration command etc for increased reliability (uses microseconds)
2014-06-02 19:27:53 +00:00
local loopsleepduration = 5000 -- Pause for every event loop (uses microseconds)
local quitcheckfrequency = 20 -- Check whether VLC has closed every X loops
2013-11-10 01:45:44 +00:00
local host = " localhost "
2013-01-11 23:11:33 +00:00
local port
2014-03-08 16:31:42 +00:00
local titlemultiplier = 604800 -- One week
2013-01-11 23:11:33 +00:00
local msgterminator = " \n "
local msgseperator = " : "
local argseperator = " , "
local responsemarker = " -response "
local errormarker = " -error "
2013-01-13 22:51:15 +00:00
local notificationmarker = " -notification "
2013-01-11 23:11:33 +00:00
local noinput = " no-input "
local notimplemented = " not-implemented "
local unknowncommand = " unknown-command "
2013-06-27 15:40:29 +00:00
local unknownstream = " (Unknown Stream) "
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local oldfilepath
local oldinputstate
local newfilepath
local newinputstate
2014-04-18 10:12:43 +00:00
local oldtitle = 0
local newtitle = 0
2013-01-13 22:51:15 +00:00
2013-10-04 21:20:32 +00:00
local running = true
2013-01-24 23:24:47 +00:00
-- Start hosting Syncplay interface.
port = tonumber ( config [ " port " ] )
if ( port == nil or port < 1 ) then port = 4123 end
2013-10-07 20:45:56 +00:00
function quit_vlc ( )
running = false
vlc.misc . quit ( )
end
2013-01-13 22:51:15 +00:00
function detectchanges ( )
2013-01-24 23:24:47 +00:00
-- Detects changes in VLC to report to Syncplay.
2014-01-29 17:49:19 +00:00
-- [Used by the poll / "." command]
2013-01-13 22:51:15 +00:00
local notificationbuffer = " "
if vlc.object . input ( ) then
newinputstate = " input "
newfilepath = get_filepath ( )
2014-06-02 19:27:53 +00:00
2013-06-27 15:40:29 +00:00
if newfilepath ~= oldfilepath and get_filepath ( ) ~= unknownstream then
2013-01-13 22:51:15 +00:00
oldfilepath = newfilepath
2013-01-17 20:43:44 +00:00
notificationbuffer = notificationbuffer .. " filepath-change " .. notificationmarker .. msgterminator
2013-01-13 22:51:15 +00:00
end
2014-05-20 19:20:37 +00:00
local titleerror
newtitle , titleerror = get_var ( " title " , 0 )
if newtitle ~= oldtitle and get_var ( " time " , 0 ) > 1 then
2014-04-18 10:12:43 +00:00
vlc.misc . mwait ( vlc.misc . mdate ( ) + durationdelay ) -- Don't give new title with old time
end
oldtitle = newtitle
2013-01-13 22:51:15 +00:00
notificationbuffer = notificationbuffer .. " playstate " .. msgseperator .. tostring ( get_play_state ( ) ) .. msgterminator
2014-06-02 19:27:53 +00:00
notificationbuffer = notificationbuffer .. " position " .. msgseperator .. tostring ( get_time ( ) ) .. msgterminator
2013-01-13 22:51:15 +00:00
else
notificationbuffer = notificationbuffer .. " playstate " .. msgseperator .. noinput .. msgterminator
notificationbuffer = notificationbuffer .. " position " .. msgseperator .. noinput .. msgterminator
newinputstate = noinput
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if newinputstate ~= oldinputstate then
oldinputstate = newinputstate
2013-01-17 20:43:44 +00:00
notificationbuffer = notificationbuffer .. " inputstate-change " .. msgseperator .. tostring ( newinputstate ) .. msgterminator
2013-01-13 22:51:15 +00:00
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return notificationbuffer
end
2013-01-11 23:11:33 +00:00
function get_args ( argument , argcount )
2013-01-24 23:24:47 +00:00
-- Converts comma-space-seperated values into array of a given size, with last item absorbing all remaining data if needed.
2013-01-27 19:56:53 +00:00
-- [Used by the display-osd command]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local argarray = { }
local index
local i
local argbuffer
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
argbuffer = argument
for i = 1 , argcount , 1 do
if i == argcount then
if argbuffer == nil then
argarray [ i ] = " "
else
argarray [ i ] = argbuffer
end
else
if string.find ( argbuffer , argseperator ) then
index = string.find ( argbuffer , argseperator )
argarray [ i ] = string.sub ( argbuffer , 0 , index - 1 )
argbuffer = string.sub ( argbuffer , index + string.len ( argseperator ) )
else
argarray [ i ] = " "
end
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return argarray
2014-06-02 19:27:53 +00:00
2013-01-11 23:11:33 +00:00
end
2014-05-20 19:20:37 +00:00
function get_var ( vartoget , fallbackvar )
2013-01-24 23:24:47 +00:00
-- [Used by the poll / '.' command to get time]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local response
local errormsg
local input = vlc.object . input ( )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if input then
response = vlc.var . get ( input , tostring ( vartoget ) )
else
2014-05-20 19:20:37 +00:00
response = fallbackvar
2013-01-13 22:51:15 +00:00
errormsg = noinput
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return response , errormsg
2013-01-11 23:11:33 +00:00
end
2013-01-24 23:24:47 +00:00
2013-01-11 23:11:33 +00:00
function set_var ( vartoset , varvalue )
2013-01-24 23:24:47 +00:00
-- [Used by the set-time and set-rate commands]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local errormsg
local input = vlc.object . input ( )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if input then
2014-03-08 16:31:42 +00:00
vlc.var . set ( input , tostring ( vartoset ) , varvalue )
2013-01-13 22:51:15 +00:00
else
errormsg = noinput
end
return errormsg
2013-01-11 23:11:33 +00:00
end
2014-03-08 16:31:42 +00:00
function get_time ( )
2014-05-20 19:20:37 +00:00
local realtime , errormsg , longtime , title , titletime
realtime , errormsg = get_var ( " time " , 0 ) -- Seconds
2014-03-08 16:31:42 +00:00
if errormsg ~= nil and errormsg ~= " " then
return errormsg
end
2014-05-20 19:20:37 +00:00
title = get_var ( " title " , 0 )
2014-03-08 16:31:42 +00:00
if errormsg ~= nil and errormsg ~= " " then
return realtime
end
2014-05-20 19:20:37 +00:00
titletime = title * titlemultiplier -- weeks
2014-03-08 16:31:42 +00:00
longtime = titletime + realtime
return longtime
end
function set_time ( timetoset )
2014-04-18 22:51:08 +00:00
local input = vlc.object . input ( )
if input then
local response , errormsg , realtime , titletrack
realtime = timetoset % titlemultiplier
2014-05-20 19:20:37 +00:00
oldtitle = tonumber ( get_var ( " title " , 0 ) )
2014-04-18 22:51:08 +00:00
newtitle = ( timetoset - realtime ) / titlemultiplier
if oldtitle ~= newtitle and newtitle > - 1 then
set_var ( " title " , tonumber ( newtitle ) )
end
errormsg = set_var ( " time " , tonumber ( realtime ) )
return errormsg
else
return noinput
2014-04-19 12:00:49 +00:00
end
2014-03-08 16:31:42 +00:00
end
2013-01-11 23:11:33 +00:00
function get_play_state ( )
2013-01-24 23:24:47 +00:00
-- [Used by the get-playstate command]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local response
local errormsg
local input = vlc.object . input ( )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if input then
response = vlc.playlist . status ( )
else
errormsg = noinput
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return response , errormsg
2014-06-02 19:27:53 +00:00
2013-01-11 23:11:33 +00:00
end
function get_filepath ( )
2013-01-24 23:24:47 +00:00
-- [Used by get-filepath command]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local response
local errormsg
local item
local input = vlc.object . input ( )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if input then
local item = vlc.input . item ( )
if item then
2013-10-07 20:49:41 +00:00
if string.find ( item : uri ( ) , " file:// " ) then
2013-06-24 19:02:42 +00:00
response = vlc.strings . decode_uri ( item : uri ( ) )
2014-03-08 16:31:42 +00:00
elseif string.find ( item : uri ( ) , " dvd:// " ) or string.find ( item : uri ( ) , " simpledvd:// " ) then
response = " :::DVD::: "
2013-10-07 20:49:41 +00:00
else
local metas = item : metas ( )
if metas and metas [ " title " ] and string.len ( metas [ " title " ] ) > 0 then
response = " :::(Stream: " .. metas [ " title " ] .. " ) "
else
response = unknownstream
end
end
2013-01-13 22:51:15 +00:00
else
errormsg = noinput
end
else
errormsg = noinput
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return response , errormsg
2013-01-11 23:11:33 +00:00
end
2013-01-13 22:51:15 +00:00
function get_filename ( )
2013-01-24 23:24:47 +00:00
-- [Used by get-filename command]
2014-06-02 19:27:53 +00:00
2013-01-17 20:43:44 +00:00
local response
local index
local filename
filename = errormerge ( get_filepath ( ) )
2014-03-08 16:31:42 +00:00
if filename == unknownstream then
return unknownstream
end
if filename == " " then
local input = vlc.object . input ( )
if input then
local item = vlc.input . item ( )
if item then
if item.name then
response = " :::( " .. item.title .. " ) "
return response
end
end
end
end
2014-06-02 19:27:53 +00:00
2013-01-17 20:43:44 +00:00
if ( filename ~= nil ) and ( filename ~= " " ) and ( filename ~= noinput ) then
2013-01-25 21:32:28 +00:00
index = string.len ( tostring ( string.match ( filename , " .*/ " ) ) )
2014-03-08 16:31:42 +00:00
if string.sub ( filename , 1 , 3 ) == " ::: " then
return filename
elseif index then
2013-01-17 20:43:44 +00:00
response = string.sub ( tostring ( filename ) , index + 1 )
end
else
response = noinput
end
2014-06-02 19:27:53 +00:00
2013-01-17 20:43:44 +00:00
return response
end
function get_duration ( )
2013-01-24 23:24:47 +00:00
-- [Used by get-duration command]
2013-01-13 22:51:15 +00:00
local response
local errormsg
2013-01-17 20:43:44 +00:00
local item
2013-01-13 22:51:15 +00:00
local input = vlc.object . input ( )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if input then
local item = vlc.input . item ( )
2013-06-27 15:40:29 +00:00
if ( item and item : duration ( ) ) then
2013-01-27 19:56:53 +00:00
-- Try to get duration, which might not be available straight away
2014-06-02 19:27:53 +00:00
local i = 0
2013-01-27 19:56:53 +00:00
repeat
vlc.misc . mwait ( vlc.misc . mdate ( ) + durationdelay )
2013-06-27 15:40:29 +00:00
response = item : duration ( )
2013-01-27 19:56:53 +00:00
i = i + 1
until response > 0 or i > 5
2013-01-13 22:51:15 +00:00
else
errormsg = noinput
end
else
errormsg = noinput
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return response , errormsg
2013-01-11 23:11:33 +00:00
end
2014-06-02 19:27:53 +00:00
2013-01-11 23:11:33 +00:00
2013-01-13 22:51:15 +00:00
function display_osd ( argument )
2013-01-24 23:24:47 +00:00
-- [Used by display-osd command]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local errormsg
local osdarray
local input = vlc.object . input ( )
if input then
osdarray = get_args ( argument , 3 )
2014-02-17 21:14:53 +00:00
--position, duration, message -> message, , position, duration (converted from seconds to microseconds)
2013-01-13 22:51:15 +00:00
local osdduration = tonumber ( osdarray [ 2 ] ) * 1000 * 1000
vlc.osd . message ( osdarray [ 3 ] , channel1 , osdarray [ 1 ] , osdduration )
else
errormsg = noinput
end
return errormsg
2013-01-11 23:11:33 +00:00
end
2013-06-11 13:01:25 +00:00
function load_file ( filepath )
-- [Used by load-file command]
2014-06-02 19:27:53 +00:00
2013-06-11 13:01:25 +00:00
local uri = vlc.strings . make_uri ( filepath )
vlc.playlist . add ( { { path = uri } } )
2013-06-12 17:14:08 +00:00
return " load-file-attempted \n "
2013-06-11 13:01:25 +00:00
end
2013-07-04 15:56:22 +00:00
2013-01-13 22:51:15 +00:00
function do_command ( command , argument )
2013-01-24 23:24:47 +00:00
-- Processes all commands sent by Syncplay (see protocol, above).
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if command == " . " then
do return detectchanges ( ) end
end
local command = tostring ( command )
local argument = tostring ( argument )
local errormsg = " "
2014-06-02 19:27:53 +00:00
local response = " "
2013-01-13 22:51:15 +00:00
if command == " get-interface-version " then response = " interface-version " .. msgseperator .. connectorversion .. msgterminator
2013-01-17 20:43:44 +00:00
elseif command == " get-duration " then response = " duration " .. msgseperator .. errormerge ( get_duration ( ) ) .. msgterminator
elseif command == " get-filepath " then response = " filepath " .. msgseperator .. errormerge ( get_filepath ( ) ) .. msgterminator
elseif command == " get-filename " then response = " filename " .. msgseperator .. errormerge ( get_filename ( ) ) .. msgterminator
2014-05-20 19:20:37 +00:00
elseif command == " get-title " then response = " title " .. msgseperator .. errormerge ( get_var ( " title " , 0 ) ) .. msgterminator
2014-03-08 16:31:42 +00:00
elseif command == " set-position " then errormsg = set_time ( tonumber ( argument ) )
elseif command == " seek-within-title " then errormsg = set_var ( " time " , tonumber ( argument ) )
2013-01-13 22:51:15 +00:00
elseif command == " set-playstate " then errormsg = set_playstate ( argument )
elseif command == " set-rate " then errormsg = set_var ( " rate " , tonumber ( argument ) )
2014-03-08 16:31:42 +00:00
elseif command == " set-title " then errormsg = set_var ( " title " , tonumber ( argument ) )
2014-06-02 19:27:53 +00:00
elseif command == " display-osd " then errormsg = display_osd ( argument )
2013-06-11 13:01:25 +00:00
elseif command == " load-file " then response = load_file ( argument )
2013-10-04 21:20:32 +00:00
elseif command == " close-vlc " then quit_vlc ( )
2013-01-13 22:51:15 +00:00
else errormsg = unknowncommand
end
2014-06-02 19:27:53 +00:00
2013-01-17 20:43:44 +00:00
if ( errormsg ~= nil ) and ( errormsg ~= " " ) then
2013-01-13 22:51:15 +00:00
response = command .. errormarker .. msgseperator .. tostring ( errormsg ) .. msgterminator
end
2013-01-11 23:11:33 +00:00
2013-01-13 22:51:15 +00:00
return response
2014-06-02 19:27:53 +00:00
2013-01-11 23:11:33 +00:00
end
2013-01-17 20:43:44 +00:00
function errormerge ( argument , errormsg )
2013-01-27 19:56:53 +00:00
-- Used to integrate 'no-input' error messages into command responses.
2014-06-02 19:27:53 +00:00
2013-01-17 20:43:44 +00:00
if ( errormsg ~= nil ) and ( errormsg ~= " " ) then
do return errormsg end
end
2014-06-02 19:27:53 +00:00
2013-01-17 20:43:44 +00:00
return argument
end
2013-01-13 22:51:15 +00:00
function set_playstate ( argument )
2013-01-24 23:24:47 +00:00
-- [Used by the set-playstate command]
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local errormsg
local input = vlc.object . input ( )
local playstate
playstate , errormsg = get_play_state ( )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if playstate ~= " playing " then playstate = " paused " end
if ( ( errormsg ~= noinput ) and ( playstate ~= argument ) ) then
vlc.playlist . pause ( )
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
return errormsg
2013-01-11 23:11:33 +00:00
end
2014-06-29 17:20:24 +00:00
if string.sub ( vlc.misc . version ( ) , 1 , 2 ) == " 1. " then
vlc.msg . err ( " This version of VLC is not known to support version " .. connectorversion .. " of the Syncplay interface module on Windows. Please use VLC 2+. " )
2013-11-10 01:45:44 +00:00
quit_vlc ( )
else
l = vlc.net . listen_tcp ( host , port )
2013-11-17 11:30:56 +00:00
vlc.msg . info ( " Hosting Syncplay interface on port: " .. port )
2013-11-10 01:45:44 +00:00
end
2013-01-24 23:24:47 +00:00
-- main loop, which alternates between writing and reading
2014-06-02 19:27:53 +00:00
2014-02-17 21:14:53 +00:00
while running == true do
2013-11-10 01:45:44 +00:00
--accept new connections and select active clients
2014-06-02 19:27:53 +00:00
local quitcheckcounter = 0
local fd = l : accept ( )
local buffer , inputbuffer , responsebuffer = " "
2014-02-17 21:14:53 +00:00
while fd >= 0 and running == true do
2013-01-11 23:11:33 +00:00
2013-11-10 01:45:44 +00:00
-- handle read mode
2014-06-02 19:27:53 +00:00
2013-11-10 01:45:44 +00:00
local str = vlc.net . recv ( fd , 1000 )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local responsebuffer
2013-11-10 01:45:44 +00:00
if str == nil then str = " " end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
local safestr = string.gsub ( tostring ( str ) , " \r " , " " )
2013-11-10 01:45:44 +00:00
if inputbuffer == nil then inputbuffer = " " end
2014-06-02 19:27:53 +00:00
2013-11-10 01:45:44 +00:00
inputbuffer = inputbuffer .. safestr
2014-02-17 21:14:53 +00:00
while string.find ( inputbuffer , msgterminator ) and running == true do
2013-11-10 01:45:44 +00:00
local index = string.find ( inputbuffer , msgterminator )
local request = string.sub ( inputbuffer , 0 , index - 1 )
2013-01-13 22:51:15 +00:00
local command
local argument
2013-11-10 01:45:44 +00:00
inputbuffer = string.sub ( inputbuffer , index + string.len ( msgterminator ) )
2013-01-13 22:51:15 +00:00
if ( string.find ( request , msgseperator ) ) then
index = string.find ( request , msgseperator )
command = string.sub ( request , 0 , index - 1 )
argument = string.sub ( request , index + string.len ( msgseperator ) )
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
else
command = request
end
2014-06-02 19:27:53 +00:00
2013-01-13 22:51:15 +00:00
if ( responsebuffer ) then
responsebuffer = responsebuffer .. do_command ( command , argument )
else
responsebuffer = do_command ( command , argument )
end
end
2014-06-02 19:27:53 +00:00
2014-02-17 21:14:53 +00:00
if ( running == false ) then
net.close ( fd )
end
2014-06-02 19:27:53 +00:00
2013-11-10 01:45:44 +00:00
-- handle write mode
2014-06-02 19:27:53 +00:00
2014-02-17 21:32:12 +00:00
if ( responsebuffer and running == true ) then
2013-11-10 01:45:44 +00:00
vlc.net . send ( fd , responsebuffer )
responsebuffer = " "
2013-01-13 22:51:15 +00:00
end
2014-05-19 13:49:52 +00:00
vlc.misc . mwait ( vlc.misc . mdate ( ) + loopsleepduration ) -- Don't waste processor time
2013-11-10 01:45:44 +00:00
2014-06-02 19:27:53 +00:00
-- check if VLC has been closed
quitcheckcounter = quitcheckcounter + 1
if quitcheckcounter > quitcheckfrequency then
if vlc.volume . get ( ) == - 256 then
running = false
end
quitcheckcounter = 0
end
2013-01-11 23:11:33 +00:00
end
2013-11-10 01:45:44 +00:00
2013-01-11 23:11:33 +00:00
end