dots

git clone git://mattcarlson.org/repos/dots.git
Log | Files | Refs

sockets.lua (1067B)


      1 -- mpvSockets, one socket per instance, removes socket on exit
      2 
      3 local utils = require 'mp.utils'
      4 
      5 local function get_temp_path()
      6     local directory_seperator = package.config:match("([^\n]*)\n?")
      7     local example_temp_file_path = os.tmpname()
      8 
      9     -- remove generated temp file
     10     pcall(os.remove, example_temp_file_path)
     11 
     12     local seperator_idx = example_temp_file_path:reverse():find(directory_seperator)
     13     local temp_path_length = #example_temp_file_path - seperator_idx
     14 
     15     return example_temp_file_path:sub(1, temp_path_length)
     16 end
     17 
     18 tempDir = get_temp_path()
     19 
     20 function join_paths(...)
     21     local arg={...}
     22     path = ""
     23     for i,v in ipairs(arg) do
     24         path = utils.join_path(path, tostring(v))
     25     end
     26     return path;
     27 end
     28 
     29 ppid = utils.getpid()
     30 os.execute("mkdir " .. join_paths(tempDir, "mpv-sockets") .. " 2>/dev/null")
     31 mp.set_property("options/input-ipc-server", join_paths(tempDir, "mpv-sockets", ppid))
     32 
     33 function shutdown_handler()
     34         os.remove(join_paths(tempDir, "mpv-sockets", ppid))
     35 end
     36 mp.register_event("shutdown", shutdown_handler)