diff --git a/syncplay/client.py b/syncplay/client.py index 6a2a5ae..f596ad5 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -1887,6 +1887,15 @@ class SyncplayPlaylist(): self._ui.setPlaylist(self._playlist) self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(username)) + def addToPlaylist(self, file): + self.changePlaylist([*self._playlist, file]) + + def deleteAtIndex(self, index): + new_playlist = self._playlist.copy() + if index < len(new_playlist): + del new_playlist[index] + self.changePlaylist(new_playlist) + @needsSharedPlaylistsEnabled def undoPlaylistChange(self): if self.canUndoPlaylist(self._playlist): @@ -2005,7 +2014,7 @@ class FileSwitchManager(object): self.mediaFilesCache = {} self.filenameWatchlist = [] self.currentDirectory = None - self.mediaDirectories = None + self.mediaDirectories = client.getConfig().get('mediaSearchDirectories') self.lock = threading.Lock() self.folderSearchEnabled = True self.directorySearchError = None diff --git a/syncplay/constants.py b/syncplay/constants.py index bb35d9e..f3b9a0d 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -124,6 +124,10 @@ COMMANDS_HELP = ['help', 'h', '?', '/?', r'\?'] COMMANDS_CREATE = ['c', 'create'] COMMANDS_AUTH = ['a', 'auth'] COMMANDS_TOGGLE = ['t', 'toggle'] +COMMANDS_QUEUE = ['queue', 'qa', 'add'] +COMMANDS_PLAYLIST = ['playlist', 'ql', 'pl'] +COMMANDS_SELECT = ['select', 'qs'] +COMMANDS_DELETE = ['delete', 'd', 'qd'] MPC_MIN_VER = "1.6.4" MPC_BE_MIN_VER = "1.5.2.3123" VLC_MIN_VERSION = "2.2.1" diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index aed1a40..ed61b42 100755 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -87,6 +87,10 @@ en = { "commandlist-notification/create": "\tc [name] - create managed room using name of current room", "commandlist-notification/auth": "\ta [password] - authenticate as room operator with operator password", "commandlist-notification/chat": "\tch [message] - send a chat message in a room", + "commandList-notification/queue": "\tqa [file/url] - add file or url to bottom of playlist", + "commandList-notification/playlist": "\tql - show the current playlist", + "commandList-notification/select": "\tqs [index] - select given entry in the playlist", + "commandList-notification/delete": "\tqd [index] - delete the given entry from the playlist", "syncplay-version-notification": "Syncplay version: {}", # syncplay.version "more-info-notification": "More info available at: {}", # projectURL diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index a7d2a4c..f0c463a 100755 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -3,12 +3,13 @@ import re import sys import threading import time +import os import syncplay from syncplay import constants from syncplay import utils from syncplay.messages import getMessage -from syncplay.utils import formatTime +from syncplay.utils import formatTime, isURL class ConsoleUI(threading.Thread): @@ -22,8 +23,13 @@ class ConsoleUI(threading.Thread): def addClient(self, client): self._syncplayClient = client - def addFileToPlaylist(self): - pass + def addFileToPlaylist(self, file): + if not isURL(file): + if not self._syncplayClient.fileSwitch.findFilepath(file): + print(f"{file} is not in any media directory") + return + + self._syncplayClient.playlist.addToPlaylist(file) def drop(self): pass @@ -184,6 +190,41 @@ class ConsoleUI(threading.Thread): self._syncplayClient.identifyAsController(controlpassword) elif command.group('command') in constants.COMMANDS_TOGGLE: self._syncplayClient.toggleReady() + elif command.group('command') in constants.COMMANDS_QUEUE: + filename = command.group('parameter') + if filename is None: + self.showErrorMessage("No file/url given") + return + + self._syncplayClient.ui.addFileToPlaylist(filename) + elif command.group('command') in constants.COMMANDS_PLAYLIST: + playlist = self._syncplayClient.playlist + playlist_elements = [f"\t{i+1}: {el}" for i, el in enumerate(playlist._playlist)] + + if playlist_elements: + i = playlist._playlistIndex + if i is not None and i in range(len(playlist_elements)): + playlist_elements[i] = " *" + playlist_elements[i] + + print(*playlist_elements, sep='\n') + else: + print("playlist is currently empty.") + elif command.group('command') in constants.COMMANDS_SELECT: + try: + index = int(command.group('parameter').strip()) - 1 + self._syncplayClient.playlist.changeToPlaylistIndex(index, resetPosition=True) + self._syncplayClient.rewindFile() + + except TypeError: + print("invalid index") + elif command.group('command') in constants.COMMANDS_DELETE: + try: + index = int(command.group('parameter').strip()) - 1 + self._syncplayClient.playlist.deleteAtIndex(index) + + except TypeError: + print("invalid index") + else: if self._tryAdvancedCommands(data): return @@ -200,6 +241,10 @@ class ConsoleUI(threading.Thread): self.showMessage(getMessage("commandlist-notification/create"), True) self.showMessage(getMessage("commandlist-notification/auth"), True) self.showMessage(getMessage("commandlist-notification/chat"), True) + self.showMessage(getMessage("commandList-notification/queue"), True) + self.showMessage(getMessage("commandList-notification/playlist"), True) + self.showMessage(getMessage("commandList-notification/select"), True) + self.showMessage(getMessage("commandList-notification/delete"), True) self.showMessage(getMessage("syncplay-version-notification").format(syncplay.version), True) self.showMessage(getMessage("more-info-notification").format(syncplay.projectURL), True) diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index ec3d30a..c2add97 100755 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -1924,7 +1924,7 @@ class MainWindow(QtWidgets.QMainWindow): self.playlist.setPlaylistIndexFilename(filename) def addFileToPlaylist(self, filePath, index=-1): - if os.path.isfile(filePath): + if not isURL: self.removePlaylistNote() filename = os.path.basename(filePath) if self.noPlaylistDuplicates(filename): @@ -1933,7 +1933,7 @@ class MainWindow(QtWidgets.QMainWindow): else: self.playlist.insertItem(index, filename) self._syncplayClient.fileSwitch.notifyUserIfFileNotInMediaDirectory(filename, filePath) - elif isURL(filePath): + else: self.removePlaylistNote() if self.noPlaylistDuplicates(filePath): if self.playlist == -1 or index == -1: