Console improvements (#327), including work from #316 and #319

* add videos to playlist from chat

* add urls to playlist

* add files in media directory to playlist

* add commands to show the playlist and select an index

* add command to delete files from the playlist

* show selected index in playlist

* fix adding files with queue command in GUI mode

* start indexing the playlist at 1

or at least that's what it would look like to the user

* start all commands related to playlist with `q`

Co-authored-by: kiscs <csandras05@gmail.com>
This commit is contained in:
Florian Badie 2020-09-13 17:45:38 +02:00 committed by GitHub
parent bf4bea65c3
commit b09fb90b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 6 deletions

View File

@ -1887,6 +1887,15 @@ class SyncplayPlaylist():
self._ui.setPlaylist(self._playlist) self._ui.setPlaylist(self._playlist)
self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(username)) 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 @needsSharedPlaylistsEnabled
def undoPlaylistChange(self): def undoPlaylistChange(self):
if self.canUndoPlaylist(self._playlist): if self.canUndoPlaylist(self._playlist):
@ -2005,7 +2014,7 @@ class FileSwitchManager(object):
self.mediaFilesCache = {} self.mediaFilesCache = {}
self.filenameWatchlist = [] self.filenameWatchlist = []
self.currentDirectory = None self.currentDirectory = None
self.mediaDirectories = None self.mediaDirectories = client.getConfig().get('mediaSearchDirectories')
self.lock = threading.Lock() self.lock = threading.Lock()
self.folderSearchEnabled = True self.folderSearchEnabled = True
self.directorySearchError = None self.directorySearchError = None

View File

@ -124,6 +124,10 @@ COMMANDS_HELP = ['help', 'h', '?', '/?', r'\?']
COMMANDS_CREATE = ['c', 'create'] COMMANDS_CREATE = ['c', 'create']
COMMANDS_AUTH = ['a', 'auth'] COMMANDS_AUTH = ['a', 'auth']
COMMANDS_TOGGLE = ['t', 'toggle'] 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_MIN_VER = "1.6.4"
MPC_BE_MIN_VER = "1.5.2.3123" MPC_BE_MIN_VER = "1.5.2.3123"
VLC_MIN_VERSION = "2.2.1" VLC_MIN_VERSION = "2.2.1"

View File

@ -87,6 +87,10 @@ en = {
"commandlist-notification/create": "\tc [name] - create managed room using name of current room", "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/auth": "\ta [password] - authenticate as room operator with operator password",
"commandlist-notification/chat": "\tch [message] - send a chat message in a room", "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 "syncplay-version-notification": "Syncplay version: {}", # syncplay.version
"more-info-notification": "More info available at: {}", # projectURL "more-info-notification": "More info available at: {}", # projectURL

View File

@ -3,12 +3,13 @@ import re
import sys import sys
import threading import threading
import time import time
import os
import syncplay import syncplay
from syncplay import constants from syncplay import constants
from syncplay import utils from syncplay import utils
from syncplay.messages import getMessage from syncplay.messages import getMessage
from syncplay.utils import formatTime from syncplay.utils import formatTime, isURL
class ConsoleUI(threading.Thread): class ConsoleUI(threading.Thread):
@ -22,8 +23,13 @@ class ConsoleUI(threading.Thread):
def addClient(self, client): def addClient(self, client):
self._syncplayClient = client self._syncplayClient = client
def addFileToPlaylist(self): def addFileToPlaylist(self, file):
pass 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): def drop(self):
pass pass
@ -184,6 +190,41 @@ class ConsoleUI(threading.Thread):
self._syncplayClient.identifyAsController(controlpassword) self._syncplayClient.identifyAsController(controlpassword)
elif command.group('command') in constants.COMMANDS_TOGGLE: elif command.group('command') in constants.COMMANDS_TOGGLE:
self._syncplayClient.toggleReady() 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: else:
if self._tryAdvancedCommands(data): if self._tryAdvancedCommands(data):
return return
@ -200,6 +241,10 @@ class ConsoleUI(threading.Thread):
self.showMessage(getMessage("commandlist-notification/create"), True) self.showMessage(getMessage("commandlist-notification/create"), True)
self.showMessage(getMessage("commandlist-notification/auth"), True) self.showMessage(getMessage("commandlist-notification/auth"), True)
self.showMessage(getMessage("commandlist-notification/chat"), 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("syncplay-version-notification").format(syncplay.version), True)
self.showMessage(getMessage("more-info-notification").format(syncplay.projectURL), True) self.showMessage(getMessage("more-info-notification").format(syncplay.projectURL), True)

View File

@ -1924,7 +1924,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.playlist.setPlaylistIndexFilename(filename) self.playlist.setPlaylistIndexFilename(filename)
def addFileToPlaylist(self, filePath, index=-1): def addFileToPlaylist(self, filePath, index=-1):
if os.path.isfile(filePath): if not isURL:
self.removePlaylistNote() self.removePlaylistNote()
filename = os.path.basename(filePath) filename = os.path.basename(filePath)
if self.noPlaylistDuplicates(filename): if self.noPlaylistDuplicates(filename):
@ -1933,7 +1933,7 @@ class MainWindow(QtWidgets.QMainWindow):
else: else:
self.playlist.insertItem(index, filename) self.playlist.insertItem(index, filename)
self._syncplayClient.fileSwitch.notifyUserIfFileNotInMediaDirectory(filename, filePath) self._syncplayClient.fileSwitch.notifyUserIfFileNotInMediaDirectory(filename, filePath)
elif isURL(filePath): else:
self.removePlaylistNote() self.removePlaylistNote()
if self.noPlaylistDuplicates(filePath): if self.noPlaylistDuplicates(filePath):
if self.playlist == -1 or index == -1: if self.playlist == -1 or index == -1: