From 92df13d9b5fab8259a85315eb2c277546d20d4a6 Mon Sep 17 00:00:00 2001 From: Sebastian Trueg Date: Fri, 10 Feb 2012 13:31:31 +0100 Subject: [PATCH 2/8] Extract tracknumber and track count from a value like "03/16". REVIEW: 103911 --- lib/endanalyzers/flacendanalyzer.cpp | 16 +++++++++++-- lib/throughanalyzers/oggthroughanalyzer.cpp | 33 ++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/endanalyzers/flacendanalyzer.cpp b/lib/endanalyzers/flacendanalyzer.cpp index c043872..8877d1d 100644 --- a/lib/endanalyzers/flacendanalyzer.cpp +++ b/lib/endanalyzers/flacendanalyzer.cpp @@ -52,6 +52,8 @@ const string NMM_DRAFT "musicBrainzAlbumID"), discNumberPropertyName( NMM_DRAFT "setNumber"), + albumTrackCountName( + NMM_DRAFT "albumTrackCount"), musicClassName( NMM_DRAFT "MusicPiece"), @@ -226,7 +228,17 @@ FlacEndAnalyzer::analyze(Strigi::AnalysisResult& indexable, Strigi::InputStream* const string value(p2+eq+1, size-eq-1); if (iter != factory->fields.end()) { - indexable.addValue(iter->second, value); + // Hack: the tracknumber sometimes contains the track count, too + int pos = 0; + if(name=="tracknumber" && (pos = value.find_first_of('/')) > 0 ) { + // the track number + indexable.addValue(iter->second, value.substr(0, pos)); + // the track count + addStatement(indexable, albumUri, albumTrackCountName, value.substr(pos+1)); + } + else { + indexable.addValue(iter->second, value); + } } else if(name=="artist") { artist = value; } else if(name=="lyrics") { @@ -261,7 +273,7 @@ FlacEndAnalyzer::analyze(Strigi::AnalysisResult& indexable, Strigi::InputStream* indexable.addTriplet(publisherUri, fullnamePropertyName, value); } else if(name=="performer") { performer = value; - } + } } } else { m_error = "problem with tag size"; diff --git a/lib/throughanalyzers/oggthroughanalyzer.cpp b/lib/throughanalyzers/oggthroughanalyzer.cpp index 26faa15..741b28e 100644 --- a/lib/throughanalyzers/oggthroughanalyzer.cpp +++ b/lib/throughanalyzers/oggthroughanalyzer.cpp @@ -37,6 +37,8 @@ const string "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#fullname"), titlePropertyName( "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title"), + albumTrackCountName( + NMM_DRAFT "albumTrackCount"), musicClassName( NMM_DRAFT "MusicPiece"), @@ -68,6 +70,14 @@ OggThroughAnalyzerFactory::registerFields(FieldRegister& r) { fields["type"] = r.typeField; } +inline +void +addStatement(AnalysisResult* indexable, string& subject, const string& predicate, const string& object) { + if (subject.empty()) + subject = indexable->newAnonymousUri(); + indexable->addTriplet(subject, predicate, object); +} + void OggThroughAnalyzer::setIndexable(AnalysisResult* i) { indexable = i; @@ -129,6 +139,7 @@ OggThroughAnalyzer::connectInputStream(InputStream* in) { // but for the composer in calssical music. Thus, we cache both and make the decision // at the end string artist, performer; + string albumUri; // read all the comments p2 += 4; @@ -151,15 +162,21 @@ OggThroughAnalyzer::connectInputStream(InputStream* in) { = factory->fields.find(name); string value(p2+eq+1, size-eq-1); if (iter != factory->fields.end()) { - indexable->addValue(iter->second, value); + // Hack: the tracknumber sometimes contains the track count, too + int pos = 0; + if(name=="tracknumber" && (pos = value.find_first_of('/')) > 0 ) { + // the track number + indexable->addValue(iter->second, value.substr(0, pos)); + // the track count + addStatement(indexable, albumUri, albumTrackCountName, value.substr(pos+1)); + } + else { + indexable->addValue(iter->second, value); + } } else if(name=="artist") { artist = value; } else if(name=="album") { - string albumUri = indexable->newAnonymousUri(); - - indexable->addValue(factory->albumField, albumUri); - indexable->addTriplet(albumUri, typePropertyName, albumClassName); - indexable->addTriplet(albumUri, titlePropertyName, value); + addStatement(indexable, albumUri, titlePropertyName, value); } else if(name=="composer") { string composerUri = indexable->newAnonymousUri(); @@ -206,6 +223,10 @@ OggThroughAnalyzer::connectInputStream(InputStream* in) { indexable->addTriplet(performerUri, typePropertyName, contactClassName); indexable->addTriplet(performerUri, fullnamePropertyName, performer); } + if(!albumUri.empty()) { + indexable->addValue(factory->albumField, albumUri); + indexable->addTriplet(albumUri, typePropertyName, albumClassName); + } // set the "codec" value indexable->addValue(factory->fields.find("codec")->second, "Ogg/Vorbis"); -- 1.7.10.4