/* And our main album art functions */ void update_if_album_art(const char *path) { char *dir; char *match; char file[MAXPATHLEN]; char fpath[MAXPATHLEN]; char dpath[MAXPATHLEN]; int ncmp = 0; int album_art; DIR *dh; struct dirent *dp; enum file_types type = TYPE_UNKNOWN; int64_t art_id = 0; int ret; strncpyt(fpath, path, sizeof(fpath)); match = basename(fpath); /* Check if this file name matches a specific audio or video file */ if( ends_with(match, ".cover.jpg") ) { ncmp = strlen(match)-10; } else { ncmp = strrchr(match, '.') - match; } /* Check if this file name matches one of the default album art names */ album_art = is_album_art(match); strncpyt(dpath, path, sizeof(dpath)); dir = dirname(dpath); dh = opendir(dir); if( !dh ) return; while ((dp = readdir(dh)) != NULL) { switch( dp->d_type ) { case DT_REG: type = TYPE_FILE; break; case DT_LNK: case DT_UNKNOWN: snprintf(file, sizeof(file), "%s/%s", dir, dp->d_name); type = resolve_unknown_type(file, ALL_MEDIA); break; default: type = TYPE_UNKNOWN; break; } if( type != TYPE_FILE ) continue; if( (*(dp->d_name) != '.') && (is_video(dp->d_name) || is_audio(dp->d_name)) && (album_art || strncmp(dp->d_name, match, ncmp) == 0) ) { DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like cover art for %s\n", path, dp->d_name); snprintf(file, sizeof(file), "%s/%s", dir, dp->d_name); art_id = find_album_art(file, NULL, 0); ret = sql_exec(db, "UPDATE DETAILS set ALBUM_ART = %lld where PATH = '%q'", (long long)art_id, file); if( ret != SQLITE_OK ) DPRINTF(E_WARN, L_METADATA, "Error setting %s as cover art for %s\n", match, dp->d_name); } } closedir(dh); }
/* And our main album art functions */ void update_if_album_art(const char * path) { char * dir; char * match = NULL; char * file = NULL; int ncmp = 0; struct album_art_name_s * album_art_name; DIR * dh; struct dirent *dp; enum file_types type = TYPE_UNKNOWN; sqlite_int64 art_id = 0; match = strdup(basename((char *)path)); /* Check if this file name matches a specific audio or video file */ if( ends_with(match, ".cover.jpg") ) { ncmp = strlen(match)-10; } else { ncmp = strrchr(match, '.')-match; } /* Check if this file name matches one of the default album art names */ for( album_art_name = album_art_names; album_art_name; album_art_name = album_art_name->next ) { if( strcmp(album_art_name->name, match) == 0 ) break; } dir = dirname(strdup(path)); dh = opendir(dir); if( !dh ) return; while ((dp = readdir(dh)) != NULL) { switch( dp->d_type ) { case DT_REG: type = TYPE_FILE; break; case DT_LNK: case DT_UNKNOWN: asprintf(&file, "%s/%s", dir, dp->d_name); type = resolve_unknown_type(file, ALL_MEDIA); free(file); break; default: type = TYPE_UNKNOWN; break; } if( type != TYPE_FILE ) continue; if( (*(dp->d_name) != '.') && (is_video(dp->d_name) || is_audio(dp->d_name)) && (album_art_name || strncmp(dp->d_name, match, ncmp) == 0) ) { DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like cover art for %s\n", path, dp->d_name); asprintf(&file, "%s/%s", dir, dp->d_name); art_id = find_album_art(file, NULL, 0); if( sql_exec(db, "UPDATE DETAILS set ALBUM_ART = %lld where PATH = '%q'", art_id, file) != SQLITE_OK ) DPRINTF(E_WARN, L_METADATA, "Error setting %s as cover art for %s\n", match, dp->d_name); free(file); } } closedir(dh); free(dir); free(match); }