From d8ebb50da7c5e78bb28e6b5b3c7ab914c9d1911f Mon Sep 17 00:00:00 2001 From: Etoh Date: Sat, 9 Feb 2019 17:58:26 +0000 Subject: [PATCH] Only copy syncplay.lua when needed --- resources/lua/intf/syncplay.lua | 4 +- syncplay/constants.py | 2 +- syncplay/players/vlc.py | 68 +++++++++++++++++---------------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/resources/lua/intf/syncplay.lua b/resources/lua/intf/syncplay.lua index becd9b6..54ce65f 100644 --- a/resources/lua/intf/syncplay.lua +++ b/resources/lua/intf/syncplay.lua @@ -5,7 +5,7 @@ Principal author: Etoh Other contributors: DerGenaue, jb, Pilotat Project: https://syncplay.pl/ - Version: 0.3.4 + Version: 0.3.5 Note: * 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 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) diff --git a/syncplay/constants.py b/syncplay/constants.py index 76fdd17..babe85d 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -102,7 +102,7 @@ COMMANDS_TOGGLE = ['t', 'toggle'] MPC_MIN_VER = "1.6.4" MPC_BE_MIN_VER = "1.5.2.3123" 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 MPV_UNRESPONSIVE_THRESHOLD = 60.0 CONTROLLED_ROOMS_MIN_VERSION = "1.3.0" diff --git a/syncplay/players/vlc.py b/syncplay/players/vlc.py index 09eea51..3984cea 100755 --- a/syncplay/players/vlc.py +++ b/syncplay/players/vlc.py @@ -341,22 +341,6 @@ class VlcPlayer(BasePlayer): call.append(filePath) else: 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(): playerController.vlcIntfPath = "/usr/lib/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.vlcIntfUserPath = os.path.join(os.getenv('APPDATA', '.'), "VLC\\lua\\intf\\") playerController.vlcModulePath = playerController.vlcIntfPath + "modules/?.luac" - 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) + def _intfNeedsUpdating(vlcSyncplayInterfacePath): + self.__playerController._client.ui.showDebugMessage("Checking if '{}' exists and if it is the expected version".format(vlcSyncplayInterfacePath)) + if not os.path.isfile(vlcSyncplayInterfacePath): + self.__playerController._client.ui.showDebugMessage("syncplay.lua not found, so file needs copying") + return True + 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 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: - if isLinux(): - playerController.vlcDataPath = "/usr/lib/syncplay/resources" - else: - playerController.vlcDataPath = utils.findWorkingDir() + "\\resources" - playerController.SLAVE_ARGS.append('--data-path={}'.format(playerController.vlcDataPath)) - playerController.SLAVE_ARGS.append( - '--lua-config=syncplay={{modulepath=\"{}\",port=\"{}\"}}'.format( - playerController.vlcModulePath, str(playerController.vlcport))) + playerController.vlcDataPath = utils.findWorkingDir() + "\\resources" + playerController.SLAVE_ARGS.append('--data-path={}'.format(playerController.vlcDataPath)) + playerController.SLAVE_ARGS.append( + '--lua-config=syncplay={{modulepath=\"{}\",port=\"{}\"}}'.format( + playerController.vlcModulePath, str(playerController.vlcport))) call.extend(playerController.SLAVE_ARGS) if args: