From bed49869795f5bffd59d3dad657a965c2644b107 Mon Sep 17 00:00:00 2001 From: et0h Date: Sun, 2 Jan 2022 12:49:56 +0000 Subject: [PATCH] Add Windows Store mpv.net path support (#494) --- syncplay/constants.py | 8 ++++++-- syncplay/players/mpvnet.py | 7 ++++--- syncplay/ui/GuiConfiguration.py | 12 +++++++----- syncplay/utils.py | 7 +++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/syncplay/constants.py b/syncplay/constants.py index 148de9776..04e2d75d0 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -173,8 +173,12 @@ def getValueForOS(constantDict): MPV_PATHS = ["mpv", "/opt/mpv/mpv", r"c:\program files\mpv\mpv.exe", r"c:\program files\mpv-player\mpv.exe", r"c:\program Files (x86)\mpv\mpv.exe", r"c:\program Files (x86)\mpv-player\mpv.exe", "/Applications/mpv.app/Contents/MacOS/mpv"] -MPVNET_PATHS = [r"c:\program files\mpv.net\mpvnet.exe", r"c:\program files\mpv.net\mpvnet.exe", - r"c:\program Files (x86)\mpv.net\mpvnet.exe", r"c:\program Files (x86)\mpv.net\mpvnet.exe"] +MPVNET_PATHS = [r"c:\program files\mpv.net\mpvnet.exe", r"c:\program Files (x86)\mpv.net\mpvnet.exe"] +try: + import os + MPVNET_PATHS.append(os.path.expandvars(r'%LOCALAPPDATA%\Microsoft\WindowsApps\mpvnet.exe')) +except: + pass VLC_PATHS = [ r"c:\program files (x86)\videolan\vlc\vlc.exe", r"c:\program files\videolan\vlc\vlc.exe", diff --git a/syncplay/players/mpvnet.py b/syncplay/players/mpvnet.py index 41088d540..ef28d18b6 100644 --- a/syncplay/players/mpvnet.py +++ b/syncplay/players/mpvnet.py @@ -1,6 +1,7 @@ import os from syncplay import constants from syncplay.players.mpv import MpvPlayer +from syncplay.utils import playerPathExists class MpvnetPlayer(MpvPlayer): @@ -30,11 +31,11 @@ def isValidPlayerPath(path): @staticmethod def getExpandedPath(playerPath): - if not os.path.isfile(playerPath): - if os.path.isfile(playerPath + "mpvnet.exe"): + if not playerPathExists(playerPath): + if playerPathExists(playerPath + "mpvnet.exe"): playerPath += "mpvnet.exe" return playerPath - elif os.path.isfile(playerPath + "\\mpvnet.exe"): + elif playerPathExists(playerPath + "\\mpvnet.exe"): playerPath += "\\mpvnet.exe" return playerPath if os.access(playerPath, os.X_OK): diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index 4feffb345..4a2530028 100755 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -9,7 +9,7 @@ from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage from syncplay.players.playerFactory import PlayerFactory from syncplay.utils import isBSD, isLinux, isMacOS, isWindows -from syncplay.utils import resourcespath, posixresourcespath +from syncplay.utils import resourcespath, posixresourcespath, playerPathExists from syncplay.vendor.Qt import QtCore, QtWidgets, QtGui, __binding__, IsPySide, IsPySide2 from syncplay.vendor.Qt.QtCore import Qt, QSettings, QCoreApplication, QSize, QPoint, QUrl, QLine, QEventLoop, Signal @@ -210,12 +210,14 @@ def _tryToFillPlayerPath(self, playerpath, playerpathlist): self.executablepathCombobox.addItem(foundpath) else: - if not os.path.isfile(playerpath): + if not playerPathExists(playerpath): expandedpath = PlayerFactory().getExpandedPlayerPathByPath(playerpath) - if expandedpath is not None and os.path.isfile(expandedpath): + if expandedpath is not None and playerPathExists(expandedpath): playerpath = expandedpath + elif "mpvnet.exe" in playerpath and playerPathExists(playerpath.replace("mpvnet.exe","mpvnet.com")): + self.executablepathCombobox.addItem(playerpath) - if os.path.isfile(playerpath): + if playerPathExists(playerpath): foundpath = playerpath self.executablepathCombobox.addItem(foundpath) @@ -226,7 +228,7 @@ def _tryToFillPlayerPath(self, playerpath, playerpathlist): if path != playerpath: self.executablepathCombobox.addItem(path) - elif os.path.isfile(path) and os.path.normcase(os.path.normpath(path)) != os.path.normcase(os.path.normpath(foundpath)): + elif playerPathExists(path) and os.path.normcase(os.path.normpath(path)) != os.path.normcase(os.path.normpath(foundpath)): self.executablepathCombobox.addItem(path) if foundpath == "": foundpath = path diff --git a/syncplay/utils.py b/syncplay/utils.py index bfc788c68..28a9d01f2 100755 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -417,6 +417,13 @@ def open_system_file_browser(path): else: subprocess.Popen(["xdg-open", path]) +def playerPathExists(path): + if os.path.isfile(path): + return True + elif "mpvnet.exe" in path and os.path.isfile(path.replace("mpvnet.exe","mpvnet.com")): + return True + else: + return False def getListOfPublicServers(): try: