mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
Repaired processing of "non-standard" track metadata (bitrate, channels,
composer, year, etc) in IndexerTrack. Also added a new view to LocalLibrary so this data can be queried for easily. Additionally, updated year parsing logic in TaglibMetadataReader to be more robust.
This commit is contained in:
parent
a219b2e91d
commit
cc6e8dbff3
@ -490,6 +490,19 @@ void LocalLibrary::CreateDatabase(db::Connection &db){
|
||||
db.Execute("ALTER TABLE playlist_tracks ADD COLUMN track_external_id TEXT NOT NULL DEFAULT ''");
|
||||
db.Execute("ALTER TABLE playlist_tracks ADD COLUMN source_id INTEGER DEFAULT 0");
|
||||
|
||||
/* add the extended metadata track view */
|
||||
db.Execute(
|
||||
"CREATE VIEW extended_metadata AS "
|
||||
"SELECT DISTINCT "
|
||||
"tracks.id, tracks.external_id, tracks.source_id, meta_keys.id AS meta_key_id, track_meta.meta_value_id, "
|
||||
"meta_keys.name AS key, meta_values.content AS value "
|
||||
"FROM "
|
||||
"track_meta, meta_values, meta_keys, tracks "
|
||||
"WHERE "
|
||||
"tracks.id == track_meta.track_id AND "
|
||||
"meta_values.id = track_meta.meta_value_id AND "
|
||||
"meta_values.meta_key_id == meta_keys.id ");
|
||||
|
||||
/* upgrade playlist tracks table */
|
||||
if (lastVersion == 1) {
|
||||
upgradeV1toV2(db);
|
||||
|
@ -394,17 +394,22 @@ void IndexerTrack::ProcessNonStandardMetadata(db::Connection& connection) {
|
||||
for ( ; it != unknownFields.end(); ++it){
|
||||
int64_t keyId = 0;
|
||||
std::string key;
|
||||
bool keyCached = false, valueCached = false;
|
||||
|
||||
/* lookup the ID for the key; insert if it doesn't exist.. */
|
||||
if (metadataIdCache.find("metaKey-" + it->first) != metadataIdCache.end()) {
|
||||
keyId = metadataIdCache["metaKey-" + it->first];
|
||||
keyCached = true;
|
||||
}
|
||||
else {
|
||||
selectMetaKey.Reset();
|
||||
selectMetaKey.BindText(0, it->first);
|
||||
|
||||
if (selectMetaKey.Step() == db::Row) {
|
||||
keyId = selectMetaKey.ColumnInt64(0);
|
||||
}
|
||||
else {
|
||||
insertMetaKey.Reset();
|
||||
insertMetaKey.BindText(0, it->first);
|
||||
|
||||
if (insertMetaKey.Step() == db::Done) {
|
||||
@ -412,8 +417,9 @@ void IndexerTrack::ProcessNonStandardMetadata(db::Connection& connection) {
|
||||
}
|
||||
}
|
||||
|
||||
metadataIdCache["metaKey-" + it->first] = keyId;
|
||||
selectMetaKey.Reset();
|
||||
if (keyId != 0) {
|
||||
metadataIdCache["metaKey-" + it->first] = keyId;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyId == 0) {
|
||||
@ -427,8 +433,10 @@ void IndexerTrack::ProcessNonStandardMetadata(db::Connection& connection) {
|
||||
|
||||
if (metadataIdCache.find("metaValue-" + it->second) != metadataIdCache.end()) {
|
||||
valueId = metadataIdCache["metaValue-" + it->second];
|
||||
valueCached = true;
|
||||
}
|
||||
else {
|
||||
selectMetaValue.Reset();
|
||||
selectMetaValue.BindInt64(0, keyId);
|
||||
selectMetaValue.BindText(1, it->second);
|
||||
|
||||
@ -436,27 +444,31 @@ void IndexerTrack::ProcessNonStandardMetadata(db::Connection& connection) {
|
||||
valueId = selectMetaValue.ColumnInt64(0);
|
||||
}
|
||||
else {
|
||||
insertMetaValue.Reset();
|
||||
insertMetaValue.BindInt64(0, keyId);
|
||||
insertMetaValue.BindText(1, it->second);
|
||||
|
||||
if (insertMetaValue.Step() == db::Done) {
|
||||
valueId = connection.LastInsertedId();
|
||||
}
|
||||
|
||||
insertMetaValue.Reset();
|
||||
}
|
||||
|
||||
metadataIdCache["metaValue-" + it->second] = valueId;
|
||||
selectMetaValue.Reset();
|
||||
if (valueId != 0) {
|
||||
metadataIdCache["metaValue-" + it->second] = valueId;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyCached && valueCached) {
|
||||
continue; /* duplicate info. we don't need to save it again. */
|
||||
}
|
||||
|
||||
/* now that we have a keyId and a valueId, create the relationship */
|
||||
|
||||
if (valueId != 0) {
|
||||
insertTrackMeta.Reset();
|
||||
insertTrackMeta.BindInt64(0, this->id);
|
||||
insertTrackMeta.BindInt64(1, valueId);
|
||||
insertTrackMeta.Step();
|
||||
insertTrackMeta.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +207,14 @@ bool TaglibMetadataReader::GetID3v2Tag(const char* uri, musik::core::sdk::ITrack
|
||||
|
||||
this->SetTagValue("album", id3v2->album(), track);
|
||||
|
||||
//{
|
||||
// TagLib::Map<TagLib::ByteVector, TagLib::ID3v2::FrameList>::Iterator it = allTags.begin();
|
||||
// while (it != allTags.end()) {
|
||||
// const char* f = it->first.data();
|
||||
// ++it;
|
||||
// }
|
||||
//}
|
||||
|
||||
/* year */
|
||||
|
||||
if (!allTags["TYER"].isEmpty()) { /* ID3v2.3*/
|
||||
@ -217,6 +225,10 @@ bool TaglibMetadataReader::GetID3v2Tag(const char* uri, musik::core::sdk::ITrack
|
||||
this->SetTagValue("year", allTags["TDRC"].front()->toString().substr(0, 4), track);
|
||||
}
|
||||
|
||||
if (!allTags["TCOP"].isEmpty()) { /* ID3v2.3*/
|
||||
this->SetTagValue("year", allTags["TDRC"].front()->toString().substr(0, 4), track);
|
||||
}
|
||||
|
||||
/* TRCK is the track number (or "trackNum/totalTracks") */
|
||||
|
||||
std::vector<std::string> splitTrack;
|
||||
|
Loading…
x
Reference in New Issue
Block a user