Skip to content

Commit

Permalink
Improve mpv error handling and display 'mpv-failed-advice' if load fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Et0h committed May 16, 2020
1 parent 626f93e commit 5df3046
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions syncplay/messages_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"mpc-version-insufficient-error": "MPC-Version nicht ausreichend, bitte nutze `mpc-hc` >= `{}`",
"mpc-be-version-insufficient-error": "MPC-Version nicht ausreichend, bitte nutze `mpc-be` >= `{}`",
"mpv-version-error": "Syncplay ist nicht kompatibel mit dieser Version von mpv. Bitte benutze eine andere Version (z.B. Git HEAD).",
"mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.", # TODO: Translate
"player-file-open-error": "Fehler beim Öffnen der Datei durch den Player",
"player-path-error": "Ungültiger Player-Pfad. Unterstützte Player sind: mpv, mpv.net, VLC, MPC-HC, MPC-BE und mplayer2",
"hostname-empty-error": "Hostname darf nicht leer sein",
Expand Down
1 change: 1 addition & 0 deletions syncplay/messages_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"mpc-version-insufficient-error": "MPC version not sufficient, please use `mpc-hc` >= `{}`",
"mpc-be-version-insufficient-error": "MPC version not sufficient, please use `mpc-be` >= `{}`",
"mpv-version-error": "Syncplay is not compatible with this version of mpv. Please use a different version of mpv (e.g. Git HEAD).",
"mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.",
"player-file-open-error": "Player failed opening file",
"player-path-error": "Player path is not set properly. Supported players are: mpv, mpv.net, VLC, MPC-HC, MPC-BE and mplayer2",
"hostname-empty-error": "Hostname can't be empty",
Expand Down
1 change: 1 addition & 0 deletions syncplay/messages_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"mpc-version-insufficient-error": "La versión de MPC no es suficiente, por favor utiliza `mpc-hc` >= `{}`",
"mpc-be-version-insufficient-error": "La versión de MPC no es suficiente, por favor utiliza `mpc-be` >= `{}`",
"mpv-version-error": "Syncplay no es compatible con esta versión de mpv. Por favor utiliza una versión diferente de mpv (p.ej. Git HEAD).",
"mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.", # TODO: Translate
"player-file-open-error": "El reproductor falló al abrir el archivo",
"player-path-error": "La ruta del reproductor no está definida correctamente. Los reproductores soportados son: mpv, mpv.net, VLC, MPC-HC, MPC-BE y mplayer2",
"hostname-empty-error": "El nombre del host no puede ser vacío",
Expand Down
1 change: 1 addition & 0 deletions syncplay/messages_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"mpc-version-insufficient-error": "La tua versione di MPC è troppo vecchia, per favore usa `mpc-hc` >= `{}`",
"mpc-be-version-insufficient-error": "La tua versione di MPC è troppo vecchia, per favore usa `mpc-be` >= `{}`",
"mpv-version-error": "Syncplay non è compatibile con questa versione di mpv. Per favore usa un'altra versione di mpv (es. Git HEAD).",
"mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.", # TODO: Translate
"player-file-open-error": "Il player non è riuscito ad aprire il file",
"player-path-error": "Il path del player non è configurato correttamente. I player supportati sono: mpv, mpv.net, VLC, MPC-HC, MPC-BE e mplayer2",
"hostname-empty-error": "Il campo hostname non può essere vuoto",
Expand Down
1 change: 1 addition & 0 deletions syncplay/messages_pt_BR.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"mpc-version-insufficient-error": "A versão do MPC é muito antiga, por favor use `mpc-hc` >= `{}`",
"mpc-be-version-insufficient-error": "A versão do MPC-BE é muito antiga, por favor use `mpc-be` >= `{}`",
"mpv-version-error": "O Syncplay não é compatível com esta versão do mpv. Por favor, use uma versão diferente do mpv (por exemplo, Git HEAD).",
"mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.", # TODO: Translate
"player-file-open-error": "O reprodutor falhou ao abrir o arquivo",
"player-path-error": "O caminho até o arquivo executável do reprodutor não está configurado corretamente. Os reprodutores suportados são: mpv, mpv.net, VLC, MPC-HC, MPC-BE e mplayer2",
"hostname-empty-error": "O endereço do servidor não pode ser vazio",
Expand Down
1 change: 1 addition & 0 deletions syncplay/messages_ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"mpc-version-insufficient-error": "Версия MPC слишком старая, пожалуйста, используйте `mpc-hc` >= `{}`",
"mpc-be-version-insufficient-error": "Версия MPC слишком старая, пожалуйста, используйте `mpc-be` >= `{}`",
"mpv-version-error": "Syncplay не совместим с данной версией mpv. Пожалуйста, используйте другую версию mpv (лучше свежайшую).",
"mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.", # TODO: Translate
"player-file-open-error": "Проигрыватель не может открыть файл.",
"player-path-error": "Путь к проигрывателю задан неверно. Supported players are: mpv, mpv.net, VLC, MPC-HC, MPC-BE and mplayer2.", # TODO: Translate last sentence
"hostname-empty-error": "Имя пользователя не может быть пустым.",
Expand Down
28 changes: 21 additions & 7 deletions syncplay/players/mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,22 @@ def askForStatus(self):
self._paused if self.fileLoaded else self._client.getGlobalPaused(), self.getCalculatedPosition())

def drop(self):
self._listener.sendLine(['quit'])
try:
self._listener.sendLine(['quit'])
except AttributeError as e:
self._client.ui.showDebugMessage("Could not send quit message: {}".format(str(e)))
self._takeLocksDown()
self.reactor.callFromThread(self._client.stop, False)

def _takeLocksDown(self):
self._durationAsk.set()
self._filenameAsk.set()
self._pathAsk.set()
self._positionAsk.set()
self._pausedAsk.set()
try:
self._durationAsk.set()
self._filenameAsk.set()
self._pathAsk.set()
self._positionAsk.set()
self._pausedAsk.set()
except:
pass


def _getPausedAndPosition(self):
Expand Down Expand Up @@ -519,6 +525,9 @@ def __init__(self, client, playerPath, filePath, args):
self._client.ui.showMessage(getMessage("mplayer-file-required-notification/example"))
self.drop()
return
except AttributeError as e:
self._client.ui.showErrorMessage("Could not load mpv: " + str(e))
return
self._listener.setDaemon(True)
self._listener.start()

Expand Down Expand Up @@ -588,7 +597,12 @@ def __init__(self, playerController, playerPath, filePath, args):
if pythonPath is not None:
env['PATH'] = '/usr/bin:/usr/local/bin'
env['PYTHONPATH'] = pythonPath
self.mpvpipe = MPV(mpv_location=self.playerPath, loglevel="info", log_handler=self.__playerController.mpv_log_handler, quit_callback=self.stop_client, **self.mpv_arguments)
try:
self.mpvpipe = MPV(mpv_location=self.playerPath, loglevel="info", log_handler=self.__playerController.mpv_log_handler, quit_callback=self.stop_client, **self.mpv_arguments)
except Exception as e:
self.quitReason = getMessage("media-player-error").format(str(e)) + " " + getMessage("mpv-failed-advice")
self.__playerController.reactor.callFromThread(self.__playerController._client.ui.showErrorMessage, self.quitReason, True)
self.__playerController.drop()
self.__process = self.mpvpipe
#self.mpvpipe.show_text("HELLO WORLD!", 1000)
threading.Thread.__init__(self, name="MPV Listener")
Expand Down

0 comments on commit 5df3046

Please sign in to comment.