[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [libechonest] c3906e8: Fix parsing of foreign ids,
From:       Leo Franchi <lfranchi () kde ! org>
Date:       2010-11-24 4:24:01
Message-ID: 20101124042401.CF06AA60A6 () git ! kde ! org
[Download RAW message or body]

commit c3906e8dcbc9b3368dc7d6e60c630eac2ffdf959
branch master
Author: Leo Franchi <lfranchi@kde.org>
Date:   Tue Nov 23 23:23:56 2010 -0500

    Fix parsing of foreign ids, and add a first test
    Also, add a qDebug stream helper

diff --git a/src/Artist.cpp b/src/Artist.cpp
index 4bd13ef..7d64ced 100644
--- a/src/Artist.cpp
+++ b/src/Artist.cpp
@@ -441,7 +441,8 @@ Echonest::Artists Echonest::Artist::parseSearch( QNetworkReply* \
reply ) throw( E  {
     Echonest::Parser::checkForErrors( reply );
     
-    QXmlStreamReader xml( reply->readAll() );
+    QByteArray data = reply->readAll();
+    QXmlStreamReader xml( data );
     
     Echonest::Parser::readStatus( xml );
     
@@ -521,8 +522,6 @@ QByteArray \
Echonest::Artist::searchParamToString(Echonest::Artist::SearchParam p  return \
"reverse";  case Sort:
             return "sort";
-        case IdSpace:
-            return "bucket"; // HACK :(
         default:
             return "";
     }
diff --git a/src/Parsing.cpp b/src/Parsing.cpp
index 59bcfb1..0c0fb09 100644
--- a/src/Parsing.cpp
+++ b/src/Parsing.cpp
@@ -674,12 +674,15 @@ void Echonest::Parser::parseForeignArtistIds( QXmlStreamReader& \
xml, Echonest::A  
     Echonest::ForeignIds ids;
     while( xml.name() != "foreign_ids" || !xml.isEndElement() ) {
+        xml.readNext();
+        xml.readNext(); // get past the enclosing <foreign_id>, or else we'll think \
it's the internal one.  Echonest::ForeignId id;
         while( xml.name() != "foreign_id" || !xml.isEndElement() ) {
-            if( xml.name() == "catalog" )
+            if( xml.name() == "catalog" && xml.isStartElement() )
                 id.catalog = xml.readElementText();
-            else if( xml.name() == "foreign_id" )
+            else if( xml.name() == "foreign_id" && xml.isStartElement() )
                 id.foreign_id = xml.readElementText();
+            
             xml.readNext();
         }
         ids.append( id );
diff --git a/src/TypeInformation.h b/src/TypeInformation.h
index c000252..3c9b473 100644
--- a/src/TypeInformation.h
+++ b/src/TypeInformation.h
@@ -49,8 +49,6 @@ namespace Echonest {
             Terms = 0x0100,
             Urls = 0x200,
             Videos = 0x0400,
-            /// The following is for limiting the artists returned. It describe \
                collections of artists
-            IdSpace = 0x0800,
         };
         Q_DECLARE_FLAGS( ArtistInformationFlags, ArtistInformationFlag )
         
@@ -63,8 +61,8 @@ namespace Echonest {
         
         /**
          * The individual pieces of information to fetch for this artist.
-         *  If IdSpace is included, then the idspaces to return must be set.
-         *  See \c setIdSpaces for more information
+         * 
+         * Use \c setIdSpaces to set an id space for this query.
          */
         ArtistInformationFlags flags() const;
         void setArtistInformationFlags( ArtistInformationFlags flags );
@@ -98,9 +96,6 @@ namespace Echonest {
             ArtistFamiliarity = 0x010,
             ArtistLocation = 0x020,
             
-            /// The following is for limiting the songs returned. It describe \
                collections of songs, by named id space or catalog, for example.
-            IdSpace = 0x040,
-            
             NoInformation = 0x800
         };
         Q_DECLARE_FLAGS( SongInformationFlags, SongInformationFlag )
@@ -114,8 +109,7 @@ namespace Echonest {
         
         /**
          * The individual pieces of information to fetch for this song.
-         *  If IdSpace is included, then the idspaces to return must be set.
-         *  See \c setIdSpaces for more information
+         *  If id spaces are desired,see \c setIdSpaces for more information.
          */
         SongInformationFlags flags() const;
         void setSongInformationFlags( SongInformationFlags flags );
diff --git a/src/Util.cpp b/src/Util.cpp
index f932555..5f2c4e4 100644
--- a/src/Util.cpp
+++ b/src/Util.cpp
@@ -118,3 +118,9 @@ Echonest::CatalogTypes::Action \
Echonest::literalToCatalogUpdateAction(const QByt  
     return Echonest::CatalogTypes::Update;
 }
+
+QDebug Echonest::operator<<(QDebug d, const Echonest::ForeignId& id)
+{
+    return d.maybeSpace() << QString::fromLatin1( "Foreign Id(%1, %2)" ).arg( \
id.catalog ).arg( id.foreign_id ); +}
+
diff --git a/src/Util.h b/src/Util.h
index 78ac6ac..cff4037 100644
--- a/src/Util.h
+++ b/src/Util.h
@@ -17,6 +17,9 @@
 #ifndef ECHONEST_UTIL_H
 #define ECHONEST_UTIL_H
 
+#include "echonest_export.h"
+
+#include <QDebug>
 #include <QVector>
 #include <QUrl>
 
@@ -113,6 +116,8 @@ namespace Echonest
     
     QByteArray catalogUpdateActionToLiteral( CatalogTypes::Action );
     CatalogTypes::Action literalToCatalogUpdateAction( const QByteArray& type );
+    
+    ECHONEST_EXPORT QDebug operator<<(QDebug d, const ForeignId& id);
 }
 
 #endif
diff --git a/tests/ArtistTest.cpp b/tests/ArtistTest.cpp
index 02ccdf2..118558a 100644
--- a/tests/ArtistTest.cpp
+++ b/tests/ArtistTest.cpp
@@ -31,7 +31,7 @@ void ArtistTest::initTestCase()
 }
 
 void ArtistTest::testAudioUrl()
-{ /*
+{ 
     Artist testArtist;
     testArtist.setName( QLatin1String( "FooArtist" ) );
     
@@ -46,13 +46,13 @@ void ArtistTest::testAudioUrl()
     QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/audio?api_key=JGJCRKWLXLBZIFAZB&format=xml&name=FooArtist&results=15&start=5" \
) );  
     testArtist.setName( QString() );
-    testArtist.setId( "ARTIST_ID" );
+    testArtist.setId( "ARH6W4X1187B99274F" );
     reply = testArtist.fetchAudio( 15, -1 );    
-    QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/audio?api_key=JGJCRKWLXLBZIFAZB&format=xml&id=ARTIST_ID&results=15" \
) ); +    QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/audio?api_key=JGJCRKWLXLBZIFAZB&format=xml&id=ARH6W4X1187B99274F&results=15" \
) );  
     testArtist.setName( QLatin1String( "FooArtist" ) );
     reply = testArtist.fetchAudio( 100 );    
-    QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/audio?api_key=JGJCRKWLXLBZIFAZB&format=xml&id=ARTIST_ID&results=100" \
) ); */ +    QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/audio?api_key=JGJCRKWLXLBZIFAZB&format=xml&id=ARH6W4X1187B99274F&results=100" \
) );   }
 
 void ArtistTest::testAudio()
@@ -269,13 +269,13 @@ void ArtistTest::testProfileUrl()
     QNetworkReply* reply = testArtist.fetchProfile( ArtistInformation( \
ArtistInformation::Familiarity | ArtistInformation::Videos | ArtistInformation::Audio \
) );  QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/profile?api_key=JGJCRKWLXLBZIFAZB&format=xml&name=ReallyGoodArtist&bucket=audio&bucket=familiarity&bucket=video" \
) );  
-    ArtistInformation info( ArtistInformation::Biographies | ArtistInformation::News \
| ArtistInformation::Reviews | ArtistInformation::Terms | ArtistInformation::Urls | \
ArtistInformation::IdSpace ); +    ArtistInformation info( \
ArtistInformation::Biographies | ArtistInformation::News | ArtistInformation::Reviews \
| ArtistInformation::Terms | ArtistInformation::Urls );  info.setIdSpaces( \
QStringList() << QLatin1String( "musicbrainz" ) );  reply = testArtist.fetchProfile( \
info );  
     QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/profile?api_key=JGJCRKWLXLBZIFAZB&format= \
xml&name=ReallyGoodArtist&bucket=biographies&bucket=news&bucket=reviews&bucket=terms&bucket=urls&bucket=id:musicbrainz" \
) );  
-    info.setArtistInformationFlags( ArtistInformation::Blogs | \
ArtistInformation::Hotttnesss | ArtistInformation::Images  | \
ArtistInformation::IdSpace ); +    info.setArtistInformationFlags( \
ArtistInformation::Blogs | ArtistInformation::Hotttnesss | ArtistInformation::Images \
                );
     info.setIdSpaces( QStringList() << QLatin1String( "7digital" )  << \
QLatin1String( "playme" ) );  reply = testArtist.fetchProfile( info );
     QVERIFY( reply->url().toString() == QLatin1String( \
"http://developer.echonest.com/api/v4/artist/profile?api_key=JGJCRKWLXLBZIFAZB&format= \
xml&name=ReallyGoodArtist&bucket=blogs&bucket=hotttnesss&bucket=images&bucket=id:7digital&bucket=id:playme" \
) ); @@ -379,7 +379,7 @@ void ArtistTest::testSearch()
     params.append( Artist::SearchParamEntry( Artist::Description, QLatin1String( \
                "stadium rock" ) ) );
     params.append( Artist::SearchParamEntry( Artist::FuzzyMatch, true ) );
     searchResult = Artist::search( params, ArtistInformation( \
ArtistInformation::Familiarity | ArtistInformation::Hotttnesss | \
                ArtistInformation::News | ArtistInformation::Blogs | \
                ArtistInformation::Audio ) );
-    qDebug() << "Querying:" << searchResult->url().toString();
+//     qDebug() << "Querying:" << searchResult->url().toString();
     QEventLoop loop2;
     loop2.connect( searchResult, SIGNAL(finished()), SLOT(quit()) );
     loop2.exec();
@@ -398,6 +398,28 @@ void ArtistTest::testSearch()
             QVERIFY( artist.audio().size() > 0 );
         count++;
     }
+    
+    ArtistInformation info( ArtistInformation::Familiarity | \
ArtistInformation::Hotttnesss ); +    info.setIdSpaces( QStringList() << \
QLatin1String( "musicbrainz" ) ); +    params.clear();
+    params.append( Artist::SearchParamEntry( Artist::Description, QLatin1String( \
"alternative rock" ) ) ); +    params.append( Artist::SearchParamEntry( \
Artist::Description, QLatin1String( "stadium rock" ) ) ); +    params.append( \
Artist::SearchParamEntry( Artist::Description, QLatin1String( "melodic^2" ) ) ); +    \
searchResult = Artist::search( params, info, true ); +    qDebug() << "reply:" << \
searchResult->url().toString(); +    QEventLoop loop3;
+    loop3.connect( searchResult, SIGNAL(finished()), SLOT(quit()) );
+    loop3.exec();
+    
+    artists = Echonest::Artist::parseSearch( searchResult );
+    foreach( const Echonest::Artist& artist, artists ) {
+        QVERIFY( !artist.foreignIds().isEmpty() );
+        foreach( const Echonest::ForeignId& id, artist.foreignIds() ) {
+            QVERIFY( !id.catalog.isEmpty() );
+            QVERIFY( !id.foreign_id.isEmpty() );
+        }
+//         qDebug() << "foreign ids:" << artist.foreignIds();
+    }
 }
 
 void ArtistTest::testSimilarUrl()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic