mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-14 08:15:02 -05:00
Merge pull request #217 from chme/spotifycleanupafterupdate
[spotify/artwork] Remove spotify songs after playlist update and delete
This commit is contained in:
commit
e08b91d6ca
@ -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
|
||||
|
24
src/db.c
24
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 */
|
||||
|
4
src/db.h
4
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 */
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user