Handle VLC 3's lack of Syncplay support

This commit is contained in:
Et0h 2016-08-30 12:48:33 +01:00
parent 80a1f2e546
commit 351024fcaa
6 changed files with 73 additions and 54 deletions

View File

@ -5,7 +5,7 @@
Principal author: Etoh
Other contributors: DerGenaue, jb, Pilotat
Project: http://syncplay.pl/
Version: 0.3.1
Version: 0.3.2
Note:
* This interface module is intended to be used in conjunction with Syncplay.
@ -84,7 +84,7 @@ You may also need to re-copy the syncplay.lua file when you update VLC.
--]==========================================================================]
local connectorversion = "0.3.1"
local connectorversion = "0.3.2"
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)
@ -122,6 +122,15 @@ local l
local running = true
if vlcmajorversion == 3 then
-- VLC 3 does not currently support syncplay
running = false
vlc.msg.err("This version of VLC does not support Syncplay. Please use VLC 2.2.1+ or an alternative media player. VLC 3 does not support Syncplay.")
while true do
vlc.misc.quit()
vlc.misc.mwait(vlc.misc.mdate()+100000)
end
end
function radixsafe_tonumber(str)
-- Version of tonumber that works with any radix character (but not thousand seperators)
@ -243,10 +252,6 @@ function get_var( vartoget, fallbackvar )
errormsg = noinput
end
if vlcmajorversion == 3 and vartoget == "time" then
response = response / 1000000
end
return response, errormsg
end
@ -257,10 +262,6 @@ function set_var(vartoset, varvalue)
local errormsg
local input = vlc.object.input()
if vlcmajorversion == 3 and vartoset == "time" then
varvalue = varvalue * 1000000
end
if input then
vlc.var.set(input,tostring(vartoset),varvalue)
else
@ -543,9 +544,9 @@ function set_playstate(argument)
end
if string.sub(vlcversion,1,2) == "1." or string.sub(vlcversion,1,3) == "2.0" or string.sub(vlcversion,1,3) == "2.1" or string.sub(vlcversion,1,5) == "2.2.0" then
vlc.msg.err("This version of VLC does not support Syncplay. Please use VLC 2.2.1+.")
vlc.msg.err("This version of VLC does not support Syncplay. Please use VLC 2.2.1+ or an alternative media player. VLC 3 does not support Syncplay.")
quit_vlc()
else
elseif vlcmajorversion ~= 3 then
l = vlc.net.listen_tcp(host, port)
vlc.msg.info("Hosting Syncplay interface on port: "..port)
end
@ -620,4 +621,4 @@ while running == true do
end
end
end

View File

@ -72,7 +72,7 @@ COMMANDS_AUTH = ['a','auth']
COMMANDS_TOGGLE = ['t','toggle']
MPC_MIN_VER = "1.6.4"
VLC_MIN_VERSION = "2.2.1"
VLC_INTERFACE_MIN_VERSION = "0.3.0"
VLC_INTERFACE_MIN_VERSION = "0.3.2"
VLC_LATENCY_ERROR_THRESHOLD = 2.0
MPV_UNRESPONSIVE_THRESHOLD = 60.0
CONTROLLED_ROOMS_MIN_VERSION = "1.3.0"

View File

@ -92,8 +92,8 @@ de = {
"language-changed-msgbox-label" : u"Die Sprache wird geändert, wenn du Syncplay neu startest.",
"promptforupdate-label" : u"Soll Syncplay regelmäßig nach Updates suchen?",
"vlc-version-mismatch": u"Warnung: Du nutzt VLC Version {}, aber Syncplay wurde für VLC ab Version {} entwickelt.", # VLC version, VLC min version
"vlc-interface-version-mismatch": u"Warnung: Du nutzt Version {} des VLC-Syncplay Interface-Moduls, Syncplay benötigt aber mindestens Version {}.", # VLC interface version, VLC interface min version
"vlc-version-mismatch": u"This version of VLC does not support Syncplay. VLC {}+ supports Syncplay but VLC 3 does not. Please use an alternative media player.", # VLC min version # TODO: Translate
"vlc-interface-version-mismatch": u"Du nutzt Version {} des VLC-Syncplay Interface-Moduls, Syncplay benötigt aber mindestens Version {}. In der Syncplay-Anleitung unter http://syncplay.pl/guide/ [Englisch] findest du Details zur Installation des syncplay.lua-Skripts.", # VLC interface version, VLC interface min version
"vlc-interface-oldversion-warning": u"Warnung: Es ist eine alte Version des Syncplay Interface-Moduls für VLC im VLC-Verzeichnis installiert. In der Syncplay-Anleitung unter http://syncplay.pl/guide/ [Englisch] findest du Details zur Installation des syncplay.lua-Skripts.",
"vlc-interface-not-installed": u"Warnung: Es wurde kein Syncplay Interface-Modul für VLC im VLC-Verzeichnis gefunden. Daher wird, wenn du VLC 2.0 nutzt, die syncplay.lua die mit Syncplay mitgeliefert wurde, verwendet. Dies bedeutet allerdings, dass keine anderen Interface-Skripts und Erweiterungen geladen werden. In der Syncplay-Anleitung unter http://syncplay.pl/guide/ [Englisch] findest du Details zur Installation des syncplay.lua-Skripts.",
"media-player-latency-warning": u"Warnung: Der Mediaplayer brauchte {} Sekunden zum Antworten. Wenn Probleme bei der Synchronisation auftreten, schließe bitte andere Anwendungen, um Ressourcen freizugeben. Sollte das nicht funktionieren, versuche es mit einem anderen Media-Player.", # Seconds to respond

View File

@ -92,8 +92,8 @@ en = {
"language-changed-msgbox-label" : "Language will be changed when you run Syncplay.",
"promptforupdate-label" : u"Is it okay for Syncplay to automatically check for updates from time to time?",
"vlc-version-mismatch": "Warning: You are running VLC version {}, but Syncplay is designed to run on VLC {} and above.", # VLC version, VLC min version
"vlc-interface-version-mismatch": "Warning: You are running version {} of the Syncplay interface module for VLC, but Syncplay is designed to run with version {} and above.", # VLC interface version, VLC interface min version
"vlc-version-mismatch": u"This version of VLC does not support Syncplay. VLC {}+ supports Syncplay but VLC 3 does not. Please use an alternative media player.", # VLC min version
"vlc-interface-version-mismatch": "You are running version {} of the Syncplay interface module for VLC, but Syncplay is designed to run with version {} and above. Please refer to the Syncplay User Guide at http://syncplay.pl/guide/ for instructions on how to install syncplay.lua.", # VLC interface version, VLC interface min version
"vlc-interface-oldversion-warning": "Warning: Syncplay detected that an old version version of the Syncplay interface module for VLC was installed in the VLC directory. Please refer to the Syncplay User Guide at http://syncplay.pl/guide/ for instructions on how to install syncplay.lua.",
"vlc-interface-not-installed": "Warning: The Syncplay interface module for VLC was not found in the VLC directory. As such, if you are running VLC 2.0 then VLC will use the syncplay.lua module contained within the Syncplay directory, but this will mean that other custom interface scripts and extensions will not work. Please refer to the Syncplay User Guide at http://syncplay.pl/guide/ for instructions on how to install syncplay.lua.",
"media-player-latency-warning": u"Warning: The media player took {} seconds to respond. If you experience syncing issues then close applications to free up system resources, and if that doesn't work then try a different media player.", # Seconds to respond

View File

@ -92,8 +92,8 @@ ru = {
"language-changed-msgbox-label" : u"Язык переключится при следующем запуске SYncplay.",
"promptforupdate-label" : u"Вы не против, если Syncplay будет автоматически изредка проверять наличие обновлений?",
"vlc-version-mismatch" : u"Внимание: Вы используете VLC устаревшей версии {}. К сожалению, Syncplay способен работать с VLC {} и выше.", # VLC version, VLC min version
"vlc-interface-version-mismatch" : u"Внимание: В используете модуль интерфейса Syncplay устаревшей версии {} для VLC. К сожалению, Syncplay способен работать с версией {} и выше.", # VLC interface version, VLC interface min version
"vlc-version-mismatch": u"This version of VLC does not support Syncplay. VLC {}+ supports Syncplay but VLC 3 does not. Please use an alternative media player.", # VLC min version # TODO: Translate
"vlc-interface-version-mismatch" : u"В используете модуль интерфейса Syncplay устаревшей версии {} для VLC. К сожалению, Syncplay способен работать с версией {} и выше. Пожалуйста, обратитесь к Руководству Пользователя Syncplay (http://syncplay.pl/guide/) за инструкциями о том, как установить syncplay.lua.", # VLC interface version, VLC interface min version
"vlc-interface-oldversion-warning" : u"Внимание: Syncplay обнаружил, что старая версия модуля интерфейса Syncplay для VLC уже установлена в директорию VLC. Пожалуйста, обратитесь к Руководству Пользователя Syncplay (http://syncplay.pl/guide/) за инструкциями о том, как установить syncplay.lua.",
"vlc-interface-not-installed" : u"Внимание: Модуль интерфейса Syncplay для VLC не обнаружен в директории VLC. По существу, если Вы используете VLC 2.0, то VLC будет использовать модуль syncplay.lua из директории Syncplay, но в таком случае другие пользовательские скрипты и расширения интерфейса не будут работать. Пожалуйста, обратитесь к Руководству Пользователя Syncplay (http://syncplay.pl/guide/) за инструкциями о том, как установить syncplay.lua.",
"media-player-latency-warning": u"Внимание: У Вашего проигрывателя слишком большой отклик ({} секунд). Если Вы замечаете проблемы с синхронизацией, то закройте ресурсоемкие приложения, а если это не помогло - попробуйте другой проигрыватель.", # Seconds to respond

View File

@ -50,19 +50,23 @@ class VlcPlayer(BasePlayer):
self._pausedAsk = threading.Event()
self._vlcready = threading.Event()
self._vlcclosed = threading.Event()
self._listener = None
try:
self._listener = self.__Listener(self, playerPath, filePath, args, self._vlcready, self._vlcclosed)
except ValueError:
self._client.ui.showErrorMessage(getMessage("vlc-failed-connection"), True)
self.reactor.callFromThread(self._client.stop, True,)
return
self._listener.setDaemon(True)
self._listener.start()
if not self._vlcready.wait(constants.VLC_OPEN_MAX_WAIT_TIME):
self._vlcready.set()
self._client.ui.showErrorMessage(getMessage("vlc-failed-connection"), True)
self.reactor.callFromThread(self._client.stop, True,)
self.reactor.callFromThread(self._client.initPlayer, self,)
try:
self._listener.setDaemon(True)
self._listener.start()
if not self._vlcready.wait(constants.VLC_OPEN_MAX_WAIT_TIME):
self._vlcready.set()
self._client.ui.showErrorMessage(getMessage("vlc-failed-connection"), True)
self.reactor.callFromThread(self._client.stop, True,)
self.reactor.callFromThread(self._client.initPlayer, self,)
except:
pass
def _fileUpdateClearEvents(self):
self._durationAsk.clear()
@ -200,7 +204,7 @@ class VlcPlayer(BasePlayer):
elif line.startswith("vlc-version: "):
vlc_version = line.split(': ')[1].replace(' ','-').split('-')[0]
if not utils.meetsMinVersion(vlc_version, constants.VLC_MIN_VERSION):
self._client.ui.showErrorMessage(getMessage("vlc-version-mismatch").format(str(vlc_version), str(constants.VLC_MIN_VERSION)))
self._client.ui.showErrorMessage(getMessage("vlc-version-mismatch").format(constants.VLC_MIN_VERSION))
self._vlcready.set()
@staticmethod
@ -247,22 +251,27 @@ class VlcPlayer(BasePlayer):
if os.access(path, os.X_OK):
return path
def drop(self):
self._vlcclosed.clear()
self._listener.sendLine('close-vlc')
self._vlcclosed.wait()
def drop(self, dropErrorMessage=None):
if self._listener:
self._vlcclosed.clear()
self._listener.sendLine('close-vlc')
self._vlcclosed.wait()
self._durationAsk.set()
self._filenameAsk.set()
self._pathAsk.set()
self._positionAsk.set()
self._vlcready.set()
self._pausedAsk.set()
if dropErrorMessage:
self.reactor.callFromThread(self._client.ui.showErrorMessage, dropErrorMessage, True)
self.reactor.callFromThread(self._client.stop, False,)
class __Listener(threading.Thread, asynchat.async_chat):
def __init__(self, playerController, playerPath, filePath, args, vlcReady, vlcClosed):
self.__playerController = playerController
self.requestedVLCVersion = False
self.vlcHasResponded = False
self.oldIntfVersion = None
call = [playerPath]
if filePath:
if utils.isASCII(filePath):
@ -281,7 +290,7 @@ class VlcPlayer(BasePlayer):
if utils.meetsMinVersion(interface_version, constants.VLC_INTERFACE_MIN_VERSION):
return True
else:
playerController._client.ui.showErrorMessage(getMessage("vlc-interface-oldversion-warning"))
self.oldIntfVersion = line[26:31]
return False
playerController._client.ui.showErrorMessage(getMessage("vlc-interface-not-installed"))
return False
@ -316,26 +325,32 @@ class VlcPlayer(BasePlayer):
self._vlcready = vlcReady
self._vlcclosed = vlcClosed
self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
for line in iter(self.__process.stderr.readline, ''):
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
self.__process.stderr = None
threading.Thread.__init__(self, name="VLC Listener")
asynchat.async_chat.__init__(self)
self.set_terminator("\n")
self._ibuffer = []
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self._sendingData = threading.Lock()
if self.oldIntfVersion:
self.__playerController.drop(getMessage("vlc-interface-version-mismatch").format(self.oldIntfVersion,constants.VLC_INTERFACE_MIN_VERSION))
else:
self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
for line in iter(self.__process.stderr.readline, ''):
self.vlcHasResponded = True
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
self.__process.stderr = None
threading.Thread.__init__(self, name="VLC Listener")
asynchat.async_chat.__init__(self)
self.set_terminator("\n")
self._ibuffer = []
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self._sendingData = threading.Lock()
def initiate_send(self):
with self._sendingData:
@ -355,7 +370,10 @@ class VlcPlayer(BasePlayer):
def handle_close(self):
asynchat.async_chat.handle_close(self)
self.__playerController.drop()
if self.vlcHasResponded:
self.__playerController.drop()
else:
self.__playerController.drop(getMessage("vlc-version-mismatch").format(constants.VLC_MIN_VERSION))
def found_terminator(self):
self.__playerController.lineReceived("".join(self._ibuffer))