def __init__(self, playerController, playerPath, filePath, args): self.sendQueue = [] self.readyToSend = True self.lastSendTime = None self.lastNotReadyTime = None self.__playerController = playerController if not self.__playerController._client._config["chatOutputEnabled"]: self.__playerController.alertOSDSupported = False self.__playerController.chatOSDSupported = False if self.__playerController.getPlayerPathErrors(playerPath, filePath): raise ValueError() if filePath and '://' not in filePath: if not os.path.isfile(filePath) and 'PWD' in os.environ: filePath = os.environ['PWD'] + os.path.sep + filePath filePath = os.path.realpath(filePath) call = [playerPath] if filePath: if isWindows() and not utils.isASCII(filePath): self.__playerController.delayedFilePath = filePath filePath = None else: call.extend([filePath]) call.extend(playerController.getStartupArgs(playerPath, args)) # At least mpv may output escape sequences which result in syncplay # trying to parse something like # "\x1b[?1l\x1b>ANS_filename=blah.mkv". Work around this by # unsetting TERM. env = os.environ.copy() if 'TERM' in env: del env['TERM'] # On macOS, youtube-dl requires system python to run. Set the environment # to allow that version of python to be executed in the mpv subprocess. if isMacOS(): try: pythonLibs = subprocess.check_output(['/usr/bin/python', '-E', '-c', 'import sys; print(sys.path)'], text=True, env=dict()) pythonLibs = ast.literal_eval(pythonLibs) pythonPath = ':'.join(pythonLibs[1:]) except: pythonPath = None if pythonPath is not None: env['PATH'] = '/usr/bin:/usr/local/bin' env['PYTHONPATH'] = pythonPath if filePath: self.__process = subprocess.Popen( call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.__getCwd(filePath, env), env=env, bufsize=0) else: self.__process = subprocess.Popen( call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, bufsize=0) threading.Thread.__init__(self, name="MPlayer Listener")
def getMRL(self, fileURL): if utils.isURL(fileURL): fileURL = urllib.parse.quote(fileURL, safe="%/:=&?~#+!$,;'@()*") return fileURL fileURL = fileURL.replace('\\', '/') fileURL = fileURL.encode('utf8') fileURL = urllib.parse.quote_plus(fileURL) if isWindows(): fileURL = "file:///" + fileURL else: fileURL = "file://" + fileURL fileURL = fileURL.replace("+", "%20") return fileURL
def getMRL(self, fileURL): if utils.isURL(fileURL): fileURL = urllib.parse.quote(fileURL, safe="%/:=&?~#+!$,;'@()*") return fileURL fileURL = fileURL.replace('\\', '/') fileURL = fileURL.encode('utf8') fileURL = urllib.parse.quote_plus(fileURL) if isWindows(): fileURL = "file:///" + fileURL else: fileURL = "file://" + fileURL fileURL = fileURL.replace("+", "%20") return fileURL
def __init__(self, playerController, playerPath, filePath, args): self.sendQueue = [] self.readyToSend = True self.lastSendTime = None self.lastNotReadyTime = None self.__playerController = playerController if not self.__playerController._client._config["chatOutputEnabled"]: self.__playerController.alertOSDSupported = False self.__playerController.chatOSDSupported = False if self.__playerController.getPlayerPathErrors( playerPath, filePath): raise ValueError() if filePath and '://' not in filePath: if not os.path.isfile(filePath) and 'PWD' in os.environ: filePath = os.environ['PWD'] + os.path.sep + filePath filePath = os.path.realpath(filePath) call = [playerPath] if filePath: if isWindows() and not utils.isASCII(filePath): self.__playerController.delayedFilePath = filePath filePath = None else: call.extend([filePath]) call.extend(playerController.getStartupArgs(playerPath, args)) # At least mpv may output escape sequences which result in syncplay # trying to parse something like # "\x1b[?1l\x1b>ANS_filename=blah.mkv". Work around this by # unsetting TERM. env = os.environ.copy() if 'TERM' in env: del env['TERM'] if filePath: self.__process = subprocess.Popen(call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.__getCwd( filePath, env), env=env, bufsize=0) else: self.__process = subprocess.Popen(call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, bufsize=0) threading.Thread.__init__(self, name="MPlayer Listener")
def _shouldListenForSTDOUT(self): return not isWindows()
def __init__(self, playerController, playerPath, filePath, args, vlcReady, vlcClosed): self.__playerController = playerController self.requestedVLCVersion = False self.vlcHasResponded = False self.oldIntfVersion = None self.timeVLCLaunched = None call = [playerPath] if filePath: if utils.isASCII(filePath): 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 playerController._client.ui.showErrorMessage( getMessage("vlc-interface-not-installed")) return False if isLinux(): playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") elif isMacOS(): playerController.vlcIntfPath = "/Applications/VLC.app/Contents/MacOS/share/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/") elif isBSD(): # *BSD ports/pkgs install to /usr/local by default. # This should also work for all the other BSDs, such as OpenBSD or DragonFly. playerController.vlcIntfPath = "/usr/local/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") else: 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" if _usevlcintf(playerController.vlcIntfPath, playerController.vlcIntfUserPath): playerController.SLAVE_ARGS.append( '--lua-config=syncplay={{port=\"{}\"}}'.format( str(playerController.vlcport))) 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))) call.extend(playerController.SLAVE_ARGS) if args: call.extend(args) self._vlcready = vlcReady self._vlcclosed = vlcClosed self._vlcVersion = None if self.oldIntfVersion: self.__playerController.drop( getMessage("vlc-interface-version-mismatch").format( self.oldIntfVersion, constants.VLC_INTERFACE_MIN_VERSION)) else: if isWindows() and getattr(sys, 'frozen', '') and getattr( sys, '_MEIPASS', '' ) is not None: # Needed for pyinstaller --onefile bundle self.__process = subprocess.Popen(call, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, creationflags=0x08000000) else: self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE) self.timeVLCLaunched = time.time() if self._shouldListenForSTDOUT(): for line in iter(self.__process.stderr.readline, ''): line = line.decode('utf-8') self.vlcHasResponded = True self.timeVLCLaunched = None if "[syncplay]" in line: if "Listening on host" in line: break if "Hosting Syncplay" in line: break elif "Couldn't find lua interface" in line: playerController._client.ui.showErrorMessage( getMessage("vlc-failed-noscript").format( line), True) break elif "lua interface error" in line: playerController._client.ui.showErrorMessage( getMessage("media-player-error").format( line), True) break if not isMacOS(): self.__process.stderr = None else: vlcoutputthread = threading.Thread( target=self.handle_vlcoutput, args=()) vlcoutputthread.setDaemon(True) vlcoutputthread.start() threading.Thread.__init__(self, name="VLC Listener") asynchat.async_chat.__init__(self) self.set_terminator(b'\n') self._ibuffer = [] self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self._sendingData = threading.Lock()
def _shouldListenForSTDOUT(self): if isWindows(): return False # Due to VLC3 not using STDOUT/STDERR else: return True
def __init__(self, playerController, playerPath, filePath, args): self.sendQueue = [] self.readyToSend = True self.lastSendTime = None self.lastNotReadyTime = None self.__playerController = playerController if not self.__playerController._client._config["chatOutputEnabled"]: self.__playerController.alertOSDSupported = False self.__playerController.chatOSDSupported = False if self.__playerController.getPlayerPathErrors( playerPath, filePath): raise ValueError() if filePath and '://' not in filePath: if not os.path.isfile(filePath) and 'PWD' in os.environ: filePath = os.environ['PWD'] + os.path.sep + filePath filePath = os.path.realpath(filePath) call = [playerPath] if filePath: if isWindows() and not utils.isASCII(filePath): self.__playerController.delayedFilePath = filePath filePath = None else: call.extend([filePath]) call.extend(playerController.getStartupArgs(playerPath, args)) # At least mpv may output escape sequences which result in syncplay # trying to parse something like # "\x1b[?1l\x1b>ANS_filename=blah.mkv". Work around this by # unsetting TERM. env = os.environ.copy() if 'TERM' in env: del env['TERM'] # On macOS, youtube-dl requires system python to run. Set the environment # to allow that version of python to be executed in the mpv subprocess. if isMacOS(): try: pythonLibs = subprocess.check_output([ '/usr/bin/python', '-E', '-c', 'import sys; print(sys.path)' ], text=True, env=dict()) pythonLibs = ast.literal_eval(pythonLibs) pythonPath = ':'.join(pythonLibs[1:]) except: pythonPath = None if pythonPath is not None: env['PATH'] = '/usr/bin:/usr/local/bin' env['PYTHONPATH'] = pythonPath if filePath: self.__process = subprocess.Popen(call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.__getCwd( filePath, env), env=env, bufsize=0) else: self.__process = subprocess.Popen(call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, bufsize=0) threading.Thread.__init__(self, name="MPlayer Listener")
def _shouldListenForSTDOUT(self): if isWindows(): return False # Due to VLC3 not using STDOUT/STDERR else: return True
def __init__(self, playerController, playerPath, filePath, args, reactor): self.__playerController = playerController self.reactor = reactor self.vlcHasResponded = False self.oldIntfVersion = None self.timeVLCLaunched = None call = [playerPath] if filePath: if utils.isASCII(filePath): call.append(filePath) else: call.append(self.__playerController.getMRL(filePath)) if isLinux(): if 'snap' in playerPath: self.__playerController.vlcIntfPath = '/snap/vlc/current/usr/lib/vlc/lua/intf/' self.__playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), "snap/vlc/current/.local/share/vlc/lua/intf/") else: self.__playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/" self.__playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") elif isMacOS(): self.__playerController.vlcIntfPath = "/Applications/VLC.app/Contents/MacOS/share/lua/intf/" self.__playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/") elif isBSD(): # *BSD ports/pkgs install to /usr/local by default. # This should also work for all the other BSDs, such as OpenBSD or DragonFly. self.__playerController.vlcIntfPath = "/usr/local/lib/vlc/lua/intf/" self.__playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") elif "vlcportable.exe" in playerPath.lower(): self.__playerController.vlcIntfPath = os.path.dirname(playerPath).replace("\\", "/") + "/App/vlc/lua/intf/" self.__playerController.vlcIntfUserPath = playerController.vlcIntfPath else: self.__playerController.vlcIntfPath = os.path.dirname(playerPath).replace("\\", "/") + "/lua/intf/" self.__playerController.vlcIntfUserPath = os.path.join(os.getenv('APPDATA', '.'), "VLC\\lua\\intf\\") self.__playerController.vlcModulePath = self.__playerController.vlcIntfPath + "modules/?.luac" def _createIntfFolder(vlcSyncplayInterfaceDir): self.__playerController._client.ui.showDebugMessage("Checking if syncplay.lua intf directory exists") from pathlib import Path if os.path.exists(vlcSyncplayInterfaceDir): self.__playerController._client.ui.showDebugMessage("Found syncplay.lua intf directory:'{}'".format(vlcSyncplayInterfaceDir)) else: self.__playerController._client.ui.showDebugMessage("syncplay.lua intf directory not found, so creating directory '{}'".format(vlcSyncplayInterfaceDir)) Path(vlcSyncplayInterfaceDir).mkdir(mode=0o755, parents=True, exist_ok=True) try: _createIntfFolder(self.__playerController.vlcIntfUserPath) copyForm = utils.findResourcePath("syncplay.lua") copyTo = os.path.join(self.__playerController.vlcIntfUserPath, "syncplay.lua") self.__playerController._client.ui.showDebugMessage("Copying VLC Lua Interface from '{}' to '{}'".format(copyForm, copyTo)) import shutil if os.path.exists(copyTo): os.chmod(copyTo, 0o755) shutil.copyfile(copyForm, copyTo) os.chmod(copyTo, 0o755) except Exception as e: self.__playerController._client.ui.showErrorMessage(e) return if isLinux(): self.__playerController.vlcDataPath = "/usr/lib/syncplay/resources" else: self.__playerController.vlcDataPath = utils.findWorkingDir() + "\\resources" self.__playerController.SLAVE_ARGS.append( '--lua-config=syncplay={{modulepath=\"{}\",port=\"{}\"}}'.format( self.__playerController.vlcModulePath, str(self.__playerController.vlcport))) call.extend(self.__playerController.SLAVE_ARGS) if args: call.extend(args) self._vlcVersion = None if isWindows() and getattr(sys, 'frozen', '') and getattr(sys, '_MEIPASS', '') is not None: # Needed for pyinstaller --onefile bundle self.__process = subprocess.Popen( call, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, creationflags=0x08000000) else: self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE) self.timeVLCLaunched = time.time() if self._shouldListenForSTDOUT(): for line in iter(self.__process.stderr.readline, ''): line = line.decode('utf-8') self.vlcHasResponded = True self.timeVLCLaunched = None if "[syncplay]" in line: if "Listening on host" in line: break if "Hosting Syncplay" in line: break elif "Couldn't find lua interface" in line: self.__playerController._client.ui.showErrorMessage( getMessage("vlc-failed-noscript").format(line), True) break elif "lua interface error" in line: self.__playerController._client.ui.showErrorMessage( getMessage("media-player-error").format(line), True) break if not isMacOS(): self.__process.stderr = None else: vlcoutputthread = threading.Thread(target=self.handle_vlcoutput, args=()) vlcoutputthread.setDaemon(True) vlcoutputthread.start() self.__playerController._vlcready.clear() self._factory = VLCClientFactory(self.__playerController, self.vlcHasResponded, self.timeVLCLaunched, self.__process) self.reactor.connectTCP('localhost', self.__playerController.vlcport, self._factory)
def __init__(self, playerController, playerPath, filePath, args, vlcReady, vlcClosed): self.__playerController = playerController self.requestedVLCVersion = False self.vlcHasResponded = False self.oldIntfVersion = None self.timeVLCLaunched = None call = [playerPath] if filePath: if utils.isASCII(filePath): call.append(filePath) else: call.append(self.__playerController.getMRL(filePath)) if isLinux(): if 'snap' in playerPath: playerController.vlcIntfPath = '/snap/vlc/current/usr/lib/vlc/lua/intf/' playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), "snap/vlc/current/.local/share/vlc/lua/intf/") else: playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") elif isMacOS(): playerController.vlcIntfPath = "/Applications/VLC.app/Contents/MacOS/share/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/") elif isBSD(): # *BSD ports/pkgs install to /usr/local by default. # This should also work for all the other BSDs, such as OpenBSD or DragonFly. playerController.vlcIntfPath = "/usr/local/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") elif "vlcportable.exe" in playerPath.lower(): playerController.vlcIntfPath = os.path.dirname( playerPath).replace("\\", "/") + "/App/vlc/lua/intf/" playerController.vlcIntfUserPath = playerController.vlcIntfPath else: 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" def _createIntfFolder(vlcSyncplayInterfaceDir): self.__playerController._client.ui.showDebugMessage( "Checking if syncplay.lua intf directory exists") from pathlib import Path if os.path.exists(vlcSyncplayInterfaceDir): self.__playerController._client.ui.showDebugMessage( "Found syncplay.lua intf directory:'{}'".format( vlcSyncplayInterfaceDir)) else: self.__playerController._client.ui.showDebugMessage( "syncplay.lua intf directory not found, so creating directory '{}'" .format(vlcSyncplayInterfaceDir)) Path(vlcSyncplayInterfaceDir).mkdir(mode=0o755, parents=True, exist_ok=True) 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: _createIntfFolder(playerController.vlcIntfUserPath) 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 if os.path.exists(copyTo): os.chmod(copyTo, 0o755) shutil.copyfile(copyForm, copyTo) os.chmod(copyTo, 0o755) except Exception as e: playerController._client.ui.showErrorMessage(e) return if isLinux(): playerController.vlcDataPath = "/usr/lib/syncplay/resources" else: playerController.vlcDataPath = utils.findWorkingDir( ) + "\\resources" playerController.SLAVE_ARGS.append( '--lua-config=syncplay={{modulepath=\"{}\",port=\"{}\"}}'. format(playerController.vlcModulePath, str(playerController.vlcport))) call.extend(playerController.SLAVE_ARGS) if args: call.extend(args) self._vlcready = vlcReady self._vlcclosed = vlcClosed self._vlcVersion = None if isWindows() and getattr(sys, 'frozen', '') and getattr( sys, '_MEIPASS', '') is not None: # Needed for pyinstaller --onefile bundle self.__process = subprocess.Popen(call, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, creationflags=0x08000000) else: self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE) self.timeVLCLaunched = time.time() if self._shouldListenForSTDOUT(): for line in iter(self.__process.stderr.readline, ''): line = line.decode('utf-8') self.vlcHasResponded = True self.timeVLCLaunched = None if "[syncplay]" in line: if "Listening on host" in line: break if "Hosting Syncplay" in line: break elif "Couldn't find lua interface" in line: playerController._client.ui.showErrorMessage( getMessage("vlc-failed-noscript").format(line), True) break elif "lua interface error" in line: playerController._client.ui.showErrorMessage( getMessage("media-player-error").format(line), True) break if not isMacOS(): self.__process.stderr = None else: vlcoutputthread = threading.Thread( target=self.handle_vlcoutput, args=()) vlcoutputthread.setDaemon(True) vlcoutputthread.start() threading.Thread.__init__(self, name="VLC Listener") asynchat.async_chat.__init__(self) self.set_terminator(b'\n') self._ibuffer = [] self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self._sendingData = threading.Lock()
def getConfiguration(self): iniPath = self._getConfigurationFilePath() self._parseConfigFile(iniPath) # # Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments # if self._config['language']: setLanguage(self._config['language']) self._argparser = argparse.ArgumentParser( description=getMessage("argument-description"), epilog=getMessage("argument-epilog")) self._argparser.add_argument('--no-gui', action='store_true', help=getMessage("nogui-argument")) self._argparser.add_argument('-a', '--host', metavar='hostname', type=str, help=getMessage("host-argument")) self._argparser.add_argument('-n', '--name', metavar='username', type=str, help=getMessage("name-argument")) self._argparser.add_argument('-d', '--debug', action='store_true', help=getMessage("debug-argument")) self._argparser.add_argument('-g', '--force-gui-prompt', action='store_true', help=getMessage("force-gui-prompt-argument")) self._argparser.add_argument('--no-store', action='store_true', help=getMessage("no-store-argument")) self._argparser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help=getMessage("room-argument")) self._argparser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help=getMessage("password-argument")) self._argparser.add_argument('--player-path', metavar='path', type=str, help=getMessage("player-path-argument")) self._argparser.add_argument('-psn', metavar='blackhole', type=str, help=argparse.SUPPRESS) self._argparser.add_argument('--language', metavar='language', type=str, help=getMessage("language-argument")) self._argparser.add_argument('file', metavar='file', type=str, nargs='?', help=getMessage("file-argument")) self._argparser.add_argument('--clear-gui-data', action='store_true', help=getMessage("clear-gui-data-argument")) self._argparser.add_argument('-v', '--version', action='store_true', help=getMessage("version-argument")) self._argparser.add_argument('--load-playlist-from-file', metavar="loadPlaylistFromFile", type=str, help=getMessage("load-playlist-from-file-argument")) self._argparser.add_argument('_args', metavar='options', type=str, nargs='*', help=getMessage("args-argument")) args = self._argparser.parse_args() if args.version: print(getMessage("version-message").format(version, milestone)) sys.exit() self._overrideConfigWithArgs(args) if not self._config['noGui']: try: from syncplay.vendor.Qt import QtWidgets, IsPySide, IsPySide2, QtGui from syncplay.vendor.Qt.QtCore import QCoreApplication from syncplay.vendor import qt5reactor if not (IsPySide2 or IsPySide): raise ImportError if QCoreApplication.instance() is None: self.app = QtWidgets.QApplication(sys.argv) if isWindows(): try: from syncplay.vendor import darkdetect isDarkMode = darkdetect.isDark() except: isDarkMode = False if isDarkMode: self.app.setStyle(QtWidgets.QStyleFactory.create("fusion")) self.app.setPalette(self.getDarkPalette(QtGui)) qt5reactor.install() if isMacOS(): import appnope appnope.nope() except ImportError: try: from twisted.trial import unittest except Exception as e: print(e) print(getMessage("unable-import-twisted-error")) sys.exit() print(getMessage("unable-import-gui-error")) self._config['noGui'] = True if self._config['file'] and self._config['file'][:2] == "--": self._config['playerArgs'].insert(0, self._config['file']) self._config['file'] = None # Arguments not validated yet - booleans are still text values if self._config['language']: setLanguage(self._config['language']) if (self._config['forceGuiPrompt'] == "True" or not self._config['file']) and not self._config['noGui']: self._forceGuiPrompt() self._checkConfig() self._saveConfig(iniPath) if self._config['file']: self._config['loadedRelativePaths'] = self._loadRelativeConfiguration() if self._config['language']: setLanguage(self._config['language']) return self._config
def _shouldListenForSTDOUT(self): return not isWindows()
def __init__(self, playerController, playerPath, filePath, args, vlcReady, vlcClosed): self.__playerController = playerController self.requestedVLCVersion = False self.vlcHasResponded = False self.oldIntfVersion = None self.timeVLCLaunched = None call = [playerPath] if filePath: if utils.isASCII(filePath): call.append(filePath) else: call.append(self.__playerController.getMRL(filePath)) if isLinux(): playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") elif isMacOS(): playerController.vlcIntfPath = "/Applications/VLC.app/Contents/MacOS/share/lua/intf/" playerController.vlcIntfUserPath = os.path.join( os.getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/") elif isBSD(): # *BSD ports/pkgs install to /usr/local by default. # This should also work for all the other BSDs, such as OpenBSD or DragonFly. playerController.vlcIntfPath = "/usr/local/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") else: 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" def _createIntfFolder(vlcSyncplayInterfaceDir): self.__playerController._client.ui.showDebugMessage("Checking if syncplay.lua intf directory exists") from pathlib import Path if os.path.exists(vlcSyncplayInterfaceDir): self.__playerController._client.ui.showDebugMessage("Found syncplay.lua intf directory:'{}'".format(vlcSyncplayInterfaceDir)) else: self.__playerController._client.ui.showDebugMessage("syncplay.lua intf directory not found, so creating directory '{}'".format(vlcSyncplayInterfaceDir)) Path(vlcSyncplayInterfaceDir).mkdir(mode=0o755, parents=True, exist_ok=True) 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: _createIntfFolder(playerController.vlcIntfUserPath) 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 if os.path.exists(copyTo): os.chmod(copyTo, 0o755) shutil.copyfile(copyForm, copyTo) os.chmod(copyTo, 0o755) except Exception as e: playerController._client.ui.showErrorMessage(e) return 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))) call.extend(playerController.SLAVE_ARGS) if args: call.extend(args) self._vlcready = vlcReady self._vlcclosed = vlcClosed self._vlcVersion = None if isWindows() and getattr(sys, 'frozen', '') and getattr(sys, '_MEIPASS', '') is not None: # Needed for pyinstaller --onefile bundle self.__process = subprocess.Popen( call, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, creationflags=0x08000000) else: self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE) self.timeVLCLaunched = time.time() if self._shouldListenForSTDOUT(): for line in iter(self.__process.stderr.readline, ''): line = line.decode('utf-8') self.vlcHasResponded = True self.timeVLCLaunched = None if "[syncplay]" in line: if "Listening on host" in line: break if "Hosting Syncplay" in line: break elif "Couldn't find lua interface" in line: playerController._client.ui.showErrorMessage( getMessage("vlc-failed-noscript").format(line), True) break elif "lua interface error" in line: playerController._client.ui.showErrorMessage( getMessage("media-player-error").format(line), True) break if not isMacOS(): self.__process.stderr = None else: vlcoutputthread = threading.Thread(target=self.handle_vlcoutput, args=()) vlcoutputthread.setDaemon(True) vlcoutputthread.start() threading.Thread.__init__(self, name="VLC Listener") asynchat.async_chat.__init__(self) self.set_terminator(b'\n') self._ibuffer = [] self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self._sendingData = threading.Lock()