Exemple #1
0
 def deleteSong(self):
     to_delete = self.musicTable.selectedItems()
     songs_to_delete = []
     for i in to_delete:
         song_id = i.data(Qt.UserRole).toInt()[0]
         if not song_id == 0:
             songs_to_delete.append(song_id)
             
     if len(songs_to_delete) > 0:
         for song_id in songs_to_delete:
             Db.execute("DELETE FROM songs WHERE id = %d" % (song_id))
             Db.execute("DELETE FROM playlist_songs WHERE song_id = %d" % (song_id))
         self.sources.clear()
         self.clearMusicTable()
         self.loadAllSongs()
Exemple #2
0
 def __getSongAlbum(self, artist_id):
     
     if not self.__album == None:
         query = Db.select("albums", ["id"], {"name": self.__album, "artist_id": artist_id})
         if query and query.size() > 0 and query.next():
             return query.value(0).toInt()[0]
         else:
             return Db.insert("albums", {"name": self.__album, "artist_id": artist_id})
     else:
         query = Db.execute("SELECT a.id FROM albums as a, songs as s WHERE s.album_id = a.id AND s.id = %d" % (self.__id))
         if query and query.next():
             return query.value(0).toInt()[0]
Exemple #3
0
 def __getSongGenre(self):
     
     if not self.__genre == None:
         query = Db.select("genres", ["id"], {"name": self.__genre})
         if query and query.size() > 0 and query.next():
             return query.value(0).toInt()[0]
         else:
             return Db.insert("genres", {"name": self.__genre})
     else:
         query = Db.execute("SELECT g.id FROM genres as g, songs as s WHERE s.genre_id = g.id AND s.id = %d" % (self.__id))
         if query and query.next():
             return query.value(0).toInt()[0]
Exemple #4
0
    def addPlaylistAction(self):
        playlistName, response = QInputDialog.getText(self, 'Pysawndz', 'Playlist name:')

        if response:
            sql = "SELECT * FROM playlists WHERE name = '%s'" % (playlistName)
            query = Db.execute(sql)
            if query.size() == 0:
                Db.insert("playlists", {"name": playlistName})
                self.loadAllPlaylists()
                self.playlist.setCurrentRow(self.playlist.count() - 1)
                self.loadContextMenu()
            else:
                QMessageBox.warning(self, "Pysawndz", "Another playlist with the same name already exist.", QMessageBox.Ok);
Exemple #5
0
 def addToPlaylistAction(self):
     action = self.sender()
     playlist_id = action.data().toInt()[0]
     
     to_add = self.musicTable.selectedItems()
     songs_to_add = []
     for i in to_add:
         song_id = i.data(Qt.UserRole).toInt()[0]
         if not song_id == 0:
             songs_to_add.append(song_id)
             
     if len(songs_to_add) > 0:
         for song_id in songs_to_add:
             sql = "SELECT * FROM playlist_songs WHERE song_id = %d AND playlist_id = %d" % (song_id, playlist_id)
             query = Db.execute(sql)
             if query.size() == 0:
                 Db.insert("playlist_songs", {"playlist_id": playlist_id, "song_id": song_id})
         self.playlist.setCurrentRow(self.getRowByData(playlist_id))
Exemple #6
0
 def loadAllSongs(self):
     sql = "SELECT s.id, s.title, s.path, s.duration, a.name as artist, al.name as album, g.name as genre FROM songs as s \
             INNER JOIN artists as a ON a.id = s.artist_id \
             INNER JOIN albums as al ON al.id = s.album_id \
             INNER JOIN genres as g ON g.id = s.genre_id ORDER BY s.title ASC"
     query = Db.execute(sql)
     if query:
         while query.next():
             
             song = Song(id=query.value(0).toInt()[0],
                         title=query.value(1).toString(),
                         path=query.value(2).toString(),
                         duration=query.value(3).toInt()[0],
                         artist=query.value(4).toString(),
                         album=query.value(5).toString(),
                         genre=query.value(6).toString())
             
             self.sources.addSong(song)
         self.displayAllSongs()
Exemple #7
0
 def restorePlaylist(self):
     filename = QFileDialog.getOpenFileName(self,
         "Select playlist to restore",
         QDesktopServices.storageLocation(QDesktopServices.DesktopLocation),
         "*.songs")
     handle = open(filename, "rb")
     self.sources = pickle.load(handle)
     
     playlistName = self.phelper.getFileName(filename)
     sql = "SELECT * FROM playlists WHERE name = '%s'" % (playlistName)
     query = Db.execute(sql)
     if query.size() == 0:
         Db.insert("playlists", {"name": playlistName})
         
         #TODO: I forgot :)
         
         self.loadAllPlaylists()
         self.playlist.setCurrentRow(self.playlist.count() - 1)
         self.loadContextMenu()
     else:
         QMessageBox.warning(self, "Pysawndz", "Another playlist with the same name already exist.", QMessageBox.Ok);
Exemple #8
0
 def playListChanged(self, row):
     
     currentRow = self.playlist.item(row)
     
     if not row == 0 and not currentRow == None: 
         
         currentPlaylist = currentRow.data(Qt.UserRole).toInt()[0]
         
         sql = "SELECT s.id, s.title, s.path, s.duration, a.name as artist, al.name as album, g.name as genre FROM songs as s \
                 INNER JOIN artists as a ON a.id = s.artist_id \
                 INNER JOIN albums as al ON al.id = s.album_id \
                 INNER JOIN genres as g ON g.id = s.genre_id \
                 INNER JOIN playlist_songs as ps ON ps.song_id = s.id \
                 WHERE ps.playlist_id = %d \
                 ORDER BY s.title ASC" % (currentPlaylist)
         
         query = Db.execute(sql)
         if query and query.size() > 0:
             self.sources.clear()
             while query.next():
                 #song_id = query.value(0).toInt()[0]
                 song = Song(id=query.value(0).toInt()[0],
                         title=query.value(1).toString(),
                         path=query.value(2).toString(),
                         duration=query.value(3).toInt()[0],
                         artist=query.value(4).toString(),
                         album=query.value(5).toString(),
                         genre=query.value(6).toString())
             
                 self.sources.addSong(song)
             self.clearMusicTable()
             self.displayAllSongs()
         else:
             self.clearMusicTable()
             
     else:
         #all songs
         self.loadAllSongs()
         self.displayAllSongs()