| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2013 Konrad Zemek <[email protected]> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#include "BansheeProvider.h" |
| 18 |
|
| 19 |
#include "BansheeTrack.h" |
| 20 |
#include "importers/ImporterSqlConnection.h" |
| 21 |
|
| 22 |
using namespace StatSyncing; |
| 23 |
|
| 24 |
BansheeProvider::BansheeProvider( const QVariantMap &config, ImporterManager *importer ) |
| 25 |
: ImporterProvider( config, importer ) |
| 26 |
, m_connection( new ImporterSqlConnection( m_config.value( QStringLiteral("dbPath") ).toString() ) ) |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
BansheeProvider::~BansheeProvider() |
| 31 |
{ |
| 32 |
} |
| 33 |
|
| 34 |
qint64 |
| 35 |
BansheeProvider::reliableTrackMetaData() const |
| 36 |
{ |
| 37 |
return Meta::valTitle | Meta::valArtist | Meta::valAlbum | Meta::valComposer |
| 38 |
| Meta::valYear | Meta::valTrackNr | Meta::valDiscNr; |
| 39 |
} |
| 40 |
|
| 41 |
qint64 |
| 42 |
BansheeProvider::writableTrackStatsData() const |
| 43 |
{ |
| 44 |
return Meta::valRating | Meta::valLastPlayed | Meta::valPlaycount; |
| 45 |
} |
| 46 |
|
| 47 |
QSet<QString> |
| 48 |
BansheeProvider::artists() |
| 49 |
{ |
| 50 |
QSet<QString> result; |
| 51 |
for( const QVariantList &row : m_connection->query( QStringLiteral("SELECT Name FROM coreartists") ) ) |
| 52 |
result.insert( row[0].toString() ); |
| 53 |
|
| 54 |
return result; |
| 55 |
} |
| 56 |
|
| 57 |
TrackList |
| 58 |
BansheeProvider::artistTracks( const QString &artistName ) |
| 59 |
{ |
| 60 |
// Due to Banshee's peculiar track info storage, to avoid massive amount of confusion |
| 61 |
// we only take tracks from PrimarySource: MusicLibrarySource-Library (always ID 1) |
| 62 |
const QString query = QStringLiteral("SELECT TrackID, TRIM(t.Title), ar.Name, al.Title, " |
| 63 |
"TRIM(t.Composer), t.Year, t.TrackNumber, t.Disc, t.Rating, " |
| 64 |
"t.LastPlayedStamp, t.PlayCount " |
| 65 |
"FROM coretracks t " |
| 66 |
"INNER JOIN coreartists ar USING(ArtistID) " |
| 67 |
"LEFT JOIN corealbums al USING(AlbumID) " |
| 68 |
"WHERE ar.Name = :artist AND t.PrimarySourceID = 1"); |
| 69 |
|
| 70 |
QVariantMap bindValues; |
| 71 |
bindValues.insert( QStringLiteral(":artist"), artistName ); |
| 72 |
|
| 73 |
const QList<qint64> fields = QList<qint64>() << Meta::valTitle << Meta::valArtist |
| 74 |
<< Meta::valAlbum << Meta::valComposer << Meta::valYear << Meta::valTrackNr |
| 75 |
<< Meta::valDiscNr << Meta::valRating << Meta::valLastPlayed |
| 76 |
<< Meta::valPlaycount; |
| 77 |
|
| 78 |
TrackList result; |
| 79 |
for( const QVariantList &row : m_connection->query( query, bindValues ) ) |
| 80 |
{ |
| 81 |
const qint64 trackId = row[0].toLongLong(); |
| 82 |
|
| 83 |
Meta::FieldHash metadata; |
| 84 |
for( int i = 0; i < fields.size(); ++i ) |
| 85 |
metadata.insert( fields[i], row[i + 1] ); |
| 86 |
|
| 87 |
result << TrackPtr( new BansheeTrack( trackId, m_connection, metadata ) ); |
| 88 |
} |
| 89 |
|
| 90 |
return result; |
| 91 |
} |