mirror of
https://github.com/Syncplay/syncplay
synced 2025-02-14 09:57:12 +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):
|
||||
self._player.openFile(filePath, resetPosition)
|
||||
|
||||
def fileSwitchFoundFiles(self):
|
||||
self.ui.fileSwitchFoundFiles()
|
||||
self.playlist.loadCurrentPlaylistIndex()
|
||||
|
||||
def setPlaylistIndex(self, index):
|
||||
self._protocol.setPlaylistIndex(index)
|
||||
|
||||
@ -1257,6 +1261,9 @@ class UiManager(object):
|
||||
def setPlaylistIndexFilename(self, filename):
|
||||
self.__ui.setPlaylistIndexFilename(filename)
|
||||
|
||||
def fileSwitchFoundFiles(self):
|
||||
self.__ui.fileSwitchFoundFiles()
|
||||
|
||||
def showDebugMessage(self, message):
|
||||
if constants.DEBUG_MODE and 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))
|
||||
return
|
||||
else:
|
||||
path = self._client.fileSwitch.findFilepath(filename)
|
||||
path = self._client.fileSwitch.findFilepath(filename, highPriority=True)
|
||||
if path:
|
||||
self._client.openFile(path, resetPosition)
|
||||
else:
|
||||
@ -1533,7 +1540,6 @@ class SyncplayPlaylist():
|
||||
class FileSwitchManager(object):
|
||||
def __init__(self, client):
|
||||
self._client = client
|
||||
self.fileSwitchTimer = task.LoopingCall(self.updateInfo)
|
||||
self.mediaFilesCache = {}
|
||||
self.filenameWatchlist = []
|
||||
self.currentDirectory = None
|
||||
@ -1543,8 +1549,8 @@ class FileSwitchManager(object):
|
||||
self.disabledDir = None
|
||||
self.newInfo = False
|
||||
self.currentlyUpdating = False
|
||||
self.newInfo = False
|
||||
self.newWatchlist = []
|
||||
self.fileSwitchTimer = task.LoopingCall(self.updateInfo)
|
||||
self.fileSwitchTimer.start(constants.FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL, True)
|
||||
|
||||
def setClient(self, newClient):
|
||||
@ -1604,12 +1610,9 @@ class FileSwitchManager(object):
|
||||
|
||||
def infoUpdated(self):
|
||||
if self.areWatchedFilenamesInCache() or self.areWatchedFilenamesInCurrentDir():
|
||||
self.updateListOfWhoIsPlayingWhat()
|
||||
self._client.fileSwitchFoundFiles()
|
||||
|
||||
def updateListOfWhoIsPlayingWhat(self):
|
||||
self._client.showUserList()
|
||||
|
||||
def findFilepath(self, filename):
|
||||
def findFilepath(self, filename, highPriority=False):
|
||||
if filename is None:
|
||||
return
|
||||
|
||||
@ -1628,6 +1631,20 @@ class FileSwitchManager(object):
|
||||
if os.path.isfile(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):
|
||||
if self.filenameWatchlist is not None and self.currentDirectory is not None:
|
||||
for filename in self.filenameWatchlist:
|
||||
|
@ -83,6 +83,9 @@ class ConsoleUI(threading.Thread):
|
||||
def userListChange(self):
|
||||
pass
|
||||
|
||||
def fileSwitchFoundFiles(self):
|
||||
pass
|
||||
|
||||
def showMessage(self, message, noTimestamp=False):
|
||||
message = message.encode(sys.stdout.encoding, 'replace')
|
||||
if noTimestamp:
|
||||
|
@ -181,11 +181,12 @@ class MainWindow(QtGui.QMainWindow):
|
||||
itemFilename = self.item(item).text()
|
||||
isPlayingFilename = itemFilename == self.playlistIndexFilename
|
||||
self.item(item).setData(Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE, isPlayingFilename)
|
||||
fileSwitchState = self.selfWindow.getFileSwitchState(itemFilename)
|
||||
if fileSwitchState == constants.FILEITEM_SWITCH_NO_SWITCH and not isPlayingFilename:
|
||||
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
|
||||
else:
|
||||
fileIsAvailable = self.selfWindow.isFileAvailable(itemFilename)
|
||||
if fileIsAvailable:
|
||||
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()
|
||||
|
||||
def setWindow(self, window):
|
||||
@ -346,6 +347,20 @@ class MainWindow(QtGui.QMainWindow):
|
||||
self.newWatchlist.extend([filename])
|
||||
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
|
||||
def showUserList(self, currentUser, rooms):
|
||||
self._usertreebuffer = QtGui.QStandardItemModel()
|
||||
@ -571,7 +586,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
if isURL(filename):
|
||||
self._syncplayClient._player.openFile(filename)
|
||||
else:
|
||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename)
|
||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename, highPriority=True)
|
||||
if pathFound:
|
||||
self._syncplayClient._player.openFile(pathFound)
|
||||
else:
|
||||
@ -591,7 +606,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
if isURL(filename):
|
||||
self._syncplayClient._player.openFile(filename)
|
||||
else:
|
||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename)
|
||||
pathFound = self._syncplayClient.fileSwitch.findFilepath(filename, highPriority=True)
|
||||
if pathFound:
|
||||
self._syncplayClient._player.openFile(pathFound)
|
||||
else:
|
||||
@ -602,6 +617,10 @@ class MainWindow(QtGui.QMainWindow):
|
||||
def userListChange(self):
|
||||
self._syncplayClient.showUserList()
|
||||
|
||||
def fileSwitchFoundFiles(self):
|
||||
self._syncplayClient.showUserList()
|
||||
self.playlist.updatePlaylistIndexIcon()
|
||||
|
||||
def updateRoomName(self, room=""):
|
||||
self.roomInput.setText(room)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user