mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-02 20:28:14 +02:00
* Properly deal with auto-creating artists & albums.
This commit is contained in:
@@ -160,16 +160,13 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
|
|||||||
if( !source()->isLocal() )
|
if( !source()->isLocal() )
|
||||||
url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( url );
|
url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( url );
|
||||||
|
|
||||||
bool autoCreate = true;
|
artistid = dbi->artistId( artist, true );
|
||||||
artistid = dbi->artistId( artist, autoCreate );
|
|
||||||
if ( artistid < 1 )
|
if ( artistid < 1 )
|
||||||
continue;
|
continue;
|
||||||
autoCreate = true; // artistId overwrites autoCreate (reference)
|
trackid = dbi->trackId( artistid, track, true );
|
||||||
trackid = dbi->trackId( artistid, track, autoCreate );
|
|
||||||
if ( trackid < 1 )
|
if ( trackid < 1 )
|
||||||
continue;
|
continue;
|
||||||
autoCreate = true; // trackId overwrites autoCreate (reference)
|
albumid = dbi->albumId( artistid, album, true );
|
||||||
albumid = dbi->albumId( artistid, album, autoCreate );
|
|
||||||
|
|
||||||
// Now add the association
|
// Now add the association
|
||||||
query_filejoin.bindValue( 0, fileid );
|
query_filejoin.bindValue( 0, fileid );
|
||||||
|
@@ -259,9 +259,8 @@ DatabaseImpl::file( int fid )
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
DatabaseImpl::artistId( const QString& name_orig, bool& autoCreate )
|
DatabaseImpl::artistId( const QString& name_orig, bool autoCreate )
|
||||||
{
|
{
|
||||||
bool isnew = false;
|
|
||||||
if ( m_lastart == name_orig )
|
if ( m_lastart == name_orig )
|
||||||
return m_lastartid;
|
return m_lastartid;
|
||||||
|
|
||||||
@@ -296,20 +295,17 @@ DatabaseImpl::artistId( const QString& name_orig, bool& autoCreate )
|
|||||||
}
|
}
|
||||||
|
|
||||||
id = query.lastInsertId().toInt();
|
id = query.lastInsertId().toInt();
|
||||||
isnew = true;
|
|
||||||
m_lastart = name_orig;
|
m_lastart = name_orig;
|
||||||
m_lastartid = id;
|
m_lastartid = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
autoCreate = isnew;
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
DatabaseImpl::trackId( int artistid, const QString& name_orig, bool& isnew )
|
DatabaseImpl::trackId( int artistid, const QString& name_orig, bool autoCreate )
|
||||||
{
|
{
|
||||||
isnew = false;
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
QString sortname = DatabaseImpl::sortname( name_orig );
|
QString sortname = DatabaseImpl::sortname( name_orig );
|
||||||
//if( ( id = m_artistcache[sortname] ) ) return id;
|
//if( ( id = m_artistcache[sortname] ) ) return id;
|
||||||
@@ -320,45 +316,46 @@ DatabaseImpl::trackId( int artistid, const QString& name_orig, bool& isnew )
|
|||||||
query.addBindValue( sortname );
|
query.addBindValue( sortname );
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
if( query.next() )
|
if ( query.next() )
|
||||||
{
|
{
|
||||||
id = query.value( 0 ).toInt();
|
id = query.value( 0 ).toInt();
|
||||||
}
|
}
|
||||||
if( id )
|
if ( id )
|
||||||
{
|
{
|
||||||
//m_trackcache[sortname]=id;
|
//m_trackcache[sortname]=id;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( autoCreate )
|
||||||
|
{
|
||||||
// not found, insert it.
|
// not found, insert it.
|
||||||
query.prepare( "INSERT INTO track(id,artist,name,sortname) VALUES(NULL,?,?,?)" );
|
query.prepare( "INSERT INTO track(id,artist,name,sortname) VALUES(NULL,?,?,?)" );
|
||||||
query.addBindValue( artistid );
|
query.addBindValue( artistid );
|
||||||
query.addBindValue( name_orig );
|
query.addBindValue( name_orig );
|
||||||
query.addBindValue( sortname );
|
query.addBindValue( sortname );
|
||||||
if( !query.exec() )
|
if ( !query.exec() )
|
||||||
{
|
{
|
||||||
tDebug() << "Failed to insert track:" << name_orig;
|
tDebug() << "Failed to insert track:" << name_orig;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = query.lastInsertId().toInt();
|
id = query.lastInsertId().toInt();
|
||||||
//m_trackcache[sortname]=id;
|
}
|
||||||
isnew = true;
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
DatabaseImpl::albumId( int artistid, const QString& name_orig, bool& isnew )
|
DatabaseImpl::albumId( int artistid, const QString& name_orig, bool autoCreate )
|
||||||
{
|
{
|
||||||
isnew = false;
|
if ( name_orig.isEmpty() )
|
||||||
if( name_orig.isEmpty() )
|
|
||||||
{
|
{
|
||||||
//qDebug() << Q_FUNC_INFO << "empty album name";
|
//qDebug() << Q_FUNC_INFO << "empty album name";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_lastartid == artistid && m_lastalb == name_orig )
|
if ( m_lastartid == artistid && m_lastalb == name_orig )
|
||||||
return m_lastalbid;
|
return m_lastalbid;
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
@@ -370,17 +367,19 @@ DatabaseImpl::albumId( int artistid, const QString& name_orig, bool& isnew )
|
|||||||
query.addBindValue( artistid );
|
query.addBindValue( artistid );
|
||||||
query.addBindValue( sortname );
|
query.addBindValue( sortname );
|
||||||
query.exec();
|
query.exec();
|
||||||
if( query.next() )
|
if ( query.next() )
|
||||||
{
|
{
|
||||||
id = query.value( 0 ).toInt();
|
id = query.value( 0 ).toInt();
|
||||||
}
|
}
|
||||||
if( id )
|
if ( id )
|
||||||
{
|
{
|
||||||
m_lastalb = name_orig;
|
m_lastalb = name_orig;
|
||||||
m_lastalbid = id;
|
m_lastalbid = id;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( autoCreate )
|
||||||
|
{
|
||||||
// not found, insert it.
|
// not found, insert it.
|
||||||
query.prepare( "INSERT INTO album(id,artist,name,sortname) VALUES(NULL,?,?,?)" );
|
query.prepare( "INSERT INTO album(id,artist,name,sortname) VALUES(NULL,?,?,?)" );
|
||||||
query.addBindValue( artistid );
|
query.addBindValue( artistid );
|
||||||
@@ -393,10 +392,10 @@ DatabaseImpl::albumId( int artistid, const QString& name_orig, bool& isnew )
|
|||||||
}
|
}
|
||||||
|
|
||||||
id = query.lastInsertId().toInt();
|
id = query.lastInsertId().toInt();
|
||||||
//m_albumcache[sortname]=id;
|
|
||||||
isnew = true;
|
|
||||||
m_lastalb = name_orig;
|
m_lastalb = name_orig;
|
||||||
m_lastalbid = id;
|
m_lastalbid = id;
|
||||||
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,9 +52,9 @@ public:
|
|||||||
TomahawkSqlQuery newquery() { return TomahawkSqlQuery( db ); }
|
TomahawkSqlQuery newquery() { return TomahawkSqlQuery( db ); }
|
||||||
QSqlDatabase& database() { return db; }
|
QSqlDatabase& database() { return db; }
|
||||||
|
|
||||||
int artistId( const QString& name_orig, bool& autoCreate );
|
int artistId( const QString& name_orig, bool autoCreate );
|
||||||
int trackId( int artistid, const QString& name_orig, bool& isnew );
|
int trackId( int artistid, const QString& name_orig, bool autoCreate );
|
||||||
int albumId( int artistid, const QString& name_orig, bool& isnew );
|
int albumId( int artistid, const QString& name_orig, bool autoCreate );
|
||||||
|
|
||||||
QList< QPair<int, float> > searchTable( const QString& table, const QString& name, uint limit = 10 );
|
QList< QPair<int, float> > searchTable( const QString& table, const QString& name, uint limit = 10 );
|
||||||
QList< int > getTrackFids( int tid );
|
QList< int > getTrackFids( int tid );
|
||||||
|
@@ -179,9 +179,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
artistsModel->setColumnStyle( TreeModel::TrackOnly );
|
artistsModel->setColumnStyle( TreeModel::TrackOnly );
|
||||||
foreach ( const QString& artist, artists )
|
foreach ( const QString& artist, artists )
|
||||||
{
|
{
|
||||||
artist_ptr artistPtr = Artist::get( artist );
|
artist_ptr artistPtr = Artist::get( artist, false );
|
||||||
if ( artistPtr.isNull() )
|
|
||||||
artistPtr = Artist::get( 0, artist );
|
|
||||||
artistsModel->addArtists( artistPtr );
|
artistsModel->addArtists( artistPtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,12 +197,8 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums )
|
foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums )
|
||||||
{
|
{
|
||||||
qDebug() << "Getting album" << album.album << "By" << album.artist;
|
qDebug() << "Getting album" << album.album << "By" << album.artist;
|
||||||
artist_ptr artistPtr = Artist::get( album.artist );
|
artist_ptr artistPtr = Artist::get( album.artist, false );
|
||||||
if ( artistPtr.isNull() )
|
album_ptr albumPtr = Album::get( artistPtr, album.album, false );
|
||||||
artistPtr = Artist::get( 0, album.artist );
|
|
||||||
album_ptr albumPtr = Album::get( 0, album.album, artistPtr );
|
|
||||||
|
|
||||||
if( !albumPtr.isNull() )
|
|
||||||
al << albumPtr;
|
al << albumPtr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user