File indexing completed on 2024-05-19 04:49:16
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.com> * 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 "ArtistHelper.h" 0018 0019 #include <QStringList> 0020 0021 #include <KLocalizedString> 0022 0023 QString 0024 ArtistHelper::bestGuessAlbumArtist( const QString &albumArtist, const QString &trackArtist, 0025 const QString &genre, const QString &composer) 0026 { 0027 QString best( albumArtist ); 0028 0029 // - for classical tracks it's the composer 0030 if( best.isEmpty() && 0031 (genre.compare( i18nc( "The genre name for classical music", "Classical" ), Qt::CaseInsensitive ) == 0 || 0032 genre.compare( QLatin1String( "Classical" ), Qt::CaseInsensitive ) == 0 ) ) 0033 best = ArtistHelper::realTrackArtist( composer ); 0034 0035 // - for "normal" tracks it's the track artist 0036 if( best.isEmpty() ) 0037 best = ArtistHelper::realTrackArtist( trackArtist ); 0038 0039 // - "Various Artists" is the same as no artist 0040 if( best.compare( i18n( "Various Artists" ), Qt::CaseInsensitive ) == 0 || 0041 best.compare( QLatin1String( "Various Artists" ), Qt::CaseInsensitive ) == 0 ) 0042 best.clear(); 0043 0044 return best; 0045 } 0046 0047 QString 0048 ArtistHelper::realTrackArtist( const QString &trackArtistTag ) 0049 { 0050 bool featuring = false; 0051 QStringList trackArtists; 0052 if( trackArtistTag.contains( QLatin1String("featuring") ) ) 0053 { 0054 featuring = true; 0055 trackArtists = trackArtistTag.split( QStringLiteral("featuring") ); 0056 } 0057 else if( trackArtistTag.contains( QLatin1String("feat.") ) ) 0058 { 0059 featuring = true; 0060 trackArtists = trackArtistTag.split( QStringLiteral("feat.") ); 0061 } 0062 else if( trackArtistTag.contains( QLatin1String("ft.") ) ) 0063 { 0064 featuring = true; 0065 trackArtists = trackArtistTag.split( QStringLiteral("ft.") ); 0066 } 0067 else if( trackArtistTag.contains( QLatin1String("f.") ) ) 0068 { 0069 featuring = true; 0070 trackArtists = trackArtistTag.split( QStringLiteral("f.") ); 0071 } 0072 0073 //this needs to be improved 0074 0075 if( featuring ) 0076 { 0077 //always use the first artist 0078 QString tmp = trackArtists[0].simplified(); 0079 //artists are written as "A (feat. B)" or "A [feat. B]" as well 0080 if( tmp.endsWith(QLatin1String(" (")) || tmp.endsWith( QLatin1String(" [") ) ) 0081 tmp = tmp.left( tmp.length() -2 ).simplified(); //remove last two characters 0082 0083 if( tmp.isEmpty() ) 0084 return trackArtistTag; //huh? 0085 else 0086 { 0087 return tmp; 0088 } 0089 } 0090 else 0091 { 0092 return trackArtistTag; 0093 } 0094 }