[scan] Update iTunes scanner to use new filescanner util functions
This commit is contained in:
parent
46a9114948
commit
2a69869816
|
@ -21,6 +21,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -859,21 +860,14 @@ process_pls(plist_t playlists, const char *file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
void
|
itml_is_modified(const char *path, time_t mtime)
|
||||||
scan_itunes_itml(const char *file, time_t mtime, int dir_id)
|
|
||||||
{
|
{
|
||||||
struct playlist_info *pli;
|
struct playlist_info *pli;
|
||||||
struct stat sb;
|
int pl_id;
|
||||||
char buf[PATH_MAX];
|
|
||||||
char *itml_xml;
|
|
||||||
plist_t itml;
|
|
||||||
plist_t node;
|
|
||||||
int fd;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
// This is special playlist that is disabled and only used for saving a timestamp
|
// This is a special playlist that is disabled and only used for saving a timestamp
|
||||||
pli = db_pl_fetch_bytitlepath(file, file);
|
pli = db_pl_fetch_bytitlepath(path, path);
|
||||||
if (pli)
|
if (pli)
|
||||||
{
|
{
|
||||||
// mtime == db_timestamp is also treated as a modification because some editors do
|
// mtime == db_timestamp is also treated as a modification because some editors do
|
||||||
|
@ -882,47 +876,50 @@ scan_itunes_itml(const char *file, time_t mtime, int dir_id)
|
||||||
// is equal to the newly updated db_timestamp)
|
// is equal to the newly updated db_timestamp)
|
||||||
if (mtime && (pli->db_timestamp > mtime))
|
if (mtime && (pli->db_timestamp > mtime))
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Unchanged iTunes XML found, not processing '%s'\n", file);
|
DPRINTF(E_LOG, L_SCAN, "Unchanged iTunes XML found, not processing '%s'\n", path);
|
||||||
|
|
||||||
// TODO Protect the radio stations from purge after scan
|
// TODO Protect the radio stations from purge after scan
|
||||||
db_pl_ping_bymatch(file, 0);
|
db_pl_ping_bymatch(path, 0);
|
||||||
free_pli(pli, 0);
|
free_pli(pli, 0);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Modified iTunes XML found, processing '%s'\n", file);
|
DPRINTF(E_LOG, L_SCAN, "Modified iTunes XML found, processing '%s'\n", path);
|
||||||
|
|
||||||
// Clear out everything, we will recreate
|
// Clear out everything, we will recreate
|
||||||
db_pl_delete_bypath(file);
|
db_pl_delete_bypath(path);
|
||||||
free_pli(pli, 0);
|
free_pli(pli, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "New iTunes XML found, processing: '%s'\n", file);
|
DPRINTF(E_LOG, L_SCAN, "New iTunes XML found, processing: '%s'\n", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_NULL(L_SCAN, pli = calloc(1, sizeof(struct playlist_info)));
|
pl_id = playlist_add(path);
|
||||||
|
if (pl_id < 0)
|
||||||
pli->type = PL_PLAIN;
|
|
||||||
pli->title = strdup(file);
|
|
||||||
pli->path = strdup(file);
|
|
||||||
snprintf(buf, sizeof(buf), "/file:%s", file);
|
|
||||||
pli->virtual_path = strip_extension(buf);
|
|
||||||
pli->directory_id = dir_id;
|
|
||||||
|
|
||||||
ret = db_pl_add(pli, (int *)&pli->id);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Error adding iTunes XML meta playlist '%s'\n", file);
|
DPRINTF(E_LOG, L_SCAN, "Error adding iTunes XML meta playlist '%s'\n", path);
|
||||||
|
return false;
|
||||||
free_pli(pli, 0);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable, only used for saving timestamp
|
// Disable, only used for saving timestamp
|
||||||
db_pl_disable_bypath(file, STRIP_NONE, 0);
|
db_pl_disable_bypath(path, STRIP_NONE, 0);
|
||||||
|
|
||||||
free_pli(pli, 0);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
scan_itunes_itml(const char *file, time_t mtime, int dir_id)
|
||||||
|
{
|
||||||
|
struct stat sb;
|
||||||
|
char *itml_xml;
|
||||||
|
plist_t itml;
|
||||||
|
plist_t node;
|
||||||
|
int fd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!itml_is_modified(file, mtime))
|
||||||
|
return;
|
||||||
|
|
||||||
fd = open(file, O_RDONLY);
|
fd = open(file, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
|
Loading…
Reference in New Issue