Fixed taglib bug when id3v2 frames exists but are empty and id3v1 should be read.

Track and TrackMeta do not allow empty strings (unnecessary data).
This commit is contained in:
Daniel Önnerby 2008-05-05 09:27:09 +00:00
parent 86593f5d1e
commit 27071b015b
3 changed files with 28 additions and 15 deletions

View File

@ -104,8 +104,11 @@ bool TagReaderTaglib::ReadTag(musik::core::Track *track){
boost::algorithm::to_lower(ext); // Convert to lower case
if(ext==UTF("mp3"))
if(this->GetID3v2Tag(track))
if(this->GetID3v2Tag(track)){
// Get the generic tag as well, just in case there is only a id3v1 tag.
this->GetGenericTag(track);
return true;
}
if(ext==UTF("ogg"))
if(this->GetOGGTag(track))
@ -149,9 +152,13 @@ bool TagReaderTaglib::GetGenericTag(musik::core::Track *track){
// COMMENT
this->SetTagValue("comment",tag->comment(),track);
// TRACK
this->SetTagValue("track",tag->track(),track);
if(tag->track()){
this->SetTagValue("track",tag->track(),track);
}
// TRACK
this->SetTagValue("year",tag->year(),track);
if(tag->year()){
this->SetTagValue("year",tag->year(),track);
}
this->SetAudioProperties(oAudioProperties,track);
@ -184,8 +191,6 @@ bool TagReaderTaglib::GetID3v2Tag(musik::core::Track *track){
if(!oTagv2->title().isEmpty()){
this->SetTagValue("title",oTagv2->title(),track);
}else{
this->SetTagValue("title",track->GetValue("filename"),track);
}
this->SetTagValue("album",oTagv2->album(),track);

View File

@ -322,14 +322,20 @@ bool Track::Save(db::Connection &dbConnection,utfstring libraryDirectory,DBINT f
DBINT albumId(0);
{
db::CachedStatement stmt("SELECT id FROM albums WHERE name=?",dbConnection);
stmt.BindTextUTF(0,this->GetValue("album"));
const utfchar *album=this->GetValue("album");
if(album==NULL){
album=UTF("");
}
stmt.BindTextUTF(0,album);
if(stmt.Step()==db::ReturnCode::Row){
albumId = stmt.ColumnInt(0);
}else{
// INSERT a new album
db::Statement insertAlbum("INSERT INTO albums (name) VALUES (?)",dbConnection);
insertAlbum.BindTextUTF(0,this->GetValue("album"));
insertAlbum.BindTextUTF(0,album);
if(insertAlbum.Step()==db::ReturnCode::Done){
albumId = dbConnection.LastInsertedId();
}

View File

@ -121,15 +121,17 @@ TrackMeta::TagMapIteratorPair TrackMeta::GetValues(const char* metakey) const{
}
void TrackMeta::SetValue(const TrackMeta::Key &key,const TrackMeta::Value &value){
if(this->library){
// Threadsafe
boost::mutex::scoped_lock lock(library->libraryMutex);
this->tags.insert( TrackMeta::TagMapPair(key,value) );
return;
}
if(!value.empty()){
if(this->library){
// Threadsafe
boost::mutex::scoped_lock lock(library->libraryMutex);
this->tags.insert( TrackMeta::TagMapPair(key,value) );
return;
}
// Non threadsafe
this->tags.insert( TrackMeta::TagMapPair(key,value) );
// Non threadsafe
this->tags.insert( TrackMeta::TagMapPair(key,value) );
}
}
const TrackMeta::Value& TrackMeta::_GetValue(const TrackMeta::Key &key) const{