[scan] Update smartpl scanner to use filescanner util functions

This commit is contained in:
ejurgensen 2020-02-01 12:56:54 -08:00
parent 2a69869816
commit 189370df91

View File

@ -35,6 +35,8 @@
#include "db.h" #include "db.h"
#include "misc.h" #include "misc.h"
#include "smartpl_query.h" #include "smartpl_query.h"
#include "library/filescanner.h"
#include "library.h"
void void
@ -42,28 +44,18 @@ scan_smartpl(const char *file, time_t mtime, int dir_id)
{ {
struct smartpl smartpl; struct smartpl smartpl;
struct playlist_info *pli; struct playlist_info *pli;
int pl_id;
char virtual_path[PATH_MAX];
char *ptr;
int ret; int ret;
/* Fetch or create playlist */ /* Fetch or create playlist */
pli = db_pl_fetch_bypath(file); pli = db_pl_fetch_bypath(file);
if (!pli) if (!pli)
{ {
pli = calloc(1, sizeof(struct playlist_info)); CHECK_NULL(L_SCAN, pli = calloc(1, sizeof(struct playlist_info)));
if (!pli)
{ ret = playlist_fill(pli, file);
DPRINTF(E_LOG, L_SCAN, "Out of memory\n"); if (ret < 0)
return; goto error;
}
pli->path = strdup(file);
snprintf(virtual_path, PATH_MAX, "/file:%s", file);
ptr = strrchr(virtual_path, '.');
if (ptr)
*ptr = '\0';
pli->virtual_path = strdup(virtual_path);
pli->type = PL_SMART; pli->type = PL_SMART;
} }
@ -74,10 +66,8 @@ scan_smartpl(const char *file, time_t mtime, int dir_id)
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_SCAN, "Error parsing smart playlist '%s'\n", file); DPRINTF(E_LOG, L_SCAN, "Error parsing smart playlist '%s'\n", file);
free_pli(pli, 0);
free_smartpl(&smartpl, 1); free_smartpl(&smartpl, 1);
return; goto error;
} }
free(pli->title); free(pli->title);
@ -93,26 +83,16 @@ scan_smartpl(const char *file, time_t mtime, int dir_id)
free_smartpl(&smartpl, 1); free_smartpl(&smartpl, 1);
if (pli->id) ret = library_playlist_save(pli);
{
pl_id = pli->id;
ret = db_pl_update(pli);
}
else
{
ret = db_pl_add(pli, &pl_id);
}
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_SCAN, "Error adding smart playlist '%s'\n", file); DPRINTF(E_LOG, L_SCAN, "Error saving smart playlist '%s'\n", file);
goto error;
free_pli(pli, 0);
return;
} }
DPRINTF(E_INFO, L_SCAN, "Added or updated smart playlist as id %d\n", pl_id); DPRINTF(E_INFO, L_SCAN, "Added or updated smart playlist '%s'\n", file);
error:
free_pli(pli, 0); free_pli(pli, 0);
return;
DPRINTF(E_INFO, L_SCAN, "Done processing smart playlist\n");
} }