[library/spotify] Implement rescan in spotify.c and purge old files

after rescan
This commit is contained in:
chme 2017-01-01 16:51:21 +01:00
parent 0bea83cafa
commit ae1a45bacc
5 changed files with 42 additions and 14 deletions

View File

@ -3528,12 +3528,12 @@ db_directory_addorupdate(char *virtual_path, int disabled, int parent_id)
} }
void 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; 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); db_query_run(query, 1, 0);
#undef Q_TMPL_DIR #undef Q_TMPL_DIR

View File

@ -633,7 +633,7 @@ int
db_directory_addorupdate(char *virtual_path, int disabled, int parent_id); db_directory_addorupdate(char *virtual_path, int disabled, int parent_id);
void void
db_directory_ping_bymatch(char *path); db_directory_ping_bymatch(char *virtual_path);
void void
db_directory_disable_bymatch(char *path, char *strip, uint32_t cookie); db_directory_disable_bymatch(char *path, char *strip, uint32_t cookie);

View File

@ -766,6 +766,8 @@ bulk_scan(int flags)
time_t end; time_t end;
int parent_id; int parent_id;
int i; int i;
char virtual_path[PATH_MAX];
int ret;
start = time(NULL); start = time(NULL);
@ -793,7 +795,11 @@ bulk_scan(int flags)
db_file_ping_bymatch(path, 1); db_file_ping_bymatch(path, 1);
db_pl_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; continue;
} }

View File

@ -572,6 +572,8 @@ rescan(void *arg, int *ret)
sources[i]->rescan(); sources[i]->rescan();
} }
purge_cruft(starttime);
endtime = time(NULL); endtime = time(NULL);
DPRINTF(E_LOG, L_LIB, "Library rescan completed in %.f sec\n", difftime(endtime, starttime)); DPRINTF(E_LOG, L_LIB, "Library rescan completed in %.f sec\n", difftime(endtime, starttime));
@ -646,10 +648,13 @@ initscan()
sources[i]->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"); DPRINTF(E_DBG, L_LIB, "Running post library scan jobs\n");
db_hook_post_scan(); db_hook_post_scan();
}
endtime = time(NULL); endtime = time(NULL);
DPRINTF(E_LOG, L_LIB, "Library init scan completed in %.f sec\n", difftime(endtime, starttime)); DPRINTF(E_LOG, L_LIB, "Library init scan completed in %.f sec\n", difftime(endtime, starttime));

View File

@ -2233,7 +2233,7 @@ scan_playlists()
/* Thread: library */ /* Thread: library */
static int static int
spotify_initscan() initscan()
{ {
cfg_t *spotify_cfg; cfg_t *spotify_cfg;
int ret; int ret;
@ -2283,14 +2283,31 @@ spotify_initscan()
/* Thread: library */ /* Thread: library */
static int 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; return 0;
} }
/* Thread: library */ /* Thread: library */
static int static int
spotify_fullrescan() fullrescan()
{ {
return 0; return 0;
} }
@ -2498,7 +2515,7 @@ struct library_source spotifyscanner =
.disabled = 0, .disabled = 0,
.init = spotify_init, .init = spotify_init,
.deinit = spotify_deinit, .deinit = spotify_deinit,
.rescan = spotify_rescan, .rescan = rescan,
.initscan = spotify_initscan, .initscan = initscan,
.fullrescan = spotify_fullrescan, .fullrescan = fullrescan,
}; };