Permalink
Browse files

[infoscanner] add songs to database by album

  • Loading branch information...
1 parent 8c4d9fb commit 709706435ef9b1ab91cdadfffd2f155474e03584 Jonathan Marshall committed Jul 2, 2012
Showing with 47 additions and 30 deletions.
  1. +20 −6 xbmc/music/MusicDatabase.cpp
  2. +9 −1 xbmc/music/MusicDatabase.h
  3. +18 −23 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -268,7 +268,19 @@ void CMusicDatabase::CreateViews()
" artist.idArtist = artistinfo.idArtist");
}
-int CMusicDatabase::AddSong(const CSong& song, bool bCheck)
+int CMusicDatabase::AddAlbum(const CAlbum &album, vector<int> &songIDs)
+{
+ // add the album
+ int idAlbum = AddAlbum(album.strAlbum, StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator), -1, StringUtils::Join(album.genre, g_advancedSettings.m_musicItemSeparator), album.iYear, album.bCompilation);
+
+ // add the songs
+ for (VECSONGS::const_iterator i = album.songs.begin(); i != album.songs.end(); ++i)
+ songIDs.push_back(AddSong(*i, false, idAlbum));
+
+ return idAlbum;
+}
+
+int CMusicDatabase::AddSong(const CSong& song, bool bCheck, int idAlbum)
{
int idSong = -1;
CStdString strSQL;
@@ -286,11 +298,13 @@ int CMusicDatabase::AddSong(const CSong& song, bool bCheck)
int idPath = AddPath(strPath);
int idThumb = AddThumb(song.strThumb);
- int idAlbum;
- if (!song.albumArtist.empty()) // have an album artist
- idAlbum = AddAlbum(song.strAlbum, StringUtils::Join(song.albumArtist, g_advancedSettings.m_musicItemSeparator), idThumb, StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator), song.iYear, song.bCompilation);
- else
- idAlbum = AddAlbum(song.strAlbum, StringUtils::Join(song.artist, g_advancedSettings.m_musicItemSeparator), idThumb, StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator), song.iYear, song.bCompilation);
+ if (idAlbum < 0)
+ {
+ if (!song.albumArtist.empty()) // have an album artist
+ idAlbum = AddAlbum(song.strAlbum, StringUtils::Join(song.albumArtist, g_advancedSettings.m_musicItemSeparator), idThumb, StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator), song.iYear, song.bCompilation);
+ else
+ idAlbum = AddAlbum(song.strAlbum, StringUtils::Join(song.artist, g_advancedSettings.m_musicItemSeparator), idThumb, StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator), song.iYear, song.bCompilation);
+ }
DWORD crc = ComputeCRC(song.strFileName);
View
@@ -127,7 +127,14 @@ class CMusicDatabase : public CDatabase
void DeleteAlbumInfo();
bool LookupCDDBInfo(bool bRequery=false);
void DeleteCDDBInfo();
- int AddSong(const CSong &song, bool bCheck = true);
+
+ /*! \brief Add an album and all its songs to the database
+ \param album the album to add
+ \param songIDs [out] the ids of the added songs
+ \return the id of the album
+ */
+ int AddAlbum(const CAlbum &album, std::vector<int> &songIDs);
+
int UpdateSong(const CSong& song, int idSong = -1);
int SetAlbumInfo(int idAlbum, const CAlbum& album, const VECSONGS& songs, bool bTransaction=true);
bool DeleteAlbumInfo(int idArtist);
@@ -296,6 +303,7 @@ class CMusicDatabase : public CDatabase
virtual int GetMinVersion() const { return 26; };
const char *GetBaseDBName() const { return "MyMusic"; };
+ int AddSong(const CSong& song, bool bCheck = true, int idAlbum = -1);
int AddAlbum(const CStdString& strAlbum1, const CStdString &strArtist1, int idThumb, const CStdString& strGenre, int year, bool bCompilation);
int AddGenre(const CStdString& strGenre);
int AddArtist(const CStdString& strArtist);
@@ -536,39 +536,34 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
// finally, add these to the database
m_musicDatabase.BeginTransaction();
- for (unsigned int i = 0; i < songsToAdd.size(); ++i)
+ int numAdded = 0;
+ set<long> albumsToScan;
+ set<long> artistsToScan;
+ for (VECALBUMS::iterator i = albums.begin(); i != albums.end(); ++i)
{
+ vector<int> songIDs;
+ int idAlbum = m_musicDatabase.AddAlbum(*i, songIDs);
+ numAdded += i->songs.size();
if (m_bStop)
{
m_musicDatabase.RollbackTransaction();
- return i;
+ return numAdded;
}
- m_musicDatabase.AddSong(songsToAdd[i], false);
- }
- m_musicDatabase.CommitTransaction();
- // Build the artist & album sets
- set<long> artistsToScan;
- set<long> albumsToScan;
- for (unsigned int i = 0; i < songsToAdd.size(); ++i)
- {
- if (m_bStop)
+ // Build the artist & album sets
+ albumsToScan.insert(idAlbum);
+ for (vector<int>::iterator j = songIDs.begin(); j != songIDs.end(); ++j)
{
- return 0;
+ vector<long> songArtists;
+ m_musicDatabase.GetArtistsBySong(*j, false, songArtists);
+ artistsToScan.insert(songArtists.begin(), songArtists.end());
}
- std::vector<long> songArtists;
- m_musicDatabase.GetArtistsBySong(songsToAdd[i].idSong, false, songArtists);
- for (std::vector<long>::iterator it = songArtists.begin(); it != songArtists.end(); ++it)
- artistsToScan.insert(*it);
-
std::vector<long> albumArtists;
- m_musicDatabase.GetArtistsByAlbum(songsToAdd[i].iAlbumId, false, albumArtists);
- for (std::vector<long>::iterator it = albumArtists.begin(); it != albumArtists.end(); ++it)
- artistsToScan.insert(*it);
-
- albumsToScan.insert(songsToAdd[i].iAlbumId);
+ m_musicDatabase.GetArtistsByAlbum(idAlbum, false, albumArtists);
+ artistsToScan.insert(albumArtists.begin(), albumArtists.end());
}
-
+ m_musicDatabase.CommitTransaction();
+
// Download info & artwork
bool bCanceled;
for (set<long>::iterator it = artistsToScan.begin(); it != artistsToScan.end(); ++it)

0 comments on commit 7097064

Please sign in to comment.