def addSong(self, newSong): if isinstance(newSong, Song) and not newSong.getId() in self.songs: #check if the file still exist if path.isfile(newSong.getPath()) and path.exists(newSong.getPath()): query = Db.select("songs", ["id"], {"path": newSong.getPath()}) if query and query.next(): songInList = False for song in self.songs: if song.getPath() == newSong.getPath(): songInList = True if not songInList: if not newSong.dirty: self.songs.append(newSong) else: loadedSong = Song(id=query.value(0).toInt()[0]) if not loadedSong.dirty: self.songs.append(loadedSong) else: newSong.saveSong() if not newSong.dirty: self.songs.append(newSong) else: #else, delete its record Db.delete("songs", {"id": newSong.getId()})
def removePlaylistAction(self): if self.playlist.currentRow() == 0: return self.mediaObject.stop() self.mediaObject.clearQueue() currentItem = self.playlist.currentItem() currentData = currentItem.data(Qt.UserRole).toInt()[0] Db.delete("playlists", {"id": currentData}) Db.delete("playlist_songs", {"playlist_id": currentData}) self.loadAllPlaylists() self.loadContextMenu()