diff --git a/syncplay/__init__.py b/syncplay/__init__.py index 02e8e74..2cf5466 100644 --- a/syncplay/__init__.py +++ b/syncplay/__init__.py @@ -1,4 +1,4 @@ -version = '1.5.0' +version = '1.5.1' milestone = 'Yoitsu' -release_number = '50' +release_number = '51' projectURL = 'http://syncplay.pl/' diff --git a/syncplay/client.py b/syncplay/client.py index fa73d9e..c4b3e8a 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -117,6 +117,9 @@ class SyncplayClient(object): self.autoPlay = False self.autoPlayThreshold = None + self.ignorePath = None + self.ignorePathTime = None + self.autoplayTimer = task.LoopingCall(self.autoplayCountdown) self.autoplayTimeLeft = constants.AUTOPLAY_DELAY @@ -445,6 +448,11 @@ class SyncplayClient(object): return self._globalPaused def updateFile(self, filename, duration, path): + if self.ignorePath == path and self.ignorePathTime is not None and abs(time.time() - self.ignorePathTime) < 5.0: + self.ignorePath = None + self.ignorePathTime = None + return + newPath = u"" if utils.isURL(path): try: @@ -461,6 +469,28 @@ class SyncplayClient(object): size = os.path.getsize(path) except: size = 0 + + def _fileOpenedFromPlayer(): + return self.sharedPlaylistIsEnabled and self._config['dropFileAddsToPlaylist'] and not utils.isURL(path) and filename <> self.playlist.lastFileOpened and not filename in self.playlist._playlist + + if _fileOpenedFromPlayer(): + oldFilePath = self.userlist.currentUser.file['path'] if self.userlist.currentUser.file else None + self.ignorePath = deepcopy(oldFilePath) + self.ignorePathTime = time.time() + if not self.playlist._playlist and self.userlist.currentUser.file: + if utils.isURL(oldFilePath): + self.playlist.addFileToPlaylist(oldFilePath) + else: + self.playlist.addFileToPlaylist(os.path.basename(oldFilePath)) + self.playlist.addFileToPlaylist(filename) + if self.userlist.currentUser.file: + self._player.openFile(oldFilePath) + return + else: + self.playlist.lastFileOpened = filename + + # TODO: Cancel if new same as old? + if not utils.isURL(path) and os.path.exists(path): self.fileSwitch.notifyUserIfFileNotInMediaDirectory(filename, path) filename, size = self.__executePrivacySettings(filename, size) @@ -502,7 +532,7 @@ class SyncplayClient(object): return False def openFile(self, filePath, resetPosition=False): - self.playlist.openedFile() + self.playlist.openedFile(filePath) self._player.openFile(filePath, resetPosition) if resetPosition: self.establishRewindDoubleCheck() @@ -1424,6 +1454,7 @@ class SyncplayPlaylist(): self._playlistIndex = None self.addedChangeListCallback = False self._lastPlaylistIndexChange = time.time() + self.lastFileOpened = os.path.basename(self._client._config['file']) if self._client._config['file'] and not utils.isURL(self._client._config['file']) else None def needsSharedPlaylistsEnabled(f): # @NoSelf @wraps(f) @@ -1434,8 +1465,12 @@ class SyncplayPlaylist(): return f(self, *args, **kwds) return wrapper - def openedFile(self): + def openedFile(self, filePath): self._lastPlaylistIndexChange = time.time() + if utils.isURL(filePath): + self.lastFileOpened = None + return + self.lastFileOpened = os.path.basename(filePath) def changeToPlaylistIndexFromFilename(self, filename): try: @@ -1602,6 +1637,15 @@ class SyncplayPlaylist(): self.changePlaylist(shuffledPlaylist, username=None, resetIndex=True) self.switchToNewPlaylistIndex(0, resetPosition=True) + @needsSharedPlaylistsEnabled + def addFileToPlaylist(self, filename): + if filename in self._playlist: + return + newPlaylist = deepcopy(self._playlist) + newPlaylist.append(filename) + if newPlaylist <> self._playlist: + self.changePlaylist(newPlaylist, username=None, resetIndex=False) + def canUndoPlaylist(self, currentPlaylist): return self._previousPlaylist is not None and currentPlaylist <> self._previousPlaylist diff --git a/syncplay/ui/ConfigurationGetter.py b/syncplay/ui/ConfigurationGetter.py index b23814f..230a805 100755 --- a/syncplay/ui/ConfigurationGetter.py +++ b/syncplay/ui/ConfigurationGetter.py @@ -64,6 +64,7 @@ class ConfigurationGetter(object): "showNonControllerOSD" : False, "showContactInfo" : True, "showDurationNotification" : True, + "dropFileAddsToPlaylist": False, "publicServers" : [] } @@ -106,6 +107,7 @@ class ConfigurationGetter(object): "sharedPlaylistEnabled", "loopAtEndOfPlaylist", "loopSingleFiles", + "dropFileAddsToPlaylist", "onlySwitchToTrustedDomains" ] self._tristate = [ @@ -140,6 +142,7 @@ class ConfigurationGetter(object): "autoplayInitialState", "mediaSearchDirectories", "sharedPlaylistEnabled", "loopAtEndOfPlaylist", "loopSingleFiles", + "dropFileAddsToPlaylist", "onlySwitchToTrustedDomains", "trustedDomains","publicServers"], "gui": ["showOSD", "showOSDWarnings", "showSlowdownOSD", "showDifferentRoomOSD", "showSameRoomOSD", diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 298d512..20efd71 100755 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -612,7 +612,7 @@ class MainWindow(QtWidgets.QMainWindow): if roomToJoin <> self._syncplayClient.getRoom(): menu.addAction(getMessage("joinroom-menu-label").format(roomToJoin), lambda: self.joinRoom(roomToJoin)) elif username and filename and filename <> getMessage("nofile-note"): - if self.config['sharedPlaylistEnabled'] and not self.isItemInPlaylist(filename): + if self._syncplayClient.sharedPlaylistIsEnabled() and not self.isItemInPlaylist(filename): if isURL(filename): menu.addAction(QtGui.QPixmap(resourcespath + u"world_add.png"),getMessage("addusersstreamstoplaylist-menu-label").format(shortUsername), lambda: self.addStreamToPlaylist(filename)) else: @@ -681,11 +681,11 @@ class MainWindow(QtWidgets.QMainWindow): if self._isTryingToChangeToCurrentFile(filename): return if isURL(filename): - self._syncplayClient._player.openFile(filename, resetPosition=True) + self._syncplayClient.openFile(filename, resetPosition=True) else: pathFound = self._syncplayClient.fileSwitch.findFilepath(filename, highPriority=True) if pathFound: - self._syncplayClient._player.openFile(pathFound, resetPosition=True) + self._syncplayClient.openFile(pathFound, resetPosition=True) else: self._syncplayClient.ui.showErrorMessage(getMessage("cannot-find-file-for-playlist-switch-error").format(filename)) @@ -708,11 +708,11 @@ class MainWindow(QtWidgets.QMainWindow): if self._isTryingToChangeToCurrentFile(filename): return if isURL(filename): - self._syncplayClient._player.openFile(filename) + self._syncplayClient.openFile(filename) else: pathFound = self._syncplayClient.fileSwitch.findFilepath(filename, highPriority=True) if pathFound: - self._syncplayClient._player.openFile(pathFound) + self._syncplayClient.openFile(pathFound) else: self._syncplayClient.fileSwitch.updateInfo() self.showErrorMessage(getMessage("switch-file-not-found-error").format(filename)) @@ -869,7 +869,7 @@ class MainWindow(QtWidgets.QMainWindow): self.mediadirectory = os.path.dirname(fileName) self._syncplayClient.fileSwitch.setCurrentDirectory(self.mediadirectory) self.saveMediaBrowseSettings() - self._syncplayClient._player.openFile(fileName) + self._syncplayClient.openFile(fileName) @needsClient def OpenAddFilesToPlaylistDialog(self): @@ -1051,7 +1051,7 @@ class MainWindow(QtWidgets.QMainWindow): getMessage("promptforstreamurlinfo-msgbox-label"), QtWidgets.QLineEdit.Normal, "") if ok and streamURL != '': - self._syncplayClient._player.openFile(streamURL) + self._syncplayClient.openFile(streamURL) @needsClient def createControlledRoom(self): @@ -1575,10 +1575,18 @@ class MainWindow(QtWidgets.QMainWindow): data = event.mimeData() urls = data.urls() if urls and urls[0].scheme() == 'file': + url = event.mimeData().urls()[0] if isMacOS() and IsPySide: dropfilepath = os.path.abspath(NSURL.URLWithString_(str(url.toString())).filePathURL().path()) else: dropfilepath = os.path.abspath(unicode(url.toLocalFile())) + if self.config['dropFileAddsToPlaylist'] and self._syncplayClient.sharedPlaylistIsEnabled(): + filename = dropfilepath if isURL(dropfilepath) else os.path.basename(dropfilepath) + if self.isItemInPlaylist(filename): + self._syncplayClient._player.openFile(dropfilepath) + else: + self.addFileToPlaylist(dropfilepath) + return if rewindFile == False: self._syncplayClient._player.openFile(dropfilepath) else: @@ -1626,7 +1634,7 @@ class MainWindow(QtWidgets.QMainWindow): self.playlist.insertItem(index, filePath) def openFile(self, filePath, resetPosition=False): - self._syncplayClient._player.openFile(filePath, resetPosition) + self._syncplayClient.openFile(filePath, resetPosition) def noPlaylistDuplicates(self, filename): if self.isItemInPlaylist(filename):