Skip to content

Commit

Permalink
Various improvements/fixes to metadata scanning and indexing:
Browse files Browse the repository at this point in the history
  * Read rating value from metadata while indexing
  * Parse ID3V2 tags from AAC files if present
  * Minor cleanup to file extension detection in TaglibMetadataReader
  * Fix bug that may cause the track's "title" field to get populated
    with the filename/uri instead of the track title.
  • Loading branch information
clangen committed Jul 28, 2023
1 parent c8ff55e commit c58c4c5
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 125 deletions.
57 changes: 29 additions & 28 deletions src/musikcore/library/track/IndexerTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ double IndexerTrack::GetDouble(const char* key, double defaultValue) {
}

void IndexerTrack::SetValue(const char* metakey, const char* value) {
if (metakey && value) {
if (metakey && value && strlen(value)) {
this->internalMetadata->metadata.insert(
std::pair<std::string, std::string>(metakey,value));
}
Expand Down Expand Up @@ -345,35 +345,35 @@ static int64_t writeToTracksTable(
query =
"UPDATE tracks "
"SET track=?, disc=?, bpm=?, duration=?, filesize=?, "
" title=?, filename=?, filetime=?, path_id=?, "
" title=?, rating=?, filename=?, filetime=?, path_id=?, "
" date_updated=julianday('now'), external_id=? "
"WHERE id=?";
}
else {
query =
"INSERT INTO tracks "
"(track, disc, bpm, duration, filesize, title, filename, "
"(track, disc, bpm, duration, filesize, title, rating, filename, "
" filetime, path_id, external_id, date_added, date_updated) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, julianday('now'), julianday('now'))";
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, julianday('now'), julianday('now'))";
}

db::Statement stmt(query.c_str(), dbConnection);

auto time = track.GetInt64("filetime");

stmt.BindInt32(0, stringToInt(track.GetString("track"), 1));
stmt.BindInt32(1, stringToInt(track.GetString("disc"), 1));
stmt.BindText(2, track.GetString("bpm"));
stmt.BindInt32(3, track.GetInt32("duration"));
stmt.BindInt32(4, track.GetInt32("filesize"));
stmt.BindText(5, track.GetString("title"));
stmt.BindText(6, track.GetString("filename"));
stmt.BindInt64(7, track.GetInt64("filetime"));
stmt.BindInt64(8, track.GetInt64("path_id"));
stmt.BindText(9, track.GetString("external_id"));
int bindPos = 0;
stmt.BindInt32(bindPos++, stringToInt(track.GetString("track"), 1));
stmt.BindInt32(bindPos++, stringToInt(track.GetString("disc"), 1));
stmt.BindText(bindPos++, track.GetString("bpm"));
stmt.BindInt32(bindPos++, track.GetInt32("duration"));
stmt.BindInt32(bindPos++, track.GetInt32("filesize"));
stmt.BindText(bindPos++, track.GetString("title"));
stmt.BindInt32(bindPos++, stringToInt(track.GetString("rating"), 0));
stmt.BindText(bindPos++, track.GetString("filename"));
stmt.BindInt64(bindPos++, track.GetInt64("filetime"));
stmt.BindInt64(bindPos++, track.GetInt64("path_id"));
stmt.BindText(bindPos++, track.GetString("external_id"));

if (id != 0) {
stmt.BindInt64(10, id);
stmt.BindInt64(bindPos++, id);
}

if (stmt.Step() == db::Done) {
Expand All @@ -397,23 +397,24 @@ static void removeRelation(
}

static void removeKnownFields(Track::MetadataMap& metadata) {
metadata.erase("track");
metadata.erase("disc");
metadata.erase("album_artist");
metadata.erase("album");
metadata.erase("artist");
metadata.erase("bpm");
metadata.erase("disc");
metadata.erase("duration");
metadata.erase("title");
metadata.erase("extension");
metadata.erase("external_id");
metadata.erase("filename");
metadata.erase("filetime");
metadata.erase("filesize");
metadata.erase("title");
metadata.erase("path");
metadata.erase("extension");
metadata.erase("filetime");
metadata.erase("genre");
metadata.erase("artist");
metadata.erase("album_artist");
metadata.erase("album");
metadata.erase("path");
metadata.erase("rating");
metadata.erase("source_id");
metadata.erase("external_id");
metadata.erase("title");
metadata.erase("title");
metadata.erase("track");
metadata.erase("visible");
}

Expand Down
Loading

0 comments on commit c58c4c5

Please sign in to comment.