| 1788 | |
| 1789 | |
| 1790 | class SyncplayPlaylist(): |
| 1791 | def __init__(self, client): |
| 1792 | self.queuedIndex = None |
| 1793 | self._client = client |
| 1794 | self._ui = self._client.ui |
| 1795 | self._previousPlaylist = None |
| 1796 | self._previousPlaylistRoom = None |
| 1797 | self._playlist = [] |
| 1798 | self._playlistIndex = None |
| 1799 | self.addedChangeListCallback = False |
| 1800 | self.switchToNewPlaylistItem = False |
| 1801 | self._lastPlaylistIndexChange = time.time() |
| 1802 | |
| 1803 | def needsSharedPlaylistsEnabled(f): # @NoSelf |
| 1804 | @wraps(f) |
| 1805 | def wrapper(self, *args, **kwds): |
| 1806 | if not self._client.sharedPlaylistIsEnabled(): |
| 1807 | self._ui.showDebugMessage("Tried to use shared playlists when it was disabled!") |
| 1808 | return |
| 1809 | return f(self, *args, **kwds) |
| 1810 | return wrapper |
| 1811 | |
| 1812 | def openedFile(self): |
| 1813 | self._lastPlaylistIndexChange = time.time() |
| 1814 | |
| 1815 | def removeDirsFromPath(self, filePath): |
| 1816 | if os.path.isfile(filePath): |
| 1817 | return os.path.basename(filePath) |
| 1818 | elif utils.isURL(filePath): |
| 1819 | return filePath |
| 1820 | self._ui.showDebugMessage("Could not find path: {}".format(filePath)) |
| 1821 | |
| 1822 | def getPlaylistIndexFromPath(self, filePath): |
| 1823 | filePath = self.removeDirsFromPath(filePath) |
| 1824 | try: |
| 1825 | return self._playlist.index(filePath) |
| 1826 | except ValueError: |
| 1827 | return |
| 1828 | |
| 1829 | def changeToPlaylistIndexFromFilename(self, filename): |
| 1830 | try: |
| 1831 | index = self._playlist.index(filename) |
| 1832 | if index != self._playlistIndex: |
| 1833 | self.changeToPlaylistIndex(index, resetPosition=True) |
| 1834 | else: |
| 1835 | if filename == self.queuedIndexFilename: |
| 1836 | return |
| 1837 | self._client.rewindFile() |
| 1838 | except ValueError: |
| 1839 | pass |
| 1840 | |
| 1841 | def loadDelayedPath(self, changeToIndex): |
| 1842 | # Implementing the behaviour set out at https://github.com/Syncplay/syncplay/issues/315 |
| 1843 | |
| 1844 | if not self._client: |
| 1845 | return |
| 1846 | |
| 1847 | if self._client.playerIsNotReady(): |