Load playlist from file (command line argument + drop) (#232)
This commit is contained in:
parent
4765fa452c
commit
51cc57ce03
@ -520,7 +520,11 @@ class SyncplayClient(object):
|
||||
return True
|
||||
return False
|
||||
|
||||
def openFile(self, filePath, resetPosition=False):
|
||||
def openFile(self, filePath, resetPosition=False, fromUser=False):
|
||||
if fromUser and filePath.endswith(".txt") or filePath.endswith(".m3u") or filePath.endswith(".m3u8"):
|
||||
self.playlist.loadPlaylistFromFile(filePath, resetPosition)
|
||||
return
|
||||
|
||||
self.playlist.openedFile()
|
||||
self._player.openFile(filePath, resetPosition)
|
||||
if resetPosition:
|
||||
@ -673,6 +677,9 @@ class SyncplayClient(object):
|
||||
readyState = self._config['readyAtStart'] if self.userlist.currentUser.isReady() is None else self.userlist.currentUser.isReady()
|
||||
self._protocol.setReady(readyState, manuallyInitiated=False)
|
||||
self.reIdentifyAsController()
|
||||
if self._config["loadPlaylistFromFile"]:
|
||||
self.playlist.loadPlaylistFromFile(self._config["loadPlaylistFromFile"])
|
||||
self._config["loadPlaylistFromFile"] = None
|
||||
|
||||
def getRoom(self):
|
||||
return self.userlist.currentUser.room
|
||||
@ -1708,6 +1715,15 @@ class SyncplayPlaylist():
|
||||
filename = _playlist[_index] if len(_playlist) > _index else None
|
||||
return filename
|
||||
|
||||
def loadPlaylistFromFile(self, path, shuffle=False):
|
||||
with open(path) as f:
|
||||
newPlaylist = f.read().splitlines()
|
||||
if shuffle:
|
||||
random.shuffle(newPlaylist)
|
||||
if newPlaylist:
|
||||
self.changePlaylist(newPlaylist, username=None, resetIndex=True)
|
||||
|
||||
|
||||
def changePlaylist(self, files, username=None, resetIndex=False):
|
||||
if self._playlist == files:
|
||||
if self._playlistIndex != 0 and resetIndex:
|
||||
|
||||
@ -173,6 +173,8 @@ de = {
|
||||
"version-argument": 'gibt die aktuelle Version aus',
|
||||
"version-message": "Du verwendest Syncplay v. {} ({})",
|
||||
|
||||
"load-playlist-from-file-argument": "loads playlist from text file (one entry per line)", # TODO: Translate
|
||||
|
||||
# Client labels
|
||||
"config-window-title": "Syncplay Konfiguration",
|
||||
|
||||
|
||||
@ -173,6 +173,8 @@ en = {
|
||||
"version-argument": 'prints your version',
|
||||
"version-message": "You're using Syncplay version {} ({})",
|
||||
|
||||
"load-playlist-from-file-argument": "loads playlist from text file (one entry per line)",
|
||||
|
||||
# Client labels
|
||||
"config-window-title": "Syncplay configuration",
|
||||
|
||||
|
||||
@ -173,6 +173,8 @@ es = {
|
||||
"version-argument": 'imprime tu versión',
|
||||
"version-message": "Estás usando la versión de Syncplay {} ({})",
|
||||
|
||||
"load-playlist-from-file-argument": "loads playlist from text file (one entry per line)", # TODO: Translate
|
||||
|
||||
# Client labels
|
||||
"config-window-title": "Configuración de Syncplay",
|
||||
|
||||
|
||||
@ -173,6 +173,8 @@ it = {
|
||||
"version-argument": 'mostra la tua versione',
|
||||
"version-message": "Stai usando la versione di Syncplay {} ({})",
|
||||
|
||||
"load-playlist-from-file-argument": "loads playlist from text file (one entry per line)", # TODO: Translate
|
||||
|
||||
# Client labels
|
||||
"config-window-title": "Configurazione di Syncplay",
|
||||
|
||||
|
||||
@ -174,6 +174,8 @@ ru = {
|
||||
"version-argument": 'выводит номер версии',
|
||||
"version-message": "Вы используете Syncplay версии {} ({})",
|
||||
|
||||
"load-playlist-from-file-argument": "loads playlist from text file (one entry per line)", # TODO: Translate
|
||||
|
||||
# Client labels
|
||||
"config-window-title": "Настройка Syncplay",
|
||||
|
||||
|
||||
@ -92,7 +92,8 @@ class ConfigurationGetter(object):
|
||||
"notificationTimeout": 3,
|
||||
"alertTimeout": 5,
|
||||
"chatTimeout": 7,
|
||||
"publicServers": []
|
||||
"publicServers": [],
|
||||
"loadPlaylistFromFile": None
|
||||
}
|
||||
|
||||
self._defaultConfig = self._config.copy()
|
||||
@ -307,6 +308,8 @@ class ConfigurationGetter(object):
|
||||
key = "noGui"
|
||||
if key == "clear_gui_data":
|
||||
key = "clearGUIData"
|
||||
if key == "load_playlist_from_file":
|
||||
key = "loadPlaylistFromFile"
|
||||
self._config[key] = val
|
||||
|
||||
def _splitPortAndHost(self, host):
|
||||
@ -495,6 +498,8 @@ class ConfigurationGetter(object):
|
||||
self._argparser.add_argument('file', metavar='file', type=str, nargs='?', help=getMessage("file-argument"))
|
||||
self._argparser.add_argument('--clear-gui-data', action='store_true', help=getMessage("clear-gui-data-argument"))
|
||||
self._argparser.add_argument('-v', '--version', action='store_true', help=getMessage("version-argument"))
|
||||
self._argparser.add_argument('--load-playlist-from-file', metavar="loadPlaylistFromFile", type=str, help=getMessage("load-playlist-from-file-argument"))
|
||||
|
||||
self._argparser.add_argument('_args', metavar='options', type=str, nargs='*', help=getMessage("args-argument"))
|
||||
args = self._argparser.parse_args()
|
||||
if args.version:
|
||||
|
||||
@ -692,9 +692,9 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(firstFile) if not isURL(firstFile) else None
|
||||
if self._syncplayClient.userlist.currentUser.file is None or firstFile != self._syncplayClient.userlist.currentUser.file["name"]:
|
||||
if isURL(firstFile):
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "world_go.png"), getMessage("openstreamurl-menu-label"), lambda: self.openFile(firstFile, resetPosition=True))
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "world_go.png"), getMessage("openstreamurl-menu-label"), lambda: self.openFile(firstFile, resetPosition=True, fromUser=True))
|
||||
elif pathFound:
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "film_go.png"), getMessage("openmedia-menu-label"), lambda: self.openFile(pathFound, resetPosition=True))
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "film_go.png"), getMessage("openmedia-menu-label"), lambda: self.openFile(pathFound, resetPosition=True, fromUser=True))
|
||||
if pathFound:
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "folder_film.png"),
|
||||
getMessage('open-containing-folder'),
|
||||
@ -753,11 +753,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
if self._syncplayClient.userlist.currentUser.file is None or filename != self._syncplayClient.userlist.currentUser.file["name"]:
|
||||
if isURL(filename):
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "world_go.png"), getMessage("openusersstream-menu-label").format(shortUsername), lambda: self.openFile(filename))
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "world_go.png"), getMessage("openusersstream-menu-label").format(shortUsername), lambda: self.openFile(filename, resetPosition=False, fromUser=True))
|
||||
else:
|
||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename)
|
||||
if pathFound:
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "film_go.png"), getMessage("openusersfile-menu-label").format(shortUsername), lambda: self.openFile(pathFound))
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "film_go.png"), getMessage("openusersfile-menu-label").format(shortUsername), lambda: self.openFile(pathFound, resetPosition=False, fromUser=True))
|
||||
if self._syncplayClient.isUntrustedTrustableURI(filename):
|
||||
domain = utils.getDomainFromURL(filename)
|
||||
menu.addAction(QtGui.QPixmap(resourcespath + "shield_add.png"), getMessage("addtrusteddomain-menu-label").format(domain), lambda: self.addTrustedDomain(domain))
|
||||
@ -814,11 +814,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))
|
||||
|
||||
@ -841,11 +841,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))
|
||||
@ -1006,7 +1006,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, resetPosition=False, fromUser=True)
|
||||
|
||||
@needsClient
|
||||
def OpenAddFilesToPlaylistDialog(self):
|
||||
@ -1186,7 +1186,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self, getMessage("promptforstreamurl-msgbox-label"),
|
||||
getMessage("promptforstreamurlinfo-msgbox-label"), QtWidgets.QLineEdit.Normal, "")
|
||||
if ok and streamURL != '':
|
||||
self._syncplayClient._player.openFile(streamURL)
|
||||
self._syncplayClient.openFile(streamURL, resetPosition=False, fromUser=True)
|
||||
|
||||
@needsClient
|
||||
def createControlledRoom(self):
|
||||
@ -1803,10 +1803,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
else:
|
||||
dropfilepath = os.path.abspath(str(url.toLocalFile()))
|
||||
if rewindFile == False:
|
||||
self._syncplayClient._player.openFile(dropfilepath)
|
||||
self._syncplayClient.openFile(dropfilepath, resetPosition=False, fromUser=True)
|
||||
else:
|
||||
self._syncplayClient.setPosition(0)
|
||||
self._syncplayClient._player.openFile(dropfilepath, resetPosition=True)
|
||||
self._syncplayClient.openFile(dropfilepath, resetPosition=True, fromUser=True)
|
||||
self._syncplayClient.setPosition(0)
|
||||
|
||||
def setPlaylist(self, newPlaylist, newIndexFilename=None):
|
||||
@ -1848,8 +1848,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
else:
|
||||
self.playlist.insertItem(index, filePath)
|
||||
|
||||
def openFile(self, filePath, resetPosition=False):
|
||||
self._syncplayClient._player.openFile(filePath, resetPosition)
|
||||
def openFile(self, filePath, resetPosition=False, fromUser=False):
|
||||
self._syncplayClient.openFile(filePath, resetPosition, fromUser=fromUser)
|
||||
|
||||
def noPlaylistDuplicates(self, filename):
|
||||
if self.isItemInPlaylist(filename):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user