1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

Merge branch 'master' of git://github.com/tomahawk-player/tomahawk

This commit is contained in:
Kilian Lackhove 2012-09-12 16:37:29 +02:00
commit 47aab91ac5
28 changed files with 862 additions and 44 deletions

BIN
data/images/exfm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
data/images/soundcloud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -842,8 +842,8 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>رقم القرص:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3181,7 +3181,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>خطأ شبكة في تحليل تقصير الرابط!</translation>
</message>

View File

@ -844,8 +844,8 @@ Tomahaw създаде доклад относно това и изпращай
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Диск, номер</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3189,7 +3189,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Мрежова грешка при извличане на съкратеният адрес.</translation>
</message>

View File

@ -841,7 +841,7 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
@ -3179,7 +3179,7 @@ Intenteu ajustar els filtres per reproduir noves cançons.</translation>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Error de la xarxa en analitzar l&apos;enllaç escurçat!</translation>
</message>

View File

@ -842,8 +842,8 @@ erlauben sich mit dir zu verbinden?</translation>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Disc Nummer:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3178,7 +3178,7 @@ Versuch die Filter anzupassen für neue Lieder.</translation>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Konnte den Kurzlink nicht auflösen!</translation>
</message>

View File

@ -842,8 +842,8 @@ connect and stream from you?</translation>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Disc Number:</translation>
<source>Track Number:</source>
<translation>Track Number:</translation>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3183,7 +3183,7 @@ Try tweaking the filters for a new set of songs to play.</translation>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Network error parsing shortened link!</translation>
</message>

View File

@ -841,7 +841,7 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
@ -3178,7 +3178,7 @@ Intente ajustar los filtros para reproducir nuevas canciones.</translation>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Error en la red al analizar el enlace acortado!</translation>
</message>

View File

@ -842,8 +842,8 @@ de se connecter et streamer de vous?</translation>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Numéro Du Disque:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3180,7 +3180,7 @@ Essayez de changer les filtres pour avoir de nouveaux morceaux à jouer.</transl
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Erreur réseau lors du décodage de l&apos;URL courte!</translation>
</message>

View File

@ -842,8 +842,8 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3180,7 +3180,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -841,8 +841,8 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Disko numeris:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3171,7 +3171,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -841,7 +841,7 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
@ -3173,7 +3173,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -842,8 +842,8 @@ se conecte e faça o stream de você?</translation>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Número do Disco:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3180,7 +3180,7 @@ Tente ajustar os filtros para ouvir um novo conjunto de músicas.</translation>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation>Erro de rede ao analisar o encurtador de link!</translation>
</message>

View File

@ -842,8 +842,8 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation>Номер диска:</translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3178,7 +3178,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -841,7 +841,7 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
@ -3172,7 +3172,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -841,7 +841,7 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
@ -3171,7 +3171,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -841,8 +841,8 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<translation></translation>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="119"/>
@ -3181,7 +3181,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation></translation>
</message>

View File

@ -841,7 +841,7 @@ connect and stream from you?</source>
</message>
<message>
<location filename="../src/libtomahawk/filemetadata/MetadataEditor.ui" line="90"/>
<source>Disc Number:</source>
<source>Track Number:</source>
<translation type="unfinished"/>
</message>
<message>
@ -3171,7 +3171,7 @@ Try tweaking the filters for a new set of songs to play.</source>
<context>
<name>Tomahawk::ShortenedLinkParser</name>
<message>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="99"/>
<location filename="../src/libtomahawk/utils/ShortenedLinkParser.cpp" line="100"/>
<source>Network error parsing shortened link!</source>
<translation type="unfinished"/>
</message>

View File

@ -153,5 +153,7 @@
<file>data/images/add-contact.png</file>
<file>data/images/account-none.png</file>
<file>data/images/green-dot.png</file>
<file>data/images/exfm.png</file>
<file>data/images/soundcloud.png</file>
</qresource>
</RCC>

View File

@ -102,6 +102,8 @@ set( libGuiSources
utils/ItunesParser.cpp
utils/RdioParser.cpp
utils/ShortenedLinkParser.cpp
utils/SoundcloudParser.cpp
utils/ExfmParser.cpp
utils/StyleHelper.cpp
utils/DropJobNotifier.cpp
utils/ProxyStyle.cpp

View File

@ -30,6 +30,8 @@
#include "utils/RdioParser.h"
#include "utils/M3uLoader.h"
#include "utils/ShortenedLinkParser.h"
#include "utils/SoundcloudParser.h"
#include "utils/ExfmParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include "GlobalActionManager.h"
@ -128,6 +130,12 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( url.contains( "spotify" ) && url.contains( "playlist" ) && s_canParseSpotifyPlaylists )
return true;
if( url.contains( "soundcloud" ) && url.contains( "sets" ) )
return true;
if( url.contains( "ex.fm" ) && !url.contains( "/song/" ) ) // We treat everything but song as playlist
return true;
if ( url.contains( "grooveshark.com" ) && url.contains( "playlist" ) )
return true;
}
@ -146,6 +154,12 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( url.contains( "spotify" ) && url.contains( "track" ) )
return true;
if ( url.contains( "ex.fm" ) && url.contains( "/song/" ) )
return true;
if( url.contains( "soundcloud" ) )
return true;
if ( url.contains( "rdio.com" ) && ( ( ( url.contains( "track" ) && url.contains( "artist" ) && url.contains( "album" ) )
|| url.contains( "playlists" ) ) ) )
return true;
@ -159,6 +173,8 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
return true;
if ( url.contains( "rdio.com" ) && ( url.contains( "artist" ) && url.contains( "album" ) && !url.contains( "track" ) ) )
return true;
if ( url.contains( "ex.fm" ) && url.contains( "site" ) && url.contains( "album" ) )
return true;
}
if ( acceptedType.testFlag( Artist ) )
@ -169,6 +185,8 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
return true;
if ( url.contains( "rdio.com" ) && ( url.contains( "artist" ) && !url.contains( "album" ) && !url.contains( "track" ) ) )
return true;
if( url.contains( "soundcloud" ) )
return true;
}
// We whitelist certain url-shorteners since they do some link checking. Often playable (e.g. spotify) links hide behind them,
@ -196,6 +214,12 @@ DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
if ( url.contains( "spotify" ) && url.contains( "playlist" ) && s_canParseSpotifyPlaylists )
return true;
if( url.contains( "soundcloud" ) && url.contains( "sets" ) )
return true;
if( url.contains( "ex.fm" ) && !url.contains( "/song/" ) ) // We treat all but song as playlist
return true;
if ( url.contains( "rdio.com" ) && url.contains( "people" ) && url.contains( "playlist" ) )
return true;
#ifdef QCA2_FOUND
@ -567,6 +591,41 @@ DropJob::handleRdioUrls( const QString& urlsRaw )
}
void
DropJob::handleSoundcloudUrls( const QString& urlsRaw )
{
QStringList urls = urlsRaw.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
qDebug() << "Got Soundcloud urls!" << urls;
if ( dropAction() == Default )
setDropAction( Create );
SoundcloudParser* sc = new SoundcloudParser( urls, dropAction() == Create, this );
connect( sc, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
m_queryCount++;
}
void
DropJob::handleExfmUrls( const QString& urlsRaw )
{
QStringList urls = urlsRaw.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
qDebug() << "Got Ex.fm urls!" << urls;
if ( dropAction() == Default )
setDropAction( Create );
ExfmParser* exfm = new ExfmParser( urls, dropAction() == Create, this );
connect( exfm, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
m_queryCount++;
}
void
DropJob::handleGroovesharkUrls ( const QString& urlsRaw )
{
@ -605,6 +664,10 @@ DropJob::handleAllUrls( const QString& urls )
handleSpotifyUrls( urls );
else if ( urls.contains( "rdio.com" ) )
handleRdioUrls( urls );
else if( urls.contains( "soundcloud" ) )
handleSoundcloudUrls( urls );
else if( urls.contains( "ex.fm" ) )
handleExfmUrls( urls );
#ifdef QCA2_FOUND
else if ( urls.contains( "grooveshark.com" ) )
handleGroovesharkUrls( urls );
@ -635,6 +698,24 @@ DropJob::handleTrackUrls( const QString& urls )
connect( spot, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
m_queryCount++;
}
else if ( urls.contains( "soundcloud" ) )
{
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
tDebug() << "Got a list of Soundcloud tracks!" << tracks;
SoundcloudParser* sc = new SoundcloudParser( tracks, false, this );
connect( sc, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
m_queryCount++;
}
else if ( urls.contains( "ex.fm" ) )
{
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
tDebug() << "Got a list of Exfm tracks!" << tracks;
ExfmParser* exfm = new ExfmParser( tracks, false, this );
connect( exfm, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
m_queryCount++;
}
else if ( urls.contains( "rdio.com" ) )
{
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );

View File

@ -105,6 +105,8 @@ public:
void handleM3u( const QString& urls );
void handleSpotifyUrls( const QString& urls );
void handleRdioUrls( const QString& urls );
void handleExfmUrls( const QString& urls );
void handleSoundcloudUrls( const QString& urls );
void handleGroovesharkUrls( const QString& urls );
static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; }

View File

@ -87,7 +87,7 @@
<item row="12" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Disc Number:</string>
<string>Track Number:</string>
</property>
</widget>
</item>

View File

@ -0,0 +1,308 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
*
* 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 "ExfmParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
using namespace Tomahawk;
QPixmap* ExfmParser::s_pixmap = 0;
ExfmParser::ExfmParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent )
: QObject ( parent )
, m_single( false )
, m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_type( DropJob::All )
{
foreach ( const QString& url, Urls )
lookupUrl( url );
}
ExfmParser::ExfmParser( const QString& Url, bool createNewPlaylist, QObject* parent )
: QObject ( parent )
, m_single( true )
, m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_type( DropJob::All )
{
lookupUrl( Url );
}
ExfmParser::~ExfmParser()
{
}
void
ExfmParser::lookupUrl( const QString& link )
{
const QString apiBase = "http://ex.fm/api/v3";
QString url( link );
QStringList paths;
foreach( const QString& path, QUrl( link ).path().split( "/" ) )
{
if ( !path.isEmpty() )
paths << path;
}
// User request
if ( paths.count() == 1 )
{
m_type = DropJob::Artist;
url = QString( apiBase + "/user/%1/trending" ).arg( paths.takeFirst() );
}
else
{
if ( url.contains( "/explore/site-of-the-day" ) ) // We treat site as artist
{
m_type = DropJob::Artist;
url.replace( "/explore/site-of-the-day", "/sotd?results=1" );
}
else if ( url.contains( "/song/" ) )
{
m_type = DropJob::Track;
}
else if( ( url.contains( "site") && url.contains( "album" ) ) || url.contains( "mixtape-of-the-month" ) )
{
m_type = DropJob::Album;
if ( url.contains( "album-of-the-week") )
url = QString( apiBase + "/%1?%2" ).arg( "aotw" ).arg( "results=1" ); // Only need the first album, eg. this week
if ( url.contains( "mixtape-of-the-month" ) )
url = QString( apiBase + "/%1?%2" ).arg( "motm" ).arg( "results=1" ); // Only need the first mixtape, eg. this week
}
else
{
m_type = DropJob::Playlist;
if ( url.contains( "tastemakers" ) )
url.replace( "trending", "explore" );
}
if ( m_type == DropJob::Playlist )
{
url.replace( "/genre/", "/tag/" );
url.replace( "/search/", "/song/search/" ); // We can only search for tracks, even though we want an artist or whatever
}
url.replace( "http://ex.fm", apiBase );
}
tDebug() << "Looking up URL..." << url;
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) );
if ( m_createNewPlaylist )
connect( reply, SIGNAL( finished() ), this, SLOT( exfmLookupFinished() ) );
else
connect( reply, SIGNAL( finished() ), this, SLOT( exfmBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Exfm", m_type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply );
}
void
ExfmParser::parseTrack( const QVariantMap& res )
{
QString title, artist, album;
album = res.value( "album", QString() ).toString();
title = res.value( "title", QString() ).toString();
artist = res.value( "artist", QString() ).toString();
if ( title.isEmpty() && artist.isEmpty() ) // don't have enough...
{
tLog() << "Didn't get an artist and track name from Exfm, not enough to build a query on. Aborting" << title << artist;
return;
}
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), m_trackMode );
if ( !q.isNull() )
{
tLog() << "Setting resulthint to " << res.value( "url" );
q->setResultHint( res.value( "url" ).toString() );
q->setProperty( "annotation", res.value( "url" ).toString() );
m_tracks << q;
}
}
void
ExfmParser::exfmLookupFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r );
m_queries.remove( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
if ( !ok )
{
tLog() << "Failed to parse json from Exfm browse item :" << p.errorString() << "On line" << p.errorLine();
return;
}
QStringList paths;
foreach( const QString& path, r->url().path().split( "/" ) )
if ( !path.isEmpty() )
paths << path;
QString title, artist, desc;
QVariantList tracks;
if ( m_type == DropJob::Album )
{
QStringList meta = res.value( "site" ).toMap().value( "title" ).toString().split( ", by " );
title = meta.takeFirst();
artist = meta.takeLast();
tracks = res.value( "site" ).toMap().value( "songs" ).toList();
}
else
{
// Take endpoint as title
title = paths.takeLast();
title[0] = title[0].toUpper();
if ( paths.contains( "trending") )
title = "Trending " + title;
else if ( paths.contains( "explore" ) )
title = "Explore " + title;
if ( paths.contains( "user" ) )
{
int index = paths.indexOf( "user");
if ( index != -1 && paths.size() > index+1 )
artist = paths.takeAt(paths.indexOf( "user" ) +1 );
}else
artist = "Ex.fm";
tracks = res.value( "songs" ).toList();
}
// Make the title
title = title + " by " + artist;
foreach( const QVariant& track, tracks )
parseTrack( track.toMap() );
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
uuid(),
title,
desc,
artist,
false,
m_tracks );
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return;
}
}
void
ExfmParser::playlistCreated()
{
ViewManager::instance()->show( m_playlist );
deleteLater();
}
void
ExfmParser::exfmBrowseFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
if ( !ok )
{
qDebug() << "Failed to parse ex.fm json";
return;
}
if ( m_type != DropJob::Track )
{
QVariantList tracks;
if( m_type == DropJob::Album )
tracks = res.value( "site" ).toMap().value( "songs" ).toList();
else
tracks = res.value( "songs" ).toList();
foreach( const QVariant& track, tracks )
parseTrack( track.toMap() );
}
else
parseTrack( res.value( "song" ).toMap() );
if ( m_single && !m_tracks.isEmpty() )
emit track( m_tracks.first() );
else if ( !m_single && !m_tracks.isEmpty() )
emit tracks( m_tracks );
deleteLater();
}
}
QPixmap
ExfmParser::pixmap() const
{
if ( !s_pixmap )
s_pixmap = new QPixmap( RESPATH "images/exfm.png" );
return *s_pixmap;
}

View File

@ -0,0 +1,89 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
*
* 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 Exfm_PARSER_H
#define Exfm_PARSER_H
#include "DllMacro.h"
#include "Typedefs.h"
#include "Query.h"
#include "DropJob.h"
#include "jobview/JobStatusItem.h"
#include <QObject>
#include <QtCore/QStringList>
/**
* Small class to parse Exfm links into query_ptrs
*
* Connect to the signals to get the results
*/
class QNetworkReply;
namespace Tomahawk
{
class DropJobNotifier;
class DLLEXPORT ExfmParser : public QObject
{
Q_OBJECT
public:
friend class ExfmJobNotifier;
explicit ExfmParser( const QString& trackUrl, bool createNewPlaylist = false, QObject* parent = 0 );
explicit ExfmParser( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 );
virtual ~ExfmParser();
// if true, emits track(), if false, emits tracks().
// only matters if you're using the QString constructor and explicityl dont' want
// the single track signal
void setSingleMode( bool single ) { m_single = single; }
signals:
void track( const Tomahawk::query_ptr& track );
void tracks( const QList< Tomahawk::query_ptr > tracks );
void playlist( const Tomahawk::query_ptr& playlist );
private slots:
void exfmBrowseFinished();
void exfmLookupFinished();
void playlistCreated();
private:
QPixmap pixmap() const;
void lookupUrl( const QString& url );
void checkBrowseFinished();
void parseTrack( const QVariantMap& res );
bool m_single;
bool m_trackMode;
bool m_createNewPlaylist;
int m_subscribers;
QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries;
Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob;
DropJob::DropType m_type;
static QPixmap* s_pixmap;
};
}
#endif

View File

@ -66,7 +66,8 @@ ShortenedLinkParser::handlesUrl( const QString& url )
url.contains( "tinysong.com" ) ||
url.contains( "grooveshark.com/s/~/" ) || // These redirect to the 'real' grooveshark track url
url.contains( "grooveshark.com/#/s/~/" ) ||
url.contains( "rd.io" ) );
url.contains( "rd.io" ) ||
url.contains( "snd.sc" ) );
}

View File

@ -0,0 +1,244 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
*
* 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 "SoundcloudParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
using namespace Tomahawk;
QPixmap* SoundcloudParser::s_pixmap = 0;
SoundcloudParser::SoundcloudParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent )
: QObject ( parent )
, m_single( false )
, m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_type( DropJob::All )
{
foreach ( const QString& url, Urls )
lookupUrl( url );
}
SoundcloudParser::SoundcloudParser( const QString& Url, bool createNewPlaylist, QObject* parent )
: QObject ( parent )
, m_single( true )
, m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_type( DropJob::All )
{
lookupUrl( Url );
}
SoundcloudParser::~SoundcloudParser()
{
}
void
SoundcloudParser::lookupUrl( const QString& link )
{
tDebug() << "Looking up URL..." << link;
QUrl scLink( QString( "http://api.soundcloud.com/resolve.json?client_id=TiNg2DRYhBnp01DA3zNag&url=" ) + link );
qDebug() << scLink.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( scLink ) );
connect( reply, SIGNAL( finished() ), this, SLOT( soundcloudBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Soundcloud", DropJob::All, reply );
JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply );
}
void
SoundcloudParser::parseTrack( const QVariantMap& res )
{
QString title, artist;
title = res.value( "title", QString() ).toString();
artist = res.value( "user" ).toMap().value( "username", QString() ).toString();
if ( title.isEmpty() && artist.isEmpty() ) // don't have enough...
{
tLog() << "Didn't get an artist and track name from Soundcloud, not enough to build a query on. Aborting" << title << artist;
return;
}
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, QString(), uuid(), m_trackMode );
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" );
m_tracks << q;
}
}
void
SoundcloudParser::soundcloudLookupFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r );
m_queries.remove( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
if ( !ok )
{
tLog() << "Failed to parse json from Soundcloud browse item :" << p.errorString() << "On line" << p.errorLine();
return;
}
if ( m_type == DropJob::Track )
{
parseTrack( res );
}
else if ( m_type == DropJob::Playlist )
{
QString title, user, desc;
title = res.value( "title" ).toString();
desc = res.value( "description" ).toString();
user = res.value( "user" ).toMap().value( "username" ).toString();
QVariantList tracks = res.value( "tracks" ).toList();
foreach( const QVariant& track, tracks )
parseTrack( track.toMap() );
if ( m_createNewPlaylist )
{
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
uuid(),
title,
desc,
user,
false,
m_tracks );
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return;
}
}
else if ( m_type == DropJob::Artist )
{
// cant parse soundcloud json here atm.
}
}
if ( m_single && !m_tracks.isEmpty() )
emit track( m_tracks.first() );
else if ( !m_single && !m_tracks.isEmpty() )
emit tracks( m_tracks );
deleteLater();
}
void
SoundcloudParser::playlistCreated()
{
ViewManager::instance()->show( m_playlist );
deleteLater();
}
void
SoundcloudParser::soundcloudBrowseFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
{
if ( r->rawHeaderList().contains( "Location" ) )
{
QString url = r->rawHeader("Location");
if ( url.contains( "tracks" ) )
{
m_type = DropJob::Track;
}
else if ( url.contains( "users" ) )
{
// For now, dont handle user tracklists
m_type = DropJob::All; //DropJob::Artist;
url = url.replace( ".json", "/tracks.json" );
qDebug() << "Gots artist!" << url;
}
else if ( url.contains( "playlists" ) )
{
m_type = DropJob::Playlist;
}
if ( m_type != DropJob::All )
{
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl(url) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( soundcloudLookupFinished() ) );
}
}
}
if ( m_type == DropJob::All )
{ // No good
m_queries.remove( r );
if ( m_browseJob )
m_browseJob->setFinished();
return;
}
}
QPixmap
SoundcloudParser::pixmap() const
{
if ( !s_pixmap )
s_pixmap = new QPixmap( RESPATH "images/soundcloud.png" );
return *s_pixmap;
}

View File

@ -0,0 +1,89 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
*
* 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 Soundcloud_PARSER_H
#define Soundcloud_PARSER_H
#include "DllMacro.h"
#include "Typedefs.h"
#include "Query.h"
#include "DropJob.h"
#include "jobview/JobStatusItem.h"
#include <QObject>
#include <QtCore/QStringList>
/**
* Small class to parse Soundcloud links into query_ptrs
*
* Connect to the signals to get the results
*/
class QNetworkReply;
namespace Tomahawk
{
class DropJobNotifier;
class DLLEXPORT SoundcloudParser : public QObject
{
Q_OBJECT
public:
friend class SoundcloudJobNotifier;
explicit SoundcloudParser( const QString& trackUrl, bool createNewPlaylist = false, QObject* parent = 0 );
explicit SoundcloudParser( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 );
virtual ~SoundcloudParser();
// if true, emits track(), if false, emits tracks().
// only matters if you're using the QString constructor and explicityl dont' want
// the single track signal
void setSingleMode( bool single ) { m_single = single; }
signals:
void track( const Tomahawk::query_ptr& track );
void tracks( const QList< Tomahawk::query_ptr > tracks );
void playlist( const Tomahawk::query_ptr& playlist );
private slots:
void soundcloudBrowseFinished();
void soundcloudLookupFinished();
void playlistCreated();
private:
QPixmap pixmap() const;
void lookupUrl( const QString& url );
void checkBrowseFinished();
void parseTrack( const QVariantMap& res );
bool m_single;
bool m_trackMode;
bool m_createNewPlaylist;
int m_subscribers;
QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries;
Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob;
DropJob::DropType m_type;
static QPixmap* s_pixmap;
};
}
#endif