Blame SOURCES/0002-Extract-tracknumber-and-track-count-from-a-value-lik.patch

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