File indexing completed on 2024-05-19 04:50:19

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "MagnatuneSqlCollection.h"
0018 
0019 #include "core/support/Debug.h"
0020 #include "MagnatuneCollectionLocation.h"
0021 #include "MagnatuneMeta.h"
0022 
0023 using namespace Collections;
0024 
0025 MagnatuneSqlCollection::MagnatuneSqlCollection(const QString & id, const QString & prettyName, ServiceMetaFactory * metaFactory, ServiceSqlRegistry * registry)
0026     : ServiceSqlCollection( id, prettyName, metaFactory, registry )
0027 {
0028 }
0029 
0030 Meta::TrackPtr MagnatuneSqlCollection::trackForUrl(const QUrl &url)
0031 {
0032     //DEBUG_BLOCK
0033 
0034     QString pristineUrl = url.url();
0035 
0036     if ( pristineUrl.startsWith( "http://magnatune.com/playlist_redirect.php?url=" ) ) {
0037 
0038         //if we are not a member of the right type, we need to preserve this or we will not be able to play the track. Actually... use the original url in any case so plays are attributed to the person whose playlist it is...
0039         QString orgUrl = pristineUrl;
0040 
0041         int endIndex = pristineUrl.indexOf( "&key=" );
0042 
0043         pristineUrl = pristineUrl.mid( 47, endIndex - 47 );
0044 
0045         //debug() << "got redirected url: " << pristineUrl;
0046 
0047 
0048         pristineUrl.remove( "_nospeech" );
0049         pristineUrl.replace( ".ogg", ".mp3" );
0050         pristineUrl.replace( "-lofi.mp3", ".mp3" );
0051 
0052         pristineUrl.replace( QRegExp( "http://download" ), "http://he3" );
0053         pristineUrl.replace( QRegExp( "http://stream" ), "http://he3" );
0054 
0055         //debug() << "after a quick makeover: " << pristineUrl;
0056 
0057         Meta::TrackPtr trackPtr = ServiceSqlCollection::trackForUrl( QUrl( pristineUrl ) );
0058 
0059         if ( trackPtr ) {
0060             Meta::ServiceTrack * mTrack = dynamic_cast< Meta::ServiceTrack * >( trackPtr.data() );
0061             if ( mTrack ) {
0062 
0063                 mTrack->setUidUrl( orgUrl );
0064             }
0065         }
0066 
0067         return trackPtr;
0068 
0069     } else {
0070 
0071         pristineUrl.remove( "_nospeech" );
0072         pristineUrl.replace( ".ogg", ".mp3" );
0073         pristineUrl.replace( "-lofi.mp3", ".mp3" );
0074 
0075         pristineUrl.replace( QRegExp( ".*:.*@download" ), "http://he3" );
0076         pristineUrl.replace( QRegExp( ".*:.*@stream" ), "http://he3" );
0077 
0078         return ServiceSqlCollection::trackForUrl( QUrl( pristineUrl ) );
0079 
0080     }
0081     
0082 }
0083 
0084 CollectionLocation * MagnatuneSqlCollection::location()
0085 {
0086     return new MagnatuneCollectionLocation( this );
0087 }
0088 
0089 
0090 
0091