int64_t find_album_art(const char *path, const char *image_data, int image_size) { char *album_art = NULL; char *sql; char **result; int cols, rows; int64_t ret = 0; if( (image_size && (album_art = check_embedded_art(path, image_data, image_size))) || (album_art = check_for_album_file(path)) ) { sql = sqlite3_mprintf("SELECT ID from ALBUM_ART where PATH = '%q'", album_art ? album_art : path); if( (sql_get_table(db, sql, &result, &rows, &cols) == SQLITE_OK) && rows ) { ret = strtoll(result[1], NULL, 10); } else { if( sql_exec(db, "INSERT into ALBUM_ART (PATH) VALUES ('%q')", album_art) == SQLITE_OK ) ret = sqlite3_last_insert_rowid(db); } sqlite3_free_table(result); sqlite3_free(sql); } free(album_art); return ret; }
sqlite_int64 find_album_art(const char * path, const char * image_data, int image_size) { char * album_art = NULL; char * sql; char ** result; int cols, rows; sqlite_int64 ret = 0; char * mypath; const char * dir; struct stat st; if( stat(path, &st) == 0 && S_ISDIR(st.st_mode) ) { mypath = NULL; dir = path; } else { mypath = strdup(path); dir = dirname(mypath); } if( (image_size && (album_art = check_embedded_art(path, image_data, image_size))) || (album_art = check_for_album_file(dir, path)) ) { sql = sqlite3_mprintf("SELECT ID from ALBUM_ART where PATH = '%q'", album_art ? album_art : path); if( (sql_get_table(db, sql, &result, &rows, &cols) == SQLITE_OK) && rows ) { ret = strtoll(result[1], NULL, 10); } else { if( sql_exec(db, "INSERT into ALBUM_ART (PATH) VALUES ('%q')", album_art) == SQLITE_OK ) ret = sqlite3_last_insert_rowid(db); } sqlite3_free_table(result); sqlite3_free(sql); } free(album_art); free(mypath); return ret; }