1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Adapt to new libechonest v2 api

This commit is contained in:
Leo Franchi
2012-07-20 13:01:59 -04:00
parent 11bcdc9cb9
commit b0b7aa426d

View File

@@ -134,6 +134,13 @@ EchonestGenerator::EchonestGenerator ( QObject* parent )
EchonestGenerator::~EchonestGenerator() EchonestGenerator::~EchonestGenerator()
{ {
if ( !m_dynPlaylist->sessionId().isNull() )
{
// Running session, delete it
QNetworkReply* deleteReply = m_dynPlaylist->deleteSession();
connect( deleteReply, SIGNAL( finished() ), deleteReply, SLOT( deleteLater() ) );
}
delete m_dynPlaylist; delete m_dynPlaylist;
} }
@@ -194,6 +201,13 @@ EchonestGenerator::generate( int number )
void void
EchonestGenerator::startOnDemand() EchonestGenerator::startOnDemand()
{ {
if ( !m_dynPlaylist->sessionId().isNull() )
{
// Running session, delete it
QNetworkReply* deleteReply = m_dynPlaylist->deleteSession();
connect( deleteReply, SIGNAL( finished() ), deleteReply, SLOT( deleteLater() ) );
}
connect( this, SIGNAL( paramsGenerated( Echonest::DynamicPlaylist::PlaylistParams ) ), this, SLOT( doStartOnDemand( Echonest::DynamicPlaylist::PlaylistParams ) ) ); connect( this, SIGNAL( paramsGenerated( Echonest::DynamicPlaylist::PlaylistParams ) ), this, SLOT( doStartOnDemand( Echonest::DynamicPlaylist::PlaylistParams ) ) );
try { try {
getParams(); getParams();
@@ -225,7 +239,7 @@ EchonestGenerator::doStartOnDemand( const Echonest::DynamicPlaylist::PlaylistPar
{ {
disconnect( this, SIGNAL( paramsGenerated( Echonest::DynamicPlaylist::PlaylistParams ) ), this, SLOT( doStartOnDemand( Echonest::DynamicPlaylist::PlaylistParams ) ) ); disconnect( this, SIGNAL( paramsGenerated( Echonest::DynamicPlaylist::PlaylistParams ) ), this, SLOT( doStartOnDemand( Echonest::DynamicPlaylist::PlaylistParams ) ) );
QNetworkReply* reply = m_dynPlaylist->start( params ); QNetworkReply* reply = m_dynPlaylist->create( params );
qDebug() << "starting a dynamic playlist from echonest!" << reply->url().toString(); qDebug() << "starting a dynamic playlist from echonest!" << reply->url().toString();
connect( reply, SIGNAL( finished() ), this, SLOT( dynamicStarted() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( dynamicStarted() ) );
} }
@@ -240,14 +254,15 @@ EchonestGenerator::fetchNext( int rating )
return; return;
} }
QNetworkReply* reply; if ( rating > -1 )
if( m_steeredSinceLastTrack ) { {
qDebug() << "Steering dynamic playlist!" << m_steerData.first << m_steerData.second; Echonest::DynamicPlaylist::DynamicFeedback feedback;
reply = m_dynPlaylist->fetchNextSong( Echonest::DynamicPlaylist::DynamicControls() << m_steerData ); feedback.append( Echonest::DynamicPlaylist::DynamicFeedbackParamData( Echonest::DynamicPlaylist::RateSong, QString( "last^%1").arg( rating * 2 ).toUtf8() ) );
m_steeredSinceLastTrack = false; QNetworkReply* reply = m_dynPlaylist->feedback( feedback );
} else { connect( reply, SIGNAL( finished() ), reply, SLOT( deleteLater() ) ); // we don't care about the result, just send it off
reply = m_dynPlaylist->fetchNextSong( rating );
} }
QNetworkReply* reply = m_dynPlaylist->next( 1, 0 );
qDebug() << "getting next song from echonest" << reply->url().toString(); qDebug() << "getting next song from echonest" << reply->url().toString();
connect( reply, SIGNAL( finished() ), this, SLOT( dynamicFetched() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( dynamicFetched() ) );
} }
@@ -369,9 +384,8 @@ EchonestGenerator::dynamicStarted()
try try
{ {
Echonest::Song song = m_dynPlaylist->parseStart( reply ); m_dynPlaylist->parseCreate( reply );
query_ptr songQuery = queryFromSong( song ); fetchNext();
emit nextTrackGenerated( songQuery );
} catch( const Echonest::ParseError& e ) { } catch( const Echonest::ParseError& e ) {
qWarning() << "libechonest threw an error parsing the start of the dynamic playlist:" << e.errorType() << e.what(); qWarning() << "libechonest threw an error parsing the start of the dynamic playlist:" << e.errorType() << e.what();
emit error( "The Echo Nest returned an error starting the station", e.what() ); emit error( "The Echo Nest returned an error starting the station", e.what() );
@@ -386,12 +400,18 @@ EchonestGenerator::dynamicFetched()
Q_ASSERT( qobject_cast< QNetworkReply* >( sender() ) ); Q_ASSERT( qobject_cast< QNetworkReply* >( sender() ) );
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
resetSteering();
try try
{ {
Echonest::Song song = m_dynPlaylist->parseNextSong( reply ); Echonest::DynamicPlaylist::FetchPair fetched = m_dynPlaylist->parseNext( reply );
query_ptr songQuery = queryFromSong( song );
if ( fetched.first.size() != 1 )
{
qWarning() << "Did not get any track when looking up the next song from the echo nest!";
emit error( "No more songs from The Echo Nest available in the station", "" );
return;
}
query_ptr songQuery = queryFromSong( fetched.first.first() );
emit nextTrackGenerated( songQuery ); emit nextTrackGenerated( songQuery );
} catch( const Echonest::ParseError& e ) { } catch( const Echonest::ParseError& e ) {
qWarning() << "libechonest threw an error parsing the next song of the dynamic playlist:" << e.errorType() << e.what(); qWarning() << "libechonest threw an error parsing the next song of the dynamic playlist:" << e.errorType() << e.what();