From b7fff7e32ca36447f279a7f7ed9daba458926fdf Mon Sep 17 00:00:00 2001 From: Et0h Date: Sat, 23 Jan 2016 16:28:54 +0000 Subject: [PATCH] Always loop at tne of playlist + At EOF go to next playlist index, not next filename --- syncplay/client.py | 59 ++++++++++++++++++++++++++++--------------- syncplay/constants.py | 1 + 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index d5beae4..2154c57 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -181,26 +181,43 @@ class SyncplayClient(object): @needsSharedPlaylistsEnabled def loadNextFileInPlaylist(self): - if self._playlistIndex is None or len(self._playlist) <= self._playlistIndex+1: - return - filename = self._playlist[self._playlistIndex+1] - if filename == "": - filename = self._playlist[0] - if utils.isURL(filename): - for URI in constants.SAFE_URIS: - if filename.startswith(URI): - self._player.openFile(filename, resetPosition=True) - return - self.ui.showErrorMessage(getMessage("cannot-add-unsafe-path-error").format(filename)) + if self._notPlayingCurrentIndex(): return + if self._thereIsNextPlaylistIndex(): + self.switchToNewPlaylistIndex(self._nextPlaylistIndex(), resetPosition=True) else: - path = self.findFilenameInDirectories(filename) - if path: - self._player.openFile(path, resetPosition=True) - else: - self.ui.showErrorMessage(getMessage("cannot-find-file-for-playlist-switch-error").format(filename)) - return - # TODO: Find Path properly + self.rewindFile() + + def _notPlayingCurrentIndex(self): + if self._playlistIndex is None or self._playlist is None or len(self._playlist) <= self._playlistIndex: + self.ui.showDebugMessage(u"Not playing current index - Index none or length issue") + return True + currentPlaylistFilename = self._playlist[self._playlistIndex] + if self.userlist.currentUser.file and currentPlaylistFilename == self.userlist.currentUser.file['name']: + return False + else: + self.ui.showDebugMessage(u"Not playing current index - Filename mismatch or no file") + return True + + def _thereIsNextPlaylistIndex(self): + if self._playlistIndex is None: + return False + elif len(self._playlist) == 1: + return False + else: + return True + + def _nextPlaylistIndex(self): + if self.playlistIsAtEnd(): + return 0 + else: + return self._playlistIndex+1 + + def playlistIsAtEnd(self): + return len(self._playlist) <= self._playlistIndex+1 + + def rewindFile(self): + self.setPosition(0) def updatePlayerStatus(self, paused, position): position -= self.getUserOffset() @@ -503,13 +520,13 @@ class SyncplayClient(object): @needsSharedPlaylistsEnabled - def switchToNewPlaylistIndex(self, index): + def switchToNewPlaylistIndex(self, index, resetPosition=False): try: filename = self._playlist[index] if utils.isURL(filename): for URI in constants.SAFE_URIS: if filename.startswith(URI): - self._player.openFile(filename) + self._player.openFile(filename, resetPosition=resetPosition) return self.ui.showErrorMessage(getMessage("cannot-add-unsafe-path-error").format(filename)) return @@ -517,7 +534,7 @@ class SyncplayClient(object): path = self.findFilenameInDirectories(filename) # TODO: Find Path properly if path: - self._player.openFile(path) + self._player.openFile(path, resetPosition) else: self.ui.showErrorMessage(getMessage("cannot-find-file-for-playlist-switch-error").format(filename)) return diff --git a/syncplay/constants.py b/syncplay/constants.py index 869d9c9..790ab6c 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -19,6 +19,7 @@ FALLBACK_INITIAL_LANGUAGE = "en" FALLBACK_PUBLIC_SYNCPLAY_SERVERS = [[u'syncplay.pl:8995 (France)', u'syncplay.pl:8995'],[u'syncplay.pl:8996 (France)', u'syncplay.pl:8996'],[u'syncplay.pl:8997 (France)', u'syncplay.pl:8997'],[u'syncplay.pl:8998 (France)', u'syncplay.pl:8998'],[u'syncplay.pl:8999 (France)', u'syncplay.pl:8999']] PLAYLIST_LOAD_NEXT_FILE_MINIMUM_LENGTH = 10 # Seconds PLAYLIST_LOAD_NEXT_FILE_TIME_FROM_END_THRESHOLD = 5 # Seconds (only triggered if file is paused, e.g. due to EOF) +PLAYLIST_LOOPS = True #Overriden by config SHOW_OSD = True # Sends Syncplay messages to media player OSD