diff --git a/src/cache.c b/src/cache.c index f1cfc787..26befb86 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1050,6 +1050,8 @@ cache_artwork_delete_by_path_impl(struct cache_command *cmd) return -1; } + DPRINTF(E_DBG, L_CACHE, "Deleted %d rows\n", sqlite3_changes(g_db_hdl)); + return 0; #undef Q_TMPL_DEL diff --git a/src/db.c b/src/db.c index f3b70f5a..1cbf6f15 100644 --- a/src/db.c +++ b/src/db.c @@ -1557,6 +1557,10 @@ db_query_start(struct query_params *qp) ret = db_build_query_browse(qp, "virtual_path", "virtual_path", &query); break; + case Q_BROWSE_PATH: + ret = db_build_query_browse(qp, "path", "path", &query); + break; + case Q_COUNT_ITEMS: ret = db_build_query_count_items(qp, &query); break; @@ -3674,11 +3678,10 @@ db_spotify_purge(void) void db_spotify_pl_delete(int id) { - char *queries_tmpl[3] = + char *queries_tmpl[2] = { "DELETE FROM playlists WHERE id = %d;", "DELETE FROM playlistitems WHERE playlistid = %d;", - "DELETE FROM files WHERE path LIKE 'spotify:%%' AND NOT path IN (SELECT filepath FROM playlistitems);", }; char *query; int i; @@ -3694,6 +3697,23 @@ db_spotify_pl_delete(int id) DPRINTF(E_DBG, L_DB, "Deleted %d rows\n", sqlite3_changes(hdl)); } } + +/* Spotify */ +void +db_spotify_files_delete() +{ +#define Q_TMPL "DELETE FROM files WHERE path LIKE 'spotify:%%' AND NOT path IN (SELECT filepath FROM playlistitems);" + char *query; + int ret; + + query = sqlite3_mprintf(Q_TMPL); + + ret = db_query_run(query, 1, 1); + + if (ret == 0) + DPRINTF(E_DBG, L_DB, "Deleted %d rows\n", sqlite3_changes(hdl)); +#undef Q_TMPL +} #endif /* Admin */ diff --git a/src/db.h b/src/db.h index 68fbf4d4..fe6f7ad0 100644 --- a/src/db.h +++ b/src/db.h @@ -49,6 +49,7 @@ enum query_type { Q_BROWSE_DISCS = Q_F_BROWSE | 14, Q_BROWSE_TRACKS = Q_F_BROWSE | 15, Q_BROWSE_VPATH = Q_F_BROWSE | 16, + Q_BROWSE_PATH = Q_F_BROWSE | 17, }; #define ARTWORK_UNKNOWN 0 @@ -571,6 +572,9 @@ db_spotify_purge(void); void db_spotify_pl_delete(int id); + +void +db_spotify_files_delete(); #endif /* Admin */ diff --git a/src/spotify.c b/src/spotify.c index b5f818e3..9e9cbc92 100644 --- a/src/spotify.c +++ b/src/spotify.c @@ -44,6 +44,7 @@ #include "logger.h" #include "conffile.h" #include "filescanner.h" +#include "cache.h" /* How long to wait for audio (in sec) before giving up */ @@ -624,6 +625,39 @@ spotify_track_save(int plid, sp_track *track, const char *pltitle, int time_adde return 0; } +static int +spotify_playlist_cleanupfiles() +{ + struct query_params qp; + char *path; + int ret; + + memset(&qp, 0, sizeof(struct query_params)); + + qp.type = Q_BROWSE_PATH; + qp.sort = S_NONE; + qp.filter = "f.path LIKE 'spotify:%%' AND NOT f.path IN (SELECT filepath FROM playlistitems)"; + + ret = db_query_start(&qp); + if (ret < 0) + { + db_query_end(&qp); + + return -1; + } + + while (((ret = db_query_fetch_string(&qp, &path)) == 0) && (path)) + { + cache_artwork_delete_by_path(path); + } + + db_query_end(&qp); + + db_spotify_files_delete(); + + return 0; +} + static int spotify_playlist_save(sp_playlist *pl) { @@ -758,6 +792,8 @@ spotify_playlist_save(sp_playlist *pl) continue; } } + + spotify_playlist_cleanupfiles(); db_transaction_end(); return plid; @@ -873,6 +909,7 @@ playlist_removed(sp_playlistcontainer *pc, sp_playlist *pl, int position, void * free_pli(pli, 0); db_spotify_pl_delete(plid); + spotify_playlist_cleanupfiles(); } /**