Don't add duplicates (same fname, artist, album and title), issue #85
This commit is contained in:
parent
4df4c50c35
commit
70365422b4
17
src/db.c
17
src/db.c
|
@ -2359,6 +2359,23 @@ db_file_fetch_byid(int id)
|
|||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
int
|
||||
db_file_is_duplicate(struct media_file_info *mfi)
|
||||
{
|
||||
#define Q_TMPL "SELECT f.id FROM files f WHERE f.title = TRIM(%Q) AND f.artist = TRIM(%Q) AND f.album = TRIM(%Q) AND f.fname = '%q';"
|
||||
char *query;
|
||||
int id;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, mfi->title, mfi->artist, mfi->album, mfi->fname);
|
||||
|
||||
id = db_file_id_byquery(query);
|
||||
|
||||
sqlite3_free(query);
|
||||
|
||||
return ((id > 0) && (id != mfi->id));
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
int
|
||||
db_file_add(struct media_file_info *mfi)
|
||||
{
|
||||
|
|
3
src/db.h
3
src/db.h
|
@ -394,6 +394,9 @@ db_file_stamp_bypath(char *path, time_t *stamp, int *id);
|
|||
struct media_file_info *
|
||||
db_file_fetch_byid(int id);
|
||||
|
||||
int
|
||||
db_file_is_duplicate(struct media_file_info *mfi);
|
||||
|
||||
int
|
||||
db_file_add(struct media_file_info *mfi);
|
||||
|
||||
|
|
|
@ -678,6 +678,19 @@ filescanner_process_media(char *path, time_t mtime, off_t size, int type, struct
|
|||
|
||||
fixup_tags(mfi);
|
||||
|
||||
if (db_file_is_duplicate(mfi))
|
||||
{
|
||||
DPRINTF(E_LOG, L_SCAN, "Skipping '%s' (duplicate filename, artist, album and title)\n", mfi->path);
|
||||
|
||||
/* Can't just disable because db_file_ping() will reenable on startup */
|
||||
if (mfi->id > 0)
|
||||
{
|
||||
db_file_delete_bypath(mfi->path);
|
||||
cache_artwork_delete_by_path(mfi->path);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (mfi->id == 0)
|
||||
db_file_add(mfi);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue