mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
Support album and artist results in JSResolvers
This commit is contained in:
@@ -563,15 +563,18 @@ JSResolver::onResolveRequestDone( const QVariantMap& data )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
QList< artist_ptr > artists = scriptAccount()->parseArtistVariantList( data.value( "artists" ).toList() );
|
||||||
|
Tomahawk::Pipeline::instance()->reportArtists( qid, artists );
|
||||||
|
|
||||||
|
QList< album_ptr > albums = scriptAccount()->parseAlbumVariantList( data.value( "albums" ).toList() );
|
||||||
|
Tomahawk::Pipeline::instance()->reportAlbums( qid, albums );
|
||||||
|
|
||||||
QList< Tomahawk::result_ptr > results = scriptAccount()->parseResultVariantList( data.value( "tracks" ).toList() );
|
QList< Tomahawk::result_ptr > results = scriptAccount()->parseResultVariantList( data.value( "tracks" ).toList() );
|
||||||
|
|
||||||
foreach( const result_ptr& result, results )
|
foreach( const result_ptr& result, results )
|
||||||
{
|
{
|
||||||
result->setResolvedByResolver( this );
|
result->setResolvedByResolver( this );
|
||||||
result->setFriendlySource( name() );
|
result->setFriendlySource( name() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Tomahawk::Pipeline::instance()->reportResults( qid, this, results );
|
Tomahawk::Pipeline::instance()->reportResults( qid, this, results );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,6 +32,8 @@
|
|||||||
#include "ScriptInfoPlugin.h"
|
#include "ScriptInfoPlugin.h"
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
#include "../Artist.h"
|
||||||
|
#include "../Album.h"
|
||||||
#include "../Result.h"
|
#include "../Result.h"
|
||||||
#include "../Track.h"
|
#include "../Track.h"
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
@@ -268,6 +270,48 @@ ScriptAccount::onJobDeleted( const QString& jobId )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList< Tomahawk::artist_ptr >
|
||||||
|
ScriptAccount::parseArtistVariantList( const QVariantList& artistList )
|
||||||
|
{
|
||||||
|
QList< Tomahawk::artist_ptr > artists;
|
||||||
|
|
||||||
|
QString artist;
|
||||||
|
foreach( const QVariant& a, artistList )
|
||||||
|
{
|
||||||
|
artist = a.toString().trimmed();
|
||||||
|
if ( artist.isEmpty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
artists << Tomahawk::Artist::get( artist );
|
||||||
|
}
|
||||||
|
|
||||||
|
return artists;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList< Tomahawk::album_ptr >
|
||||||
|
ScriptAccount::parseAlbumVariantList( const QVariantList& albumList )
|
||||||
|
{
|
||||||
|
QList< Tomahawk::album_ptr > albums;
|
||||||
|
|
||||||
|
QString artistString;
|
||||||
|
QString albumString;
|
||||||
|
foreach( const QVariant& av, albumList )
|
||||||
|
{
|
||||||
|
QVariantMap m = av.toMap();
|
||||||
|
|
||||||
|
artistString = m.value( "artist" ).toString().trimmed();
|
||||||
|
albumString = m.value( "album" ).toString().trimmed();
|
||||||
|
if ( artistString.isEmpty() || albumString.isEmpty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
albums << Tomahawk::Album::get( Tomahawk::Artist::get( artistString ), albumString );
|
||||||
|
}
|
||||||
|
|
||||||
|
return albums;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QList< Tomahawk::result_ptr >
|
QList< Tomahawk::result_ptr >
|
||||||
ScriptAccount::parseResultVariantList( const QVariantList& reslist )
|
ScriptAccount::parseResultVariantList( const QVariantList& reslist )
|
||||||
{
|
{
|
||||||
|
@@ -79,6 +79,8 @@ public:
|
|||||||
virtual void showDebugger();
|
virtual void showDebugger();
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
|
QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& artistList );
|
||||||
|
QList< Tomahawk::album_ptr > parseAlbumVariantList( const QVariantList& albumList );
|
||||||
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
||||||
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );
|
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );
|
||||||
|
|
||||||
|
@@ -372,13 +372,18 @@ SearchWidget::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums )
|
|||||||
|
|
||||||
int distance = TomahawkUtils::levenshtein( m_search, album->name() );
|
int distance = TomahawkUtils::levenshtein( m_search, album->name() );
|
||||||
int maxlen = qMax( m_search.length(), album->name().length() );
|
int maxlen = qMax( m_search.length(), album->name().length() );
|
||||||
float score = (float)( maxlen - distance ) / maxlen;
|
float scoreAlbum = (float)( maxlen - distance ) / maxlen;
|
||||||
|
|
||||||
if ( score <= 0.1 )
|
distance = TomahawkUtils::levenshtein( m_search, album->artist()->name() );
|
||||||
|
maxlen = qMax( m_search.length(), album->artist()->name().length() );
|
||||||
|
float scoreArtist = (float)( maxlen - distance ) / maxlen;
|
||||||
|
|
||||||
|
float scoreMax = qMax( scoreAlbum, scoreArtist );
|
||||||
|
if ( scoreMax <= 0.1 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_albums.insert( album, score );
|
m_albums.insert( album, scoreMax );
|
||||||
// tDebug() << Q_FUNC_INFO << "found album:" << album->name() << "score:" << score;
|
// tDebug() << Q_FUNC_INFO << "found album:" << album->name() << "scoreMax:" << scoreMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateAlbums();
|
// updateAlbums();
|
||||||
|
Reference in New Issue
Block a user