Blame SOURCES/0004-Fix-FLAC-Files-Remove-addtional-db-in-replaygain.patch

ee4fba
From 0fb8aee587436663cbb60bf743882c70954f8683 Mon Sep 17 00:00:00 2001
ee4fba
From: Vishesh Handa <handa.vish@gmail.com>
ee4fba
Date: Tue, 14 Feb 2012 21:50:13 +0530
ee4fba
Subject: [PATCH 4/8] Fix FLAC Files: Remove addtional 'db' in replaygain
ee4fba
ee4fba
FLAC files have a parameter named "replaygain" which is in the format "<num> dB",
ee4fba
and because of that Nepomuk cannot parse it as a float.
ee4fba
ee4fba
REVIEW: 103977
ee4fba
---
ee4fba
 lib/endanalyzers/flacendanalyzer.cpp |   41 ++++++++++++++++++++++------------
ee4fba
 1 file changed, 27 insertions(+), 14 deletions(-)
ee4fba
ee4fba
diff --git a/lib/endanalyzers/flacendanalyzer.cpp b/lib/endanalyzers/flacendanalyzer.cpp
ee4fba
index 8877d1d..7e34270 100644
ee4fba
--- a/lib/endanalyzers/flacendanalyzer.cpp
ee4fba
+++ b/lib/endanalyzers/flacendanalyzer.cpp
ee4fba
@@ -124,6 +124,16 @@ addStatement(AnalysisResult& indexable, string& subject, const string& predicate
ee4fba
   indexable.addTriplet(subject, predicate, object);
ee4fba
 }
ee4fba
 
ee4fba
+string
ee4fba
+removeAlphabets(const string& str) {
ee4fba
+    std::string newStr;
ee4fba
+    newStr.reserve(str.length());
ee4fba
+    for( int i=0; i
ee4fba
+        if( !isalpha(str[i]) )
ee4fba
+            newStr.push_back( str[i] );
ee4fba
+    return newStr;
ee4fba
+}
ee4fba
+
ee4fba
 signed char
ee4fba
 FlacEndAnalyzer::analyze(Strigi::AnalysisResult& indexable, Strigi::InputStream* in) {
ee4fba
     if(!in)
ee4fba
@@ -225,20 +235,22 @@ FlacEndAnalyzer::analyze(Strigi::AnalysisResult& indexable, Strigi::InputStream*
ee4fba
 		    // check if we can handle this field and if so handle it
ee4fba
 		    map<string, const RegisteredField*>::const_iterator iter
ee4fba
 			= factory->fields.find(name);
ee4fba
-		    const string value(p2+eq+1, size-eq-1);
ee4fba
+		    string value(p2+eq+1, size-eq-1);
ee4fba
 		    
ee4fba
 		    if (iter != factory->fields.end()) {
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
+                // 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
+                    if(name == "replaygain_track_gain")
ee4fba
+                        value = removeAlphabets(value);
ee4fba
+                    indexable.addValue(iter->second, value);
ee4fba
+                }
ee4fba
 		    } else if(name=="artist") {
ee4fba
                         artist = value;
ee4fba
 		    } else if(name=="lyrics") {
ee4fba
@@ -256,9 +268,10 @@ FlacEndAnalyzer::analyze(Strigi::AnalysisResult& indexable, Strigi::InputStream*
ee4fba
 		    } else if(name=="trackcount") {
ee4fba
 			addStatement(indexable, albumUri, albumTrackCountPropertyName, value);
ee4fba
 		    } else if(name=="replaygain_album_gain") {
ee4fba
-			addStatement(indexable, albumUri, albumGainPropertyName, value);
ee4fba
+			// the gain is often in the form "number dB", the appending "dB" must be removed
ee4fba
+			addStatement(indexable, albumUri, albumGainPropertyName, removeAlphabets(value));
ee4fba
 		    } else if(name=="replaygain_album_peak") {
ee4fba
-			addStatement(indexable, albumUri, albumPeakGainPropertyName, value);
ee4fba
+			addStatement(indexable, albumUri, albumPeakGainPropertyName, removeAlphabets(value));
ee4fba
 		    } else if(name=="composer") {
ee4fba
 			const string composerUri( indexable.newAnonymousUri() );
ee4fba
 
ee4fba
-- 
ee4fba
1.7.10.4
ee4fba