From c4d454d38af8f28de68ba6eeaf947c43d542c9e2 Mon Sep 17 00:00:00 2001 From: Et0h Date: Mon, 10 Jun 2024 19:22:22 +0100 Subject: [PATCH 1/4] Re-introduce rewind double check --- syncplay/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncplay/constants.py b/syncplay/constants.py index b1af978..0cc124b 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -110,7 +110,7 @@ FOLDER_SEARCH_TIMEOUT = 20.0 # Secs - How long to wait until searches in folder FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL = 30.0 # Secs - Frequency of updating cache # Usually there's no need to adjust these -DOUBLE_CHECK_REWIND = False +DOUBLE_CHECK_REWIND = True LAST_PAUSED_DIFF_THRESHOLD = 2 FILENAME_STRIP_REGEX = r"[-~_\.\[\](): ]" CONTROL_PASSWORD_STRIP_REGEX = r"[^a-zA-Z0-9\-]" From 78171856143d660e07af90c89f62ca477baedf69 Mon Sep 17 00:00:00 2001 From: Et0h Date: Fri, 21 Jun 2024 12:19:36 +0100 Subject: [PATCH 2/4] Major re-work to playlist changing/advancement (#683 & #618) --- syncplay/client.py | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index 33ad1e6..e16324d 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -84,6 +84,9 @@ class SyncplayClient(object): self.lastRewindTime = None self.lastUpdatedFileTime = None self.lastAdvanceTime = None + self.fileOpenBeforeChangingPlaylistIndex = None + self.waitingToLoadNewfile = False + self.waitingToLoadNewfileSince = None self.lastConnectTime = None self.lastSetRoomTime = None self.hadFirstPlaylistIndex = False @@ -249,15 +252,24 @@ class SyncplayClient(object): if self._lastGlobalUpdate: self._lastPlayerUpdate = time.time() if (pauseChange or seeked) and self._protocol: + if self.recentlyRewound() or self._recentlyAdvanced(): + self._protocol.sendState(self._globalPosition, self.getPlayerPaused(), False, None, True) + return if seeked: self.playerPositionBeforeLastSeek = self.getGlobalPosition() self._protocol.sendState(self.getPlayerPosition(), self.getPlayerPaused(), seeked, None, True) + def prepareToChangeToNewPlaylistItemAndRewind(self): + self.ui.showDebugMessage("Preparing to change to new playlist index and rewind...") + self.fileOpenBeforeChangingPlaylistIndex = self.userlist.currentUser.file["path"] if self.userlist.currentUser.file else None + self.waitingToLoadNewfile = True + self.waitingToLoadNewfileSince = time.time() + def prepareToAdvancePlaylist(self): if self.playlist.canSwitchToNextPlaylistIndex(): self.ui.showDebugMessage("Preparing to advance playlist...") self.lastAdvanceTime = time.time() - self._protocol.sendState(0, True, True, None, True) + #self._protocol.sendState(0, True, True, None, True) else: self.ui.showDebugMessage("Not preparing to advance playlist because the next file cannot be switched to") @@ -986,6 +998,8 @@ class SyncplayClient(object): if self.seamlessMusicOveride(): self.setPaused(False) recentlyAdvanced = self._recentlyAdvanced() + print (self.userlist.areAllUsersInRoomReady(requireSameFilenames=self._config["autoplayRequireSameFilenames"]) + and ((self.autoPlayThreshold and self.userlist.usersInRoomCount() >= self.autoPlayThreshold) or recentlyAdvanced)) return ( self._playerPaused and (self.autoPlay or recentlyAdvanced) and self.userlist.currentUser.canControl() and self.userlist.isReadinessSupported() @@ -1838,7 +1852,7 @@ class SyncplayPlaylist(): if self._client.playerIsNotReady(): if not self.addedChangeListCallback: self.addedChangeListCallback = True - self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username)) + self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username, resetPosition)) return try: filename = self._playlist[index] @@ -1854,10 +1868,24 @@ class SyncplayPlaylist(): self._playlistIndex = index if username is None: if self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled(): - if resetPosition: - self._client.rewindFile() + '''if resetPosition: + self._client.rewindFile()''' self._client.setPlaylistIndex(index) + filename = self._playlist[index] + self._ui.setPlaylistIndexFilename(filename) + if resetPosition: + self._ui.showDebugMessage("Pausing due to index change") + state = {} + state["playstate"] = {} + state["playstate"]["position"] = 0 + state["playstate"]["paused"] = True + self._client.lastAdvanceTime = time.time() + self._client._protocol.sendMessage({"State": state}) + self._playerPaused = True + self._client.autoplayCheck() elif index is not None: + filename = self._playlist[index] + self._ui.setPlaylistIndexFilename(filename) self._ui.showMessage(getMessage("playlist-selection-changed-notification").format(username)) self.switchToNewPlaylistIndex(index, resetPosition=resetPosition) @@ -1883,7 +1911,12 @@ class SyncplayPlaylist(): self.queuedIndexFilename = self._playlist[index] except: self.queuedIndexFilename = None - self._ui.showDebugMessage("Failed to find index {} in plauylist".format(index)) + self._ui.showDebugMessage("Failed to find index {} in playlist".format(index)) + if resetPosition and index is not None: + filename = self._playlist[index] + if (not utils.isURL(filename)) or self._client.isURITrusted(filename): + self._client.prepareToChangeToNewPlaylistItemAndRewind() + self._lastPlaylistIndexChange = time.time() if self._client.playerIsNotReady(): self._client.addPlayerReadyCallback(lambda x: self.switchToNewPlaylistIndex(index, resetPosition)) @@ -1904,7 +1937,7 @@ class SyncplayPlaylist(): else: path = self._client.fileSwitch.findFilepath(filename, highPriority=True) if path: - self._client.openFile(path, resetPosition) + self._client.openFile(path, resetPosition=resetPosition) else: self._ui.showErrorMessage(getMessage("cannot-find-file-for-playlist-switch-error").format(filename)) return From 095cc4d834995873869bbd36c91ea80cb43100de Mon Sep 17 00:00:00 2001 From: Et0h Date: Fri, 21 Jun 2024 18:57:01 +0100 Subject: [PATCH 3/4] Remove stray print --- syncplay/client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index e16324d..33458b6 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -998,8 +998,6 @@ class SyncplayClient(object): if self.seamlessMusicOveride(): self.setPaused(False) recentlyAdvanced = self._recentlyAdvanced() - print (self.userlist.areAllUsersInRoomReady(requireSameFilenames=self._config["autoplayRequireSameFilenames"]) - and ((self.autoPlayThreshold and self.userlist.usersInRoomCount() >= self.autoPlayThreshold) or recentlyAdvanced)) return ( self._playerPaused and (self.autoPlay or recentlyAdvanced) and self.userlist.currentUser.canControl() and self.userlist.isReadinessSupported() From b7999e13ff0ce7b35ee639cba69b789835b1e888 Mon Sep 17 00:00:00 2001 From: Et0h Date: Mon, 1 Jul 2024 22:11:32 +0100 Subject: [PATCH 4/4] Fix mpv.net 'auto load folder' playlist advancement bug --- syncplay/constants.py | 1 + syncplay/players/mpvnet.py | 1 + 2 files changed, 2 insertions(+) diff --git a/syncplay/constants.py b/syncplay/constants.py index 0cc124b..b23ad31 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -269,6 +269,7 @@ MPV_ARGS = {'force-window': 'yes', 'term-playing-msg': '\nANS_filename=${filename}\nANS_length=${=duration:${=length:0}}\nANS_path=${path}\n', 'keep-open-pause': 'yes' } +MPV_NET_EXTRA_ARGS = { 'auto-load-folder': 'no' } IINA_PROPERTIES = {'geometry': '25%+100+100', 'idle': 'yes', diff --git a/syncplay/players/mpvnet.py b/syncplay/players/mpvnet.py index 1ee7796..64da5ed 100644 --- a/syncplay/players/mpvnet.py +++ b/syncplay/players/mpvnet.py @@ -8,6 +8,7 @@ class MpvnetPlayer(MpvPlayer): @staticmethod def run(client, playerPath, filePath, args): + args.extend(constants.MPV_NET_EXTRA_ARGS) constants.MPV_NEW_VERSION = True constants.MPV_OSC_VISIBILITY_CHANGE_VERSION = True return MpvnetPlayer(client, MpvnetPlayer.getExpandedPath(playerPath), filePath, args)