Only copy syncplay.lua when needed

This commit is contained in:
Etoh 2019-02-09 17:58:26 +00:00
parent 89f8a28f3f
commit d8ebb50da7
3 changed files with 39 additions and 35 deletions

View File

@ -5,7 +5,7 @@
Principal author: Etoh Principal author: Etoh
Other contributors: DerGenaue, jb, Pilotat Other contributors: DerGenaue, jb, Pilotat
Project: https://syncplay.pl/ Project: https://syncplay.pl/
Version: 0.3.4 Version: 0.3.5
Note: Note:
* This interface module is intended to be used in conjunction with Syncplay. * This interface module is intended to be used in conjunction with Syncplay.
@ -78,7 +78,7 @@ Syncplay should install this automatically to your user folder.
--]==========================================================================] --]==========================================================================]
local connectorversion = "0.3.4" local connectorversion = "0.3.5"
local vlcversion = vlc.misc.version() local vlcversion = vlc.misc.version()
local vlcmajorversion = tonumber(vlcversion:sub(1,1)) -- get the major version of VLC local vlcmajorversion = tonumber(vlcversion:sub(1,1)) -- get the major version of VLC
local durationdelay = 500000 -- Pause for get_duration command etc for increased reliability (uses microseconds) local durationdelay = 500000 -- Pause for get_duration command etc for increased reliability (uses microseconds)

View File

@ -102,7 +102,7 @@ COMMANDS_TOGGLE = ['t', 'toggle']
MPC_MIN_VER = "1.6.4" MPC_MIN_VER = "1.6.4"
MPC_BE_MIN_VER = "1.5.2.3123" MPC_BE_MIN_VER = "1.5.2.3123"
VLC_MIN_VERSION = "2.2.1" VLC_MIN_VERSION = "2.2.1"
VLC_INTERFACE_MIN_VERSION = "0.3.4" VLC_INTERFACE_VERSION = "0.3.5"
VLC_LATENCY_ERROR_THRESHOLD = 2.0 VLC_LATENCY_ERROR_THRESHOLD = 2.0
MPV_UNRESPONSIVE_THRESHOLD = 60.0 MPV_UNRESPONSIVE_THRESHOLD = 60.0
CONTROLLED_ROOMS_MIN_VERSION = "1.3.0" CONTROLLED_ROOMS_MIN_VERSION = "1.3.0"

View File

@ -341,22 +341,6 @@ class VlcPlayer(BasePlayer):
call.append(filePath) call.append(filePath)
else: else:
call.append(self.__playerController.getMRL(filePath)) call.append(self.__playerController.getMRL(filePath))
def _usevlcintf(vlcIntfPath, vlcIntfUserPath):
vlcSyncplayInterfacePath = vlcIntfPath + "syncplay.lua"
if not os.path.isfile(vlcSyncplayInterfacePath):
vlcSyncplayInterfacePath = vlcIntfUserPath + "syncplay.lua"
if os.path.isfile(vlcSyncplayInterfacePath):
with open(vlcSyncplayInterfacePath, 'rU') as interfacefile:
for line in interfacefile:
if "local connectorversion" in line:
interface_version = line[26:31]
if utils.meetsMinVersion(interface_version, constants.VLC_INTERFACE_MIN_VERSION):
return True
else:
self.oldIntfVersion = line[26:31]
return False
return False
if isLinux(): if isLinux():
playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/" playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/"
playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/")
@ -373,23 +357,43 @@ class VlcPlayer(BasePlayer):
playerController.vlcIntfPath = os.path.dirname(playerPath).replace("\\", "/") + "/lua/intf/" playerController.vlcIntfPath = os.path.dirname(playerPath).replace("\\", "/") + "/lua/intf/"
playerController.vlcIntfUserPath = os.path.join(os.getenv('APPDATA', '.'), "VLC\\lua\\intf\\") playerController.vlcIntfUserPath = os.path.join(os.getenv('APPDATA', '.'), "VLC\\lua\\intf\\")
playerController.vlcModulePath = playerController.vlcIntfPath + "modules/?.luac" playerController.vlcModulePath = playerController.vlcIntfPath + "modules/?.luac"
try: def _intfNeedsUpdating(vlcSyncplayInterfacePath):
copyForm = utils.findResourcePath("syncplay.lua") self.__playerController._client.ui.showDebugMessage("Checking if '{}' exists and if it is the expected version".format(vlcSyncplayInterfacePath))
copyTo = os.path.join(playerController.vlcIntfUserPath, "syncplay.lua") if not os.path.isfile(vlcSyncplayInterfacePath):
self.__playerController._client.ui.showDebugMessage("Copying VLC Lua Interface from '{}' to '{}'".format(copyForm, copyTo)) self.__playerController._client.ui.showDebugMessage("syncplay.lua not found, so file needs copying")
import shutil return True
shutil.copyfile(copyForm, copyTo) if os.path.isfile(vlcSyncplayInterfacePath):
except Exception as e: with open(vlcSyncplayInterfacePath, 'rU') as interfacefile:
playerController._client.ui.showErrorMessage(e) for line in interfacefile:
if "local connectorversion" in line:
interface_version = line[26:31]
if interface_version == constants.VLC_INTERFACE_VERSION:
self.__playerController._client.ui.showDebugMessage("syncplay.lua exists and is expected version, so no file needs copying")
return False
else:
self.oldIntfVersion = line[26:31]
self.__playerController._client.ui.showDebugMessage("syncplay.lua is {} but expected version is {} so file needs to be copied".format(interface_version, constants.VLC_INTERFACE_VERSION))
return True
self.__playerController._client.ui.showDebugMessage("Up-to-dateness checks failed, so copy the file.")
return True
if _intfNeedsUpdating(os.path.join(playerController.vlcIntfUserPath, "syncplay.lua")):
try:
copyForm = utils.findResourcePath("syncplay.lua")
copyTo = os.path.join(playerController.vlcIntfUserPath, "syncplay.lua")
self.__playerController._client.ui.showDebugMessage("Copying VLC Lua Interface from '{}' to '{}'".format(copyForm, copyTo))
import shutil
shutil.copyfile(copyForm, copyTo)
except Exception as e:
playerController._client.ui.showErrorMessage(e)
return
if isLinux():
playerController.vlcDataPath = "/usr/lib/syncplay/resources"
else: else:
if isLinux(): playerController.vlcDataPath = utils.findWorkingDir() + "\\resources"
playerController.vlcDataPath = "/usr/lib/syncplay/resources" playerController.SLAVE_ARGS.append('--data-path={}'.format(playerController.vlcDataPath))
else: playerController.SLAVE_ARGS.append(
playerController.vlcDataPath = utils.findWorkingDir() + "\\resources" '--lua-config=syncplay={{modulepath=\"{}\",port=\"{}\"}}'.format(
playerController.SLAVE_ARGS.append('--data-path={}'.format(playerController.vlcDataPath)) playerController.vlcModulePath, str(playerController.vlcport)))
playerController.SLAVE_ARGS.append(
'--lua-config=syncplay={{modulepath=\"{}\",port=\"{}\"}}'.format(
playerController.vlcModulePath, str(playerController.vlcport)))
call.extend(playerController.SLAVE_ARGS) call.extend(playerController.SLAVE_ARGS)
if args: if args: