1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Initial attempt at resulthint checker

This commit is contained in:
Leo Franchi
2012-09-20 10:32:57 -04:00
parent 13fbfb0aa1
commit 12d36079f3
8 changed files with 146 additions and 9 deletions

View File

@@ -115,6 +115,7 @@ set( libGuiSources
utils/BinaryInstallerHelper.cpp
utils/BinaryExtractWorker.cpp
utils/SharedTimeLine.cpp
utils/WebResultHintChecker.cpp
widgets/AnimatedCounterLabel.cpp
widgets/Breadcrumb.cpp

View File

@@ -524,8 +524,8 @@ Playlist::setRevision( const QString& rev,
foreach( const plentry_ptr& entry, m_entries )
{
connect( entry->query().data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ),
SLOT( onResultsFound( QList<Tomahawk::result_ptr> ) ), Qt::UniqueConnection );
connect( entry->query().data(), SIGNAL( resultsChanged() ),
SLOT( onResultsChanged() ), Qt::UniqueConnection );
}
setBusy( false );
@@ -620,9 +620,8 @@ Playlist::resolve()
void
Playlist::onResultsFound( const QList<Tomahawk::result_ptr>& results )
Playlist::onResultsChanged()
{
Q_UNUSED( results );
m_locallyChanged = true;
}

View File

@@ -293,7 +293,7 @@ protected:
private slots:
void onResultsFound( const QList<Tomahawk::result_ptr>& results );
void onResultsChanged();
void onResolvingFinished();
void onDeleteResult( SourceTreePopupDialog* );

View File

@@ -36,6 +36,7 @@
#include "audio/AudioEngine.h"
#include "utils/Logger.h"
#include "utils/WebResultHintChecker.h"
using namespace Tomahawk;
@@ -772,6 +773,16 @@ Query::socialActionDescription( const QString& action, DescriptionMode mode ) co
}
void
Query::setSaveHTTPResultHint( bool saveResultHint )
{
m_saveResultHint = saveResultHint;
// Make sure it's a valid url
new WebResultHintChecker( m_ownRef.toStrongRef() );
}
#ifndef ENABLE_HEADLESS
QPixmap
Query::cover( const QSize& size, bool forceLoad ) const

View File

@@ -164,7 +164,7 @@ public:
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
void setSaveHTTPResultHint( bool saveResultHint ) { m_saveResultHint = saveResultHint; }
void setSaveHTTPResultHint( bool saveResultHint );
bool saveHTTPResultHint() const { return m_saveResultHint; }
QList<Tomahawk::query_ptr> similarTracks() const;

View File

@@ -103,9 +103,9 @@ SoundcloudParser::parseTrack( const QVariantMap& res )
if ( !q.isNull() )
{
tLog() << "Setting resulthint to " << res.value( "stream_url" );
q->setResultHint( res.value( "trackuri" ).toString() + "&client_id=TiNg2DRYhBnp01DA3zNag" );
q->setProperty( "annotation", res.value( "trackuri" ).toString() + "&client_id=TiNg2DRYhBnp01DA3zNag" );
tLog() << "Setting resulthint to " << res.value( "stream_url" ) << res;
q->setResultHint( res.value( "stream_url" ).toString() + "?client_id=TiNg2DRYhBnp01DA3zNag" );
q->setSaveHTTPResultHint( true );
m_tracks << q;
}

View File

@@ -0,0 +1,79 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WebResultHintChecker.h"
#include "Query.h"
#include "Result.h"
#include "Source.h"
#include "utils/Closure.h"
#include "utils/Logger.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
using namespace Tomahawk;
WebResultHintChecker::WebResultHintChecker( const query_ptr& q )
: QObject( 0 )
, m_query( q )
{
m_url = q->resultHint();
foreach ( const result_ptr& result, q->results() )
{
if ( result->url() == m_url )
{
m_result = result;
break;
}
}
// Nothing to do
if ( m_url.isEmpty() || !m_url.startsWith( "http" ) )
{
deleteLater();
return;
}
QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( QUrl( m_url ) ) );
NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ) );
}
WebResultHintChecker::~WebResultHintChecker()
{
}
void
WebResultHintChecker::headFinished( QNetworkReply* reply )
{
if ( reply->error() != QNetworkReply::NoError )
{
// Error getting headers for the http resulthint, remove it from the result
// as it's definitely not playable
tLog() << "Removing HTTP result from query since HEAD request failed to verify it was a valid url:" << m_url;
if ( !m_result.isNull() )
m_query->removeResult( m_result );
if ( m_query->resultHint() == m_url )
m_query->setResultHint( QString() );
}
reply->deleteLater();
deleteLater();
}

View File

@@ -0,0 +1,47 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WEB_RESULT_HINT_CHECKER_H
#define WEB_RESULT_HINT_CHECKER_H
#include "Typedefs.h"
#include <QObject>
class QNetworkReply;
namespace Tomahawk {
class WebResultHintChecker : public QObject
{
Q_OBJECT
public:
WebResultHintChecker( const query_ptr& q );
virtual ~WebResultHintChecker();
private slots:
void headFinished( QNetworkReply* reply );
private:
query_ptr m_query;
result_ptr m_result;
QString m_url;
};
}
#endif