mirror of
https://github.com/Syncplay/syncplay
synced 2025-02-19 12:36:51 +00:00
When watched file is found, update playlist and load file
This commit is contained in:
parent
b98ba59886
commit
0888ead8e6
@ -466,6 +466,10 @@ class SyncplayClient(object):
|
|||||||
def openFile(self, filePath, resetPosition=False):
|
def openFile(self, filePath, resetPosition=False):
|
||||||
self._player.openFile(filePath, resetPosition)
|
self._player.openFile(filePath, resetPosition)
|
||||||
|
|
||||||
|
def fileSwitchFoundFiles(self):
|
||||||
|
self.ui.fileSwitchFoundFiles()
|
||||||
|
self.playlist.loadCurrentPlaylistIndex()
|
||||||
|
|
||||||
def setPlaylistIndex(self, index):
|
def setPlaylistIndex(self, index):
|
||||||
self._protocol.setPlaylistIndex(index)
|
self._protocol.setPlaylistIndex(index)
|
||||||
|
|
||||||
@ -1257,6 +1261,9 @@ class UiManager(object):
|
|||||||
def setPlaylistIndexFilename(self, filename):
|
def setPlaylistIndexFilename(self, filename):
|
||||||
self.__ui.setPlaylistIndexFilename(filename)
|
self.__ui.setPlaylistIndexFilename(filename)
|
||||||
|
|
||||||
|
def fileSwitchFoundFiles(self):
|
||||||
|
self.__ui.fileSwitchFoundFiles()
|
||||||
|
|
||||||
def showDebugMessage(self, message):
|
def showDebugMessage(self, message):
|
||||||
if constants.DEBUG_MODE and message.rstrip():
|
if constants.DEBUG_MODE and message.rstrip():
|
||||||
sys.stderr.write("{}{}\n".format(time.strftime(constants.UI_TIME_FORMAT, time.localtime()),message.rstrip()))
|
sys.stderr.write("{}{}\n".format(time.strftime(constants.UI_TIME_FORMAT, time.localtime()),message.rstrip()))
|
||||||
@ -1390,7 +1397,7 @@ class SyncplayPlaylist():
|
|||||||
self._ui.showErrorMessage(getMessage("cannot-add-unsafe-path-error").format(filename))
|
self._ui.showErrorMessage(getMessage("cannot-add-unsafe-path-error").format(filename))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
path = self._client.fileSwitch.findFilepath(filename)
|
path = self._client.fileSwitch.findFilepath(filename, highPriority=True)
|
||||||
if path:
|
if path:
|
||||||
self._client.openFile(path, resetPosition)
|
self._client.openFile(path, resetPosition)
|
||||||
else:
|
else:
|
||||||
@ -1533,7 +1540,6 @@ class SyncplayPlaylist():
|
|||||||
class FileSwitchManager(object):
|
class FileSwitchManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self._client = client
|
self._client = client
|
||||||
self.fileSwitchTimer = task.LoopingCall(self.updateInfo)
|
|
||||||
self.mediaFilesCache = {}
|
self.mediaFilesCache = {}
|
||||||
self.filenameWatchlist = []
|
self.filenameWatchlist = []
|
||||||
self.currentDirectory = None
|
self.currentDirectory = None
|
||||||
@ -1543,8 +1549,8 @@ class FileSwitchManager(object):
|
|||||||
self.disabledDir = None
|
self.disabledDir = None
|
||||||
self.newInfo = False
|
self.newInfo = False
|
||||||
self.currentlyUpdating = False
|
self.currentlyUpdating = False
|
||||||
self.newInfo = False
|
|
||||||
self.newWatchlist = []
|
self.newWatchlist = []
|
||||||
|
self.fileSwitchTimer = task.LoopingCall(self.updateInfo)
|
||||||
self.fileSwitchTimer.start(constants.FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL, True)
|
self.fileSwitchTimer.start(constants.FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL, True)
|
||||||
|
|
||||||
def setClient(self, newClient):
|
def setClient(self, newClient):
|
||||||
@ -1604,12 +1610,9 @@ class FileSwitchManager(object):
|
|||||||
|
|
||||||
def infoUpdated(self):
|
def infoUpdated(self):
|
||||||
if self.areWatchedFilenamesInCache() or self.areWatchedFilenamesInCurrentDir():
|
if self.areWatchedFilenamesInCache() or self.areWatchedFilenamesInCurrentDir():
|
||||||
self.updateListOfWhoIsPlayingWhat()
|
self._client.fileSwitchFoundFiles()
|
||||||
|
|
||||||
def updateListOfWhoIsPlayingWhat(self):
|
def findFilepath(self, filename, highPriority=False):
|
||||||
self._client.showUserList()
|
|
||||||
|
|
||||||
def findFilepath(self, filename):
|
|
||||||
if filename is None:
|
if filename is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1628,6 +1631,20 @@ class FileSwitchManager(object):
|
|||||||
if os.path.isfile(filepath):
|
if os.path.isfile(filepath):
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
if highPriority and self.folderSearchEnabled:
|
||||||
|
directoryList = self.mediaDirectories
|
||||||
|
startTime = time.time()
|
||||||
|
if filename and directoryList:
|
||||||
|
for directory in directoryList:
|
||||||
|
for root, dirs, files in os.walk(directory):
|
||||||
|
if filename in files:
|
||||||
|
return os.path.join(root,filename)
|
||||||
|
if time.time() - startTime > constants.FOLDER_SEARCH_TIMEOUT:
|
||||||
|
self.disabledDir = directory
|
||||||
|
self.folderSearchEnabled = False
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
def areWatchedFilenamesInCurrentDir(self):
|
def areWatchedFilenamesInCurrentDir(self):
|
||||||
if self.filenameWatchlist is not None and self.currentDirectory is not None:
|
if self.filenameWatchlist is not None and self.currentDirectory is not None:
|
||||||
for filename in self.filenameWatchlist:
|
for filename in self.filenameWatchlist:
|
||||||
|
@ -83,6 +83,9 @@ class ConsoleUI(threading.Thread):
|
|||||||
def userListChange(self):
|
def userListChange(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def fileSwitchFoundFiles(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def showMessage(self, message, noTimestamp=False):
|
def showMessage(self, message, noTimestamp=False):
|
||||||
message = message.encode(sys.stdout.encoding, 'replace')
|
message = message.encode(sys.stdout.encoding, 'replace')
|
||||||
if noTimestamp:
|
if noTimestamp:
|
||||||
|
@ -181,11 +181,12 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
itemFilename = self.item(item).text()
|
itemFilename = self.item(item).text()
|
||||||
isPlayingFilename = itemFilename == self.playlistIndexFilename
|
isPlayingFilename = itemFilename == self.playlistIndexFilename
|
||||||
self.item(item).setData(Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE, isPlayingFilename)
|
self.item(item).setData(Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE, isPlayingFilename)
|
||||||
fileSwitchState = self.selfWindow.getFileSwitchState(itemFilename)
|
fileIsAvailable = self.selfWindow.isFileAvailable(itemFilename)
|
||||||
if fileSwitchState == constants.FILEITEM_SWITCH_NO_SWITCH and not isPlayingFilename:
|
if fileIsAvailable:
|
||||||
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
|
|
||||||
else:
|
|
||||||
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(QtGui.QPalette.ColorRole(QtGui.QPalette.Text))))
|
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(QtGui.QPalette.ColorRole(QtGui.QPalette.Text))))
|
||||||
|
else:
|
||||||
|
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
|
||||||
|
self.selfWindow._syncplayClient.fileSwitch.setFilenameWatchlist(self.selfWindow.newWatchlist)
|
||||||
self.forceUpdate()
|
self.forceUpdate()
|
||||||
|
|
||||||
def setWindow(self, window):
|
def setWindow(self, window):
|
||||||
@ -346,6 +347,20 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.newWatchlist.extend([filename])
|
self.newWatchlist.extend([filename])
|
||||||
return constants.FILEITEM_SWITCH_NO_SWITCH
|
return constants.FILEITEM_SWITCH_NO_SWITCH
|
||||||
|
|
||||||
|
@needsClient
|
||||||
|
def isFileAvailable(self, filename):
|
||||||
|
if filename:
|
||||||
|
if filename == getMessage("nofile-note"):
|
||||||
|
return None
|
||||||
|
if isURL(filename):
|
||||||
|
return True
|
||||||
|
elif filename not in self.newWatchlist:
|
||||||
|
if self._syncplayClient.fileSwitch.findFilepath(filename):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.newWatchlist.extend([filename])
|
||||||
|
return False
|
||||||
|
|
||||||
@needsClient
|
@needsClient
|
||||||
def showUserList(self, currentUser, rooms):
|
def showUserList(self, currentUser, rooms):
|
||||||
self._usertreebuffer = QtGui.QStandardItemModel()
|
self._usertreebuffer = QtGui.QStandardItemModel()
|
||||||
@ -571,7 +586,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
if isURL(filename):
|
if isURL(filename):
|
||||||
self._syncplayClient._player.openFile(filename)
|
self._syncplayClient._player.openFile(filename)
|
||||||
else:
|
else:
|
||||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename)
|
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename, highPriority=True)
|
||||||
if pathFound:
|
if pathFound:
|
||||||
self._syncplayClient._player.openFile(pathFound)
|
self._syncplayClient._player.openFile(pathFound)
|
||||||
else:
|
else:
|
||||||
@ -591,7 +606,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
if isURL(filename):
|
if isURL(filename):
|
||||||
self._syncplayClient._player.openFile(filename)
|
self._syncplayClient._player.openFile(filename)
|
||||||
else:
|
else:
|
||||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename)
|
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename, highPriority=True)
|
||||||
if pathFound:
|
if pathFound:
|
||||||
self._syncplayClient._player.openFile(pathFound)
|
self._syncplayClient._player.openFile(pathFound)
|
||||||
else:
|
else:
|
||||||
@ -602,6 +617,10 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
def userListChange(self):
|
def userListChange(self):
|
||||||
self._syncplayClient.showUserList()
|
self._syncplayClient.showUserList()
|
||||||
|
|
||||||
|
def fileSwitchFoundFiles(self):
|
||||||
|
self._syncplayClient.showUserList()
|
||||||
|
self.playlist.updatePlaylistIndexIcon()
|
||||||
|
|
||||||
def updateRoomName(self, room=""):
|
def updateRoomName(self, room=""):
|
||||||
self.roomInput.setText(room)
|
self.roomInput.setText(room)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user