From 88047542b35b7fb3bfc39dae7c6d01e85aed45c3 Mon Sep 17 00:00:00 2001 From: Leonardo Cervo Date: Tue, 24 Mar 2015 18:25:41 -0300 Subject: [PATCH] Random fixes --- GoogleMusicApi.py | 3 +-- GoogleMusicStorage.py | 57 ++++++------------------------------------ default.py | 4 ++- resources/settings.xml | 2 +- 4 files changed, 13 insertions(+), 53 deletions(-) diff --git a/GoogleMusicApi.py b/GoogleMusicApi.py index cc35ddc..e86c2e4 100644 --- a/GoogleMusicApi.py +++ b/GoogleMusicApi.py @@ -31,7 +31,7 @@ def getPlaylistSongs(self, playlist_id, forceRenew=False): songs = storage.getAutoPlaylistSongs(playlist_id) if playlist_id == 'thumbsup': """ Try to fetch all access thumbs up songs """ - for track in self.getApi().get_thumbs_up_songs(): + for track in self.getApi().get_promoted_songs(): songs.append(self._convertAATrack(track)) else: if forceRenew: @@ -73,7 +73,6 @@ def updatePlaylistSongs(self): def getSongStreamUrl(self, song_id): stream_url = self.getLogin().getStreamUrl(song_id) - #storage.updateSongStreamUrl(song_id, stream_url) return stream_url def incrementSongPlayCount(self, song_id): diff --git a/GoogleMusicStorage.py b/GoogleMusicStorage.py index 0dad001..e3f68c5 100644 --- a/GoogleMusicStorage.py +++ b/GoogleMusicStorage.py @@ -32,7 +32,6 @@ def clearCache(self): utils.addon.setSetting("fetched_all_songs", "0") def getPlaylistSongs(self, playlist_id): - #self._connect() if playlist_id == 'all_songs': result = self.curs.execute("SELECT * FROM songs ORDER BY display_name") else: @@ -40,7 +39,6 @@ def getPlaylistSongs(self, playlist_id): "INNER JOIN playlists_songs ON songs.song_id = playlists_songs.song_id "+ "WHERE playlists_songs.playlist_id = ?", (playlist_id,)) songs = result.fetchall() - #self._connect() return songs def getFilterSongs(self, filter_type, filter_criteria, albumArtist): @@ -57,9 +55,7 @@ def getFilterSongs(self, filter_type, filter_criteria, albumArtist): elif filter_type == 'composer': query = "select * from songs where composer = :filter order by album asc, disc asc, track asc, title asc" - #self._connect() songs = self.curs.execute(query,{'filter':filter_criteria if filter_criteria else '','albumArtist':albumArtist}).fetchall() - #self.conn.close() return songs @@ -67,29 +63,22 @@ def getCriteria(self, criteria, name): #print "### storage getcriteria: "+repr(criteria)+" "+repr(name) if criteria == 'album': - query = "select album_artist, album, year, max(album_art_url) from songs where album <> '-Unknown-' group by album_artist, album" + query = "select album_artist, album, year, max(album_art_url) from songs where album <> '-Unknown-' group by lower(album_artist), lower(album)" else: #if criteria == 'artist': criteria = 'album_artist' if criteria == 'artist' and not name: - query = "select artist, max(artist_art_url) from songs group by artist" + query = "select album_artist, max(artist_art_url) from songs group by lower(album_artist)" elif criteria == 'artist' and name: query = "select album_artist, album, year, max(album_art_url) from songs where (artist=:name or album_artist=:name) group by lower(album_artist), lower(album)" elif name: - query = "select album_artist, album, year, max(album_art_url) from songs where %s=:name group by album_artist, album" % criteria + query = "select album_artist, album, year, max(album_art_url) from songs where %s=:name group by lower(album_artist), lower(album)" % criteria else: query = "select %s from songs group by lower(%s)" % (criteria, criteria) - #self._connect() - criterias = self.curs.execute(query,{'name':name.decode('utf8')}).fetchall() - #self.conn.close() - - return criterias + return self.curs.execute(query,{'name':name.decode('utf8')}).fetchall() def getPlaylists(self): - #self._connect() - playlists = self.curs.execute("SELECT playlist_id, name FROM playlists ORDER BY name").fetchall() - #self.conn.close() - return playlists + return self.curs.execute("SELECT playlist_id, name FROM playlists ORDER BY name").fetchall() def getAutoPlaylistSongs(self,playlist): querys = {'thumbsup':'SELECT * FROM songs WHERE rating > 3 ORDER BY display_name', @@ -98,30 +87,20 @@ def getAutoPlaylistSongs(self,playlist): 'freepurchased':'SELECT * FROM songs WHERE type = 0 OR type = 1', 'feellucky':'SELECT * FROM songs ORDER BY random() LIMIT 500', } - #self._connect() - result = self.curs.execute(querys[playlist]).fetchall() - #self.conn.close() - return result + return self.curs.execute(querys[playlist]).fetchall() def getSong(self, song_id): - #self._connect() - result = self.curs.execute("SELECT * FROM songs WHERE song_id = ? ", (song_id,)).fetchone() - #result = self.curs.execute("SELECT stream_url FROM songs WHERE song_id = ? ", (song_id,)).fetchone() - #self.conn.close() - return result + return self.curs.execute("SELECT * FROM songs WHERE song_id = ? ", (song_id,)).fetchone() def getSearch(self, query): query = '%'+ query.replace('%','') + '%' - #self._connect() result = {} result['artists'] = self.curs.execute("SELECT artist, max(artist_art_url) FROM songs WHERE artist like ? GROUP BY artist", (query,)).fetchall() result['tracks'] = self.curs.execute("SELECT * FROM songs WHERE display_name like ? ORDER BY display_name", (query,)).fetchall() result['albums'] = self.curs.execute("SELECT album, artist, max(album_art_url) FROM songs WHERE album like ? GROUP BY album, artist", (query,)).fetchall() - #self.conn.close() return result def storePlaylistSongs(self, playlists_songs): - #self._connect() self.curs.execute("PRAGMA foreign_keys = OFF") self.curs.execute("DELETE FROM playlists_songs") @@ -140,12 +119,9 @@ def storePlaylistSongs(self, playlists_songs): api_songs.append(entry['track']) self.conn.commit() - #self.conn.close() - self.storeInAllSongs(api_songs) def storeApiSongs(self, api_songs, playlist_id = 'all_songs'): - #self._connect() self.curs.execute("PRAGMA foreign_keys = OFF") if playlist_id == 'all_songs': @@ -162,12 +138,9 @@ def storeApiSongs(self, api_songs, playlist_id = 'all_songs'): self.curs.execute("UPDATE playlists SET fetched = 1 WHERE playlist_id = ?", (playlist_id,)) self.conn.commit() - #self.conn.close() - self.storeInAllSongs(api_songs) def storeInAllSongs(self, api_songs): - #self._connect() self.curs.execute("PRAGMA foreign_keys = OFF") #for i in range(5): @@ -193,7 +166,7 @@ def songs(): 'play_count': get("playCount", 0), 'creation_date': get("creationDate", get("creationTimestamp", 0)), 'name': get("name", api_song["title"]), - 'artist': get("artist") if get("artist") else '-Unknown-', + 'artist': get("artist") if get("artist") else get("albumArtist") if get("albumArtist") else '-Unknown-', 'url': get("url", None), 'total_discs': get("total_discs", get("totalDiscCount", 0)), 'duration': int(get("durationMillis",0))/1000, @@ -208,10 +181,8 @@ def songs(): ":url, :total_discs, :duration, :album_art_url, :display_name, NULL, :artist_art_url)", songs()) self.conn.commit() - #self.conn.close() def storePlaylists(self, playlists, playlist_type): - #self._connect() self.curs.execute("PRAGMA foreign_keys = OFF") # (deletes will not cascade due to pragma) @@ -228,40 +199,29 @@ def playlist_rows(): # clean up dangling songs self.curs.execute("DELETE FROM playlists_songs WHERE playlist_id NOT IN (SELECT playlist_id FROM playlists)") self.conn.commit() - #self.conn.close() def getSongStreamUrl(self, song_id): - #self._connect() song = self.curs.execute("SELECT stream_url FROM songs WHERE song_id = ?", (song_id,)).fetchone() - #self.conn.close() return song[0] def incrementSongPlayCount(self, song_id): import time - #self._connect() self.curs.execute("UPDATE songs SET play_count = play_count+1, last_played = ? WHERE song_id = ?", (int(time.time()*1000000), song_id)) self.conn.commit() - #self.conn.close() def addToPlaylist(self, playlist_id, song_id, entry_id): - #self._connect() self.curs.execute("INSERT OR REPLACE INTO playlists_songs(playlist_id, song_id, entry_id) VALUES (?,?,?)", (playlist_id, song_id, entry_id)) self.conn.commit() - #self.conn.close() def delFromPlaylist(self, playlist_id, song_id): - #self._connect() entry_id = self.curs.execute("SELECT entry_id FROM playlists_songs WHERE playlist_id=? and song_id=?", (playlist_id, song_id)).fetchone() self.curs.execute("DELETE from playlists_songs WHERE entry_id=?", (entry_id[0], )) self.conn.commit() - #self.conn.close() return entry_id[0] def updateSongStreamUrl(self, song_id, stream_url): - #self._connect() self.curs.execute("UPDATE songs SET stream_url = ? WHERE song_id = ?", (stream_url, song_id)) self.conn.commit() - #self.conn.close() def _connect(self): self.conn = sqlite3.connect(self.path) @@ -319,7 +279,6 @@ def initializeDatabase(self): self.curs.execute('''CREATE INDEX IF NOT EXISTS songindex ON playlists_songs(song_id)''') self.conn.commit() - #self.conn.close() def _getSongDisplayName(self, api_song): displayName = "-Unknown-" diff --git a/default.py b/default.py index 4ed3170..ab194b8 100644 --- a/default.py +++ b/default.py @@ -50,10 +50,12 @@ # check if library needs to be loaded if addon.getSetting('fetched_all_songs') == '0': + xbmc.executebuiltin("XBMC.Notification(%s,%s,5000,%s)" % (utils.plugin, addon.getLocalizedString(30105) ,addon.getAddonInfo('icon'))) utils.log('Loading library') navigation.api.loadLibrary() - if addon.getSetting('auto_export') and addon.getSetting('export_path'): + + if addon.getSetting('auto_export')=='true' and addon.getSetting('export_path'): import GoogleMusicActions GoogleMusicActions.GoogleMusicActions().exportLibrary(addon.getSetting('export_path')) diff --git a/resources/settings.xml b/resources/settings.xml index 8e6d3ea..d402f7c 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -21,6 +21,6 @@ - +