mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 18:36:02 -05:00
[library/spotify] Implement rescan in spotify.c and purge old files
after rescan
This commit is contained in:
parent
0bea83cafa
commit
ae1a45bacc
6
src/db.c
6
src/db.c
@ -3528,12 +3528,12 @@ db_directory_addorupdate(char *virtual_path, int disabled, int parent_id)
|
||||
}
|
||||
|
||||
void
|
||||
db_directory_ping_bymatch(char *path)
|
||||
db_directory_ping_bymatch(char *virtual_path)
|
||||
{
|
||||
#define Q_TMPL_DIR "UPDATE directories SET db_timestamp = %" PRIi64 " WHERE virtual_path = '/file:%q' OR virtual_path LIKE '/file:%q/%%';"
|
||||
#define Q_TMPL_DIR "UPDATE directories SET db_timestamp = %" PRIi64 " WHERE virtual_path = '%q' OR virtual_path LIKE '%q/%%';"
|
||||
char *query;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL_DIR, (int64_t)time(NULL), path, path);
|
||||
query = sqlite3_mprintf(Q_TMPL_DIR, (int64_t)time(NULL), virtual_path, virtual_path);
|
||||
|
||||
db_query_run(query, 1, 0);
|
||||
#undef Q_TMPL_DIR
|
||||
|
2
src/db.h
2
src/db.h
@ -633,7 +633,7 @@ int
|
||||
db_directory_addorupdate(char *virtual_path, int disabled, int parent_id);
|
||||
|
||||
void
|
||||
db_directory_ping_bymatch(char *path);
|
||||
db_directory_ping_bymatch(char *virtual_path);
|
||||
|
||||
void
|
||||
db_directory_disable_bymatch(char *path, char *strip, uint32_t cookie);
|
||||
|
@ -766,6 +766,8 @@ bulk_scan(int flags)
|
||||
time_t end;
|
||||
int parent_id;
|
||||
int i;
|
||||
char virtual_path[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
start = time(NULL);
|
||||
|
||||
@ -793,7 +795,11 @@ bulk_scan(int flags)
|
||||
|
||||
db_file_ping_bymatch(path, 1);
|
||||
db_pl_ping_bymatch(path, 1);
|
||||
db_directory_ping_bymatch(path);
|
||||
ret = snprintf(virtual_path, sizeof(virtual_path), "/file:%s", path);
|
||||
if ((ret < 0) || (ret >= sizeof(virtual_path)))
|
||||
DPRINTF(E_LOG, L_SCAN, "Virtual path exceeds PATH_MAX (/file:%s)\n", path);
|
||||
else
|
||||
db_directory_ping_bymatch(virtual_path);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -572,6 +572,8 @@ rescan(void *arg, int *ret)
|
||||
sources[i]->rescan();
|
||||
}
|
||||
|
||||
purge_cruft(starttime);
|
||||
|
||||
endtime = time(NULL);
|
||||
DPRINTF(E_LOG, L_LIB, "Library rescan completed in %.f sec\n", difftime(endtime, starttime));
|
||||
|
||||
@ -646,10 +648,13 @@ initscan()
|
||||
sources[i]->initscan();
|
||||
}
|
||||
|
||||
purge_cruft(starttime);
|
||||
if (! (cfg_getbool(cfg_getsec(cfg, "library"), "filescan_disable")))
|
||||
{
|
||||
purge_cruft(starttime);
|
||||
|
||||
DPRINTF(E_DBG, L_LIB, "Running post library scan jobs\n");
|
||||
db_hook_post_scan();
|
||||
DPRINTF(E_DBG, L_LIB, "Running post library scan jobs\n");
|
||||
db_hook_post_scan();
|
||||
}
|
||||
|
||||
endtime = time(NULL);
|
||||
DPRINTF(E_LOG, L_LIB, "Library init scan completed in %.f sec\n", difftime(endtime, starttime));
|
||||
|
@ -2233,7 +2233,7 @@ scan_playlists()
|
||||
|
||||
/* Thread: library */
|
||||
static int
|
||||
spotify_initscan()
|
||||
initscan()
|
||||
{
|
||||
cfg_t *spotify_cfg;
|
||||
int ret;
|
||||
@ -2283,14 +2283,31 @@ spotify_initscan()
|
||||
|
||||
/* Thread: library */
|
||||
static int
|
||||
spotify_rescan()
|
||||
rescan()
|
||||
{
|
||||
/*
|
||||
* Scan saved tracks from the web api
|
||||
*/
|
||||
if (spotify_access_token_valid)
|
||||
{
|
||||
scan_saved_albums();
|
||||
scan_playlists();
|
||||
}
|
||||
else
|
||||
{
|
||||
db_transaction_begin();
|
||||
db_file_ping_bymatch("spotify:", 0);
|
||||
db_pl_ping_bymatch("spotify:", 0);
|
||||
db_directory_ping_bymatch("/spotify:");
|
||||
db_transaction_end();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Thread: library */
|
||||
static int
|
||||
spotify_fullrescan()
|
||||
fullrescan()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -2498,7 +2515,7 @@ struct library_source spotifyscanner =
|
||||
.disabled = 0,
|
||||
.init = spotify_init,
|
||||
.deinit = spotify_deinit,
|
||||
.rescan = spotify_rescan,
|
||||
.initscan = spotify_initscan,
|
||||
.fullrescan = spotify_fullrescan,
|
||||
.rescan = rescan,
|
||||
.initscan = initscan,
|
||||
.fullrescan = fullrescan,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user