mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
* Make MusixMatchPlugin a proper InfoPlugin. Also, fix it up.
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
|
#include <QtPlugin>
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@@ -32,32 +33,35 @@ using namespace Tomahawk::InfoSystem;
|
|||||||
|
|
||||||
MusixMatchPlugin::MusixMatchPlugin()
|
MusixMatchPlugin::MusixMatchPlugin()
|
||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
, m_apiKey("61be4ea5aea7dd942d52b2f1311dd9fe")
|
, m_apiKey( "61be4ea5aea7dd942d52b2f1311dd9fe" )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
m_supportedGetTypes << Tomahawk::InfoSystem::InfoTrackLyrics;
|
m_supportedGetTypes << Tomahawk::InfoSystem::InfoTrackLyrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MusixMatchPlugin::~MusixMatchPlugin()
|
MusixMatchPlugin::~MusixMatchPlugin()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
if( !isValidTrackData( requestData ) || !requestData.input.canConvert< QVariantMap >() || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics )
|
if( !isValidTrackData( requestData ) || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics )
|
||||||
return;
|
return;
|
||||||
QVariantMap hash = requestData.input.value< QVariantMap >();
|
InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||||
QString artist = hash["artistName"].toString();
|
|
||||||
QString track = hash["trackName"].toString();
|
QString artist = hash["artist"];
|
||||||
|
QString track = hash["track"];
|
||||||
if( artist.isEmpty() || track.isEmpty() )
|
if( artist.isEmpty() || track.isEmpty() )
|
||||||
{
|
{
|
||||||
emit info( requestData, QVariant() );
|
emit info( requestData, QVariant() );
|
||||||
return;
|
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" );
|
QString requestString( "http://api.musixmatch.com/ws/1.1/track.search?format=xml&page_size=1&f_has_lyrics=1" );
|
||||||
QUrl url( requestString );
|
QUrl url( requestString );
|
||||||
url.addQueryItem( "apikey", m_apiKey );
|
url.addQueryItem( "apikey", m_apiKey );
|
||||||
@@ -69,36 +73,40 @@ MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
|||||||
connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MusixMatchPlugin::isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData )
|
MusixMatchPlugin::isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
if ( requestData.input.isNull() || !requestData.input.isValid() || !requestData.input.canConvert< QVariantMap >() )
|
|
||||||
|
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||||
{
|
{
|
||||||
emit info( requestData, QVariant() );
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
QVariantMap hash = requestData.input.value< QVariantMap >();
|
InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||||
if ( hash[ "trackName" ].toString().isEmpty() )
|
|
||||||
|
if ( hash[ "track" ].isEmpty() )
|
||||||
{
|
{
|
||||||
emit info( requestData, QVariant() );
|
emit info( requestData, QVariant() );
|
||||||
qDebug() << "MusixMatchPlugin::isValidTrackData: Track name is empty";
|
tDebug() << "MusixMatchPlugin::isValidTrackData: Track name is empty";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( hash[ "artistName" ].toString().isEmpty() )
|
if ( hash[ "artist" ].isEmpty() )
|
||||||
{
|
{
|
||||||
emit info( requestData, QVariant() );
|
emit info( requestData, QVariant() );
|
||||||
qDebug() << "MusixMatchPlugin::isValidTrackData: No artist name found";
|
tDebug() << "MusixMatchPlugin::isValidTrackData: No artist name found";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MusixMatchPlugin::trackSearchSlot()
|
MusixMatchPlugin::trackSearchSlot()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
|
QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
|
||||||
if ( !oldReply )
|
if ( !oldReply )
|
||||||
return; //timeout will handle it
|
return; //timeout will handle it
|
||||||
@@ -122,10 +130,11 @@ MusixMatchPlugin::trackSearchSlot()
|
|||||||
connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MusixMatchPlugin::trackLyricsSlot()
|
MusixMatchPlugin::trackLyricsSlot()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
||||||
if ( !reply )
|
if ( !reply )
|
||||||
return; //timeout will handle it
|
return; //timeout will handle it
|
||||||
@@ -139,6 +148,8 @@ MusixMatchPlugin::trackLyricsSlot()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString lyrics = domNodeList.at(0).toElement().text();
|
QString lyrics = domNodeList.at(0).toElement().text();
|
||||||
qDebug() << "Emitting lyrics: " << lyrics;
|
|
||||||
emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant( lyrics ) );
|
emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant( lyrics ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Q_EXPORT_PLUGIN2( Tomahawk::InfoSystem::InfoPlugin, Tomahawk::InfoSystem::MusixMatchPlugin )
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "infosystem/InfoSystem.h"
|
#include "infosystem/InfoSystem.h"
|
||||||
#include "infosystem/InfoSystemWorker.h"
|
#include "infosystem/InfoSystemWorker.h"
|
||||||
|
#include "infoplugins/InfoPluginDllMacro.h"
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
|
||||||
@@ -31,9 +32,10 @@ namespace Tomahawk
|
|||||||
namespace InfoSystem
|
namespace InfoSystem
|
||||||
{
|
{
|
||||||
|
|
||||||
class MusixMatchPlugin : public InfoPlugin
|
class INFOPLUGINDLLEXPORT MusixMatchPlugin : public InfoPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_INTERFACES( Tomahawk::InfoSystem::InfoPlugin )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MusixMatchPlugin();
|
MusixMatchPlugin();
|
||||||
|
Reference in New Issue
Block a user