From 33fc2df655e9c9aee3d1c797484c766e0e035d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Wed, 27 Mar 2013 00:47:47 +0100 Subject: [PATCH] Accept http[s] and play/open links from spotify. --- src/libtomahawk/utils/SpotifyParser.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/utils/SpotifyParser.cpp b/src/libtomahawk/utils/SpotifyParser.cpp index 2076fb8a1..7f4748441 100644 --- a/src/libtomahawk/utils/SpotifyParser.cpp +++ b/src/libtomahawk/utils/SpotifyParser.cpp @@ -79,17 +79,25 @@ SpotifyParser::lookupUrl( const QString& rawLink ) { tLog() << "Looking up Spotify rawURI:" << rawLink; QString link = rawLink; - if ( link.contains( "open.spotify.com/" ) ) // convert to a URI - { - link.replace( "http://", "" ).replace( "open.spotify.com/", "" ); - link.replace( "/", ":" ); - link = "spotify:" + link; - } + + QRegExp isHttp("(?:((play|open)\\.spotify.com))(.*)"); + // Some spotify apps contain the link to the playlist as url-encoded in their link (e.g. ShareMyPlaylists) - if ( link.contains( "%3A" ) ) + if ( link.contains( "%253A" ) ) { link = QUrl::fromPercentEncoding( link.toUtf8() ); } + + if( link.contains( "%3A" ) ) + { + link = QUrl::fromPercentEncoding( link.toUtf8() ); + } + + if( isHttp.indexIn( link, 0 ) != -1 ) + { + link = "spotify"+isHttp.cap(3).replace("/", ":"); + } + // TODO: Ignoring search and user querys atm // (spotify:(?:(?:artist|album|track|user:[^:]+:playlist):[a-zA-Z0-9]+|user:[^:]+|search:(?:[-\w$\.+!*'(),<>:\s]+|%[a-fA-F0-9\s]{2})+)) QRegExp rx( "(spotify:(?:(?:artist|album|track|user:[^:]+:playlist):[a-zA-Z0-9]+[^:]))" );