|
| 1 | +import os |
| 2 | + |
| 3 | +from syncplay import constants |
| 4 | + |
| 5 | +from syncplay.players.mpv import MpvPlayer |
| 6 | +from syncplay.utils import findResourcePath, playerPathExists |
| 7 | + |
| 8 | + |
| 9 | +class MementoPlayer(MpvPlayer): |
| 10 | + @staticmethod |
| 11 | + def run(client, playerPath, filePath, args): |
| 12 | + return MementoPlayer( |
| 13 | + client, MementoPlayer.getExpandedPath(playerPath), filePath, args |
| 14 | + ) |
| 15 | + |
| 16 | + @staticmethod |
| 17 | + def getDefaultPlayerPathsList(): |
| 18 | + l = [] |
| 19 | + for path in constants.MEMENTO_PATHS: |
| 20 | + p = MementoPlayer.getExpandedPath(path) |
| 21 | + if p: |
| 22 | + l.append(p) |
| 23 | + return l |
| 24 | + |
| 25 | + @staticmethod |
| 26 | + def isValidPlayerPath(path): |
| 27 | + if "memento" in path and MementoPlayer.getExpandedPath(path): |
| 28 | + return True |
| 29 | + return False |
| 30 | + |
| 31 | + @staticmethod |
| 32 | + def getExpandedPath(playerPath): |
| 33 | + if not playerPathExists(playerPath): |
| 34 | + if playerPathExists(playerPath + "memento.exe"): |
| 35 | + playerPath += "memento.exe" |
| 36 | + return playerPath |
| 37 | + elif playerPathExists(playerPath + "\\memento.exe"): |
| 38 | + playerPath += "\\memento.exe" |
| 39 | + return playerPath |
| 40 | + if os.access(playerPath, os.X_OK): |
| 41 | + return playerPath |
| 42 | + for path in os.environ["PATH"].split(":"): |
| 43 | + path = os.path.join(os.path.realpath(path), playerPath) |
| 44 | + if os.access(path, os.X_OK): |
| 45 | + return path |
| 46 | + |
| 47 | + @staticmethod |
| 48 | + def getIconPath(path): |
| 49 | + return constants.MEMENTO_ICONPATH |
| 50 | + |
| 51 | + @staticmethod |
| 52 | + def getStartupArgs(userArgs): |
| 53 | + args = constants.MPV_ARGS |
| 54 | + args["scripts"] = findResourcePath("syncplayintf.lua") |
| 55 | + if userArgs: |
| 56 | + for argToAdd in userArgs: |
| 57 | + if argToAdd.startswith("--"): |
| 58 | + argToAdd = argToAdd[2:] |
| 59 | + elif argToAdd.startswith("-"): |
| 60 | + argToAdd = argToAdd[1:] |
| 61 | + if argToAdd.strip() == "": |
| 62 | + continue |
| 63 | + if "=" in argToAdd: |
| 64 | + (argName, argValue) = argToAdd.split("=", 1) |
| 65 | + if argValue[0] == '"' and argValue[-1] == '"': |
| 66 | + argValue = argValue[1:-1] |
| 67 | + else: |
| 68 | + argName = argToAdd |
| 69 | + argValue = "" |
| 70 | + args[argName] = argValue |
| 71 | + return args |
0 commit comments