diff --git a/src/infoplugins/generic/musixmatch/MusixMatchPlugin.cpp b/src/infoplugins/generic/musixmatch/MusixMatchPlugin.cpp index 272ff5822..53223a2b9 100644 --- a/src/infoplugins/generic/musixmatch/MusixMatchPlugin.cpp +++ b/src/infoplugins/generic/musixmatch/MusixMatchPlugin.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "utils/TomahawkUtils.h" #include "utils/Logger.h" @@ -32,32 +33,35 @@ using namespace Tomahawk::InfoSystem; MusixMatchPlugin::MusixMatchPlugin() : InfoPlugin() - , m_apiKey("61be4ea5aea7dd942d52b2f1311dd9fe") + , m_apiKey( "61be4ea5aea7dd942d52b2f1311dd9fe" ) { - qDebug() << Q_FUNC_INFO; + tDebug() << Q_FUNC_INFO; m_supportedGetTypes << Tomahawk::InfoSystem::InfoTrackLyrics; } + MusixMatchPlugin::~MusixMatchPlugin() { qDebug() << Q_FUNC_INFO; } + void MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { - qDebug() << Q_FUNC_INFO; - if( !isValidTrackData( requestData ) || !requestData.input.canConvert< QVariantMap >() || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics ) + tDebug() << Q_FUNC_INFO; + if( !isValidTrackData( requestData ) || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics ) return; - QVariantMap hash = requestData.input.value< QVariantMap >(); - QString artist = hash["artistName"].toString(); - QString track = hash["trackName"].toString(); + InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); + + QString artist = hash["artist"]; + QString track = hash["track"]; if( artist.isEmpty() || track.isEmpty() ) { emit info( requestData, QVariant() ); return; } - qDebug() << "artist is " << artist << ", track is " << track; + tDebug() << "artist is " << artist << ", track is " << track; QString requestString( "http://api.musixmatch.com/ws/1.1/track.search?format=xml&page_size=1&f_has_lyrics=1" ); QUrl url( requestString ); url.addQueryItem( "apikey", m_apiKey ); @@ -69,36 +73,40 @@ MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) ); } + bool MusixMatchPlugin::isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData ) { - qDebug() << Q_FUNC_INFO; - if ( requestData.input.isNull() || !requestData.input.isValid() || !requestData.input.canConvert< QVariantMap >() ) + tDebug() << Q_FUNC_INFO; + + if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) { emit info( requestData, QVariant() ); - qDebug() << "MusixMatchPlugin::isValidTrackData: Data null, invalid, or can't convert"; + tDebug() << "MusixMatchPlugin::isValidTrackData: Data null, invalid, or can't convert" << requestData.input.isNull() << requestData.input.isValid() << requestData.input.canConvert< QVariantMap >(); return false; } - QVariantMap hash = requestData.input.value< QVariantMap >(); - if ( hash[ "trackName" ].toString().isEmpty() ) + InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); + + if ( hash[ "track" ].isEmpty() ) { emit info( requestData, QVariant() ); - qDebug() << "MusixMatchPlugin::isValidTrackData: Track name is empty"; + tDebug() << "MusixMatchPlugin::isValidTrackData: Track name is empty"; return false; } - if ( hash[ "artistName" ].toString().isEmpty() ) + if ( hash[ "artist" ].isEmpty() ) { emit info( requestData, QVariant() ); - qDebug() << "MusixMatchPlugin::isValidTrackData: No artist name found"; + tDebug() << "MusixMatchPlugin::isValidTrackData: No artist name found"; return false; } return true; } + void MusixMatchPlugin::trackSearchSlot() { - qDebug() << Q_FUNC_INFO; + tDebug() << Q_FUNC_INFO; QNetworkReply* oldReply = qobject_cast( sender() ); if ( !oldReply ) return; //timeout will handle it @@ -122,10 +130,11 @@ MusixMatchPlugin::trackSearchSlot() connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) ); } + void MusixMatchPlugin::trackLyricsSlot() { - qDebug() << Q_FUNC_INFO; + tDebug() << Q_FUNC_INFO; QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); if ( !reply ) return; //timeout will handle it @@ -139,6 +148,8 @@ MusixMatchPlugin::trackLyricsSlot() return; } QString lyrics = domNodeList.at(0).toElement().text(); - qDebug() << "Emitting lyrics: " << lyrics; emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant( lyrics ) ); } + + +Q_EXPORT_PLUGIN2( Tomahawk::InfoSystem::InfoPlugin, Tomahawk::InfoSystem::MusixMatchPlugin ) diff --git a/src/infoplugins/generic/musixmatch/MusixMatchPlugin.h b/src/infoplugins/generic/musixmatch/MusixMatchPlugin.h index 038f74df6..3f3557f8a 100644 --- a/src/infoplugins/generic/musixmatch/MusixMatchPlugin.h +++ b/src/infoplugins/generic/musixmatch/MusixMatchPlugin.h @@ -22,6 +22,7 @@ #include "infosystem/InfoSystem.h" #include "infosystem/InfoSystemWorker.h" +#include "infoplugins/InfoPluginDllMacro.h" class QNetworkReply; @@ -31,9 +32,10 @@ namespace Tomahawk namespace InfoSystem { -class MusixMatchPlugin : public InfoPlugin +class INFOPLUGINDLLEXPORT MusixMatchPlugin : public InfoPlugin { Q_OBJECT + Q_INTERFACES( Tomahawk::InfoSystem::InfoPlugin ) public: MusixMatchPlugin();