diff --git a/resources/syncplay.lua b/resources/syncplay.lua index 302bb05..f82364c 100644 --- a/resources/syncplay.lua +++ b/resources/syncplay.lua @@ -76,8 +76,7 @@ function detectchanges() if newfilepath ~= oldfilepath then oldfilepath = newfilepath - notificationbuffer = notificationbuffer .. "filepath-change"..msgseperator..tostring(newfilepath)..msgterminator - notificationbuffer = notificationbuffer .. "file-length-change"..msgseperator..get_var("length")..msgterminator + notificationbuffer = notificationbuffer .. "filepath-change"..notificationmarker..msgterminator end notificationbuffer = notificationbuffer .. "playstate"..msgseperator..tostring(get_play_state())..msgterminator @@ -90,7 +89,7 @@ function detectchanges() if newinputstate ~= oldinputstate then oldinputstate = newinputstate - notificationbuffer = "inputstate-change"..msgseperator..tostring(newinputstate)..msgterminator..notificationbuffer + notificationbuffer = notificationbuffer.."inputstate-change"..msgseperator..tostring(newinputstate)..msgterminator end return notificationbuffer @@ -166,7 +165,7 @@ function set_var(vartoset, varvalue) return errormsg end -h:listen( "localhost:"..port) + h:listen( "localhost:"..port) -- h:listen( "*console" ) function get_play_state() @@ -194,6 +193,14 @@ function get_filepath () local item = vlc.input.item() if item then response = vlc.strings.decode_uri(item:uri()) + + if (string.sub(response, 1, 8) == "file:///") then + response = string.gsub(response, "file:///","") + response = string.gsub(response, "/","\\") + else + response = "" + errormsg = noinput + end else errormsg = noinput end @@ -205,14 +212,34 @@ function get_filepath () end function get_filename () + + local response + local index + local filename + filename = errormerge(get_filepath()) + + if(filename ~= nil) and (filename ~= "") and (filename ~= noinput) then + index = string.len(tostring(string.match(filename, ".*\\"))) + if index then + response = string.sub(tostring(filename), index+1) + end + else + response = noinput + end + + return response +end + +function get_duration () local response local errormsg + local item local input = vlc.object.input() if input then local item = vlc.input.item() if item then - response = item:name() + response = vlc.input.item():duration() else errormsg = noinput end @@ -222,6 +249,7 @@ function get_filename () return response, errormsg end + function display_osd ( argument ) local errormsg @@ -246,22 +274,21 @@ function do_command ( command, argument) local command = tostring(command) local argument = tostring(argument) local errormsg = "" - local response = "" - - local input = vlc.object.input() - - + local response = "" if command == "get-interface-version" then response = "interface-version"..msgseperator..connectorversion..msgterminator + 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 elseif command == "set-position" then errormsg = set_var("time", tonumber(argument)) elseif command == "set-playstate" then errormsg = set_playstate(argument) elseif command == "set-rate" then errormsg = set_var("rate", tonumber(argument)) elseif command == "display-osd" then errormsg = display_osd(argument) - elseif command == "close-vlc" then misc.quit() + elseif command == "close-vlc" then vlc.misc.quit() else errormsg = unknowncommand end - if (tostring(errormsg) ~= nil) and (errormsg ~= "") then + if (errormsg ~= nil) and (errormsg ~= "") then response = command..errormarker..msgseperator..tostring(errormsg)..msgterminator end @@ -269,6 +296,14 @@ function do_command ( command, argument) end +function errormerge(argument, errormsg) + if (errormsg ~= nil) and (errormsg ~= "") then + do return errormsg end + end + + return argument +end + function set_playstate(argument) local errormsg local input = vlc.object.input() @@ -302,9 +337,7 @@ while not vlc.misc.should_die() do local responsebuffer if not str then break end - local safestr = string.gsub(tostring(str), "\r", "") - if client.inputbuffer == nil then client.inputbuffer = "" end client.inputbuffer = client.inputbuffer .. safestr diff --git a/syncplay/constants.py b/syncplay/constants.py index b1cba2b..6025433 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -1,59 +1,60 @@ -#You might want to change these -DEFAULT_PORT = 8999 -OSD_DURATION = 3 -OSD_WARNING_MESSAGE_DURATION = 15 -MPC_OSD_POSITION = 2 #Right corner, 1 for left -MPLAYER_OSD_LEVEL = 1 -UI_TIME_FORMAT = "[%X] " -DEFAULT_CONFIG_NAME = ".syncplay" - -#Changing these might be ok -REWIND_THRESHOLD = 4 -SEEK_THRESHOLD = 1 -SLOWDOWN_RATE = 0.95 -SLOWDOWN_KICKIN_THRESHOLD = 1.5 -SLOWDOWN_RESET_THRESHOLD = 0.1 -DIFFFERENT_DURATION_THRESHOLD = 1 -PROTOCOL_TIMEOUT = 12.5 -RECONNECT_RETRIES = 10 -SERVER_STATE_INTERVAL = 1 -WARNING_OSD_MESSAGES_LOOP_INTERVAL = 1 - -#Usually there's no need to adjust these -COMMANDS_UNDO = ["u", "undo", "revert"] -COMMANDS_LIST = ["l", "list", "users"] -COMMANDS_PAUSE = ["p", "play", "pause"] -COMMANDS_ROOM = ["r", "room"] -COMMANDS_HELP = ['help', 'h', '?', '/?', '\?'] -MPC_MIN_VER = "1.6.4" -MPC_PATHS = [ - "C:\Program Files (x86)\MPC-HC\mpc-hc.exe", - "C:\Program Files\MPC-HC\mpc-hc.exe", - "C:\Program Files\MPC-HC\mpc-hc64.exe", - "C:\Program Files\Media Player Classic - Home Cinema\mpc-hc.exe", - "C:\Program Files\Media Player Classic - Home Cinema\mpc-hc64.exe", - "C:\Program Files (x86)\Media Player Classic - Home Cinema\mpc-hc.exe", - "C:\Program Files (x86)\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe", - "C:\Program Files\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe", - "C:\Program Files (x86)\Combined Community Codec Pack\MPC\mpc-hc.exe", - "C:\Program Files\MPC HomeCinema (x64)\mpc-hc64.exe", - ] -MPLAYER_PATHS = ["mplayer2"] -MPV_PATHS = ["mpv", "/opt/mpv/mpv"] -#Changing these is usually not something you're looking for -PLAYER_ASK_DELAY = 0.1 -PING_MOVING_AVERAGE_WEIGHT = 0.85 -MPC_OPEN_MAX_WAIT_TIME = 10 -MPC_LOCK_WAIT_TIME = 0.2 -MPC_RETRY_WAIT_TIME = 0.01 -MPC_MAX_RETRIES = 30 -MPC_PAUSE_TOGGLE_DELAY = 0.05 - -#These are not changes you're looking for -MPLAYER_SLAVE_ARGS = [ '-slave', '-msglevel', 'all=1:global=4'] -MPV_SLAVE_ARGS = [ '--slave-broken', '-msglevel', 'all=1:global=4'] -MPLAYER_ANSWER_REGEX = "^ANS_([a-zA-Z_]+)=(.+)$" -UI_COMMAND_REGEX = r"^(?P[^\ ]+)(?:\ (?P.+))?" -UI_OFFSET_REGEX = r"^(?:o|offset)\ ?(?P[/+-])?(?P