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