Permalink
Browse files

[musicdb] AddSong should take a const CSong and return the id

  • Loading branch information...
1 parent da03764 commit 06e7b4d517ce9080d06b1dccd5b95977e84c6f20 Jonathan Marshall committed Jun 23, 2012
Showing with 25 additions and 22 deletions.
  1. +23 −20 xbmc/music/MusicDatabase.cpp
  2. +2 −2 xbmc/music/MusicDatabase.h
@@ -267,20 +267,21 @@ void CMusicDatabase::CreateViews()
" artist.idArtist = artistinfo.idArtist");
}
-void CMusicDatabase::AddSong(CSong& song, bool bCheck)
+int CMusicDatabase::AddSong(const CSong& song, bool bCheck)
{
+ int idSong = -1;
CStdString strSQL;
try
{
// We need at least the title
if (song.strTitle.IsEmpty())
- return;
+ return -1;
CStdString strPath, strFileName;
URIUtils::Split(song.strFileName, strPath, strFileName);
- if (NULL == m_pDB.get()) return ;
- if (NULL == m_pDS.get()) return ;
+ if (NULL == m_pDB.get()) return -1;
+ if (NULL == m_pDS.get()) return -1;
int idPath = AddPath(strPath);
int idThumb = AddThumb(song.strThumb);
@@ -293,23 +294,18 @@ void CMusicDatabase::AddSong(CSong& song, bool bCheck)
DWORD crc = ComputeCRC(song.strFileName);
bool bInsert = true;
- int idSong = -1;
bool bHasKaraoke = false;
#ifdef HAS_KARAOKE
bHasKaraoke = CKaraokeLyricsFactory::HasLyrics( song.strFileName );
#endif
- // If this is karaoke song, change the genre to 'Karaoke' (and add it if it's not there)
- if ( bHasKaraoke && g_advancedSettings.m_karaokeChangeGenreForKaraokeSongs )
- song.genre.insert(song.genre.begin(), "Karaoke");
-
if (bCheck)
{
strSQL=PrepareSQL("select * from song where idAlbum=%i and dwFileNameCRC='%ul' and strTitle='%s'",
idAlbum, crc, song.strTitle.c_str());
if (!m_pDS->query(strSQL.c_str()))
- return;
+ return -1;
if (m_pDS->num_rows() != 0)
{
@@ -372,27 +368,34 @@ void CMusicDatabase::AddSong(CSong& song, bool bCheck)
AddSongArtist(idArtist, idSong, index > 0 ? true : false, index);
}
- for (unsigned int index = 0; index < song.genre.size(); index++)
+ unsigned int index = 0;
+ // If this is karaoke song, change the genre to 'Karaoke' (and add it if it's not there)
+ if ( bHasKaraoke && g_advancedSettings.m_karaokeChangeGenreForKaraokeSongs )
+ {
+ int idGenre = AddGenre("Karaoke");
+ AddSongGenre(idGenre, idSong, index);
+ AddAlbumGenre(idGenre, idAlbum, index++);
+ }
+ for (vector<string>::const_iterator i = song.genre.begin(); i != song.genre.end(); ++i)
{
// index will be wrong for albums, but ordering is not all that relevant
// for genres anyway
- int idGenre = AddGenre(song.genre[index]);
+ int idGenre = AddGenre(*i);
AddSongGenre(idGenre, idSong, index);
- AddAlbumGenre(idGenre, idAlbum, index);
+ AddAlbumGenre(idGenre, idAlbum, index++);
}
- song.idSong = idSong;
-
// Add karaoke information (if any)
if ( bHasKaraoke )
- AddKaraokeData( song );
+ AddKaraokeData(idSong, song );
AnnounceUpdate("song", idSong);
}
catch (...)
{
CLog::Log(LOGERROR, "musicdatabase:unable to addsong (%s)", strSQL.c_str());
}
+ return idSong;
}
int CMusicDatabase::UpdateSong(const CSong& song, int idSong /* = -1 */)
@@ -418,7 +421,7 @@ int CMusicDatabase::UpdateSong(const CSong& song, int idSong /* = -1 */)
// Make sure newSong.idSong has a valid value (> 0)
newSong.idSong = idSong;
// re-add the song
- AddSong(newSong, false);
+ newSong.idSong = AddSong(newSong, false);
if (newSong.idSong < 0)
return -1;
@@ -4663,7 +4666,7 @@ void CMusicDatabase::ImportFromXML(const CStdString &xmlFile)
progress->Close();
}
-void CMusicDatabase::AddKaraokeData(const CSong& song)
+void CMusicDatabase::AddKaraokeData(int idSong, const CSong& song)
{
try
{
@@ -4672,7 +4675,7 @@ void CMusicDatabase::AddKaraokeData(const CSong& song)
// If song.iKaraokeNumber is non-zero, we already have it in the database. Just replace the song ID.
if ( song.iKaraokeNumber > 0 )
{
- CStdString strSQL = PrepareSQL("UPDATE karaokedata SET idSong=%i WHERE iKaraNumber=%i", song.idSong, song.iKaraokeNumber);
+ CStdString strSQL = PrepareSQL("UPDATE karaokedata SET idSong=%i WHERE iKaraNumber=%i", idSong, song.iKaraokeNumber);
m_pDS->exec(strSQL.c_str());
return;
}
@@ -4691,7 +4694,7 @@ void CMusicDatabase::AddKaraokeData(const CSong& song)
// Add the data
strSQL=PrepareSQL( "INSERT INTO karaokedata (iKaraNumber, idSong, iKaraDelay, strKaraEncoding, strKaralyrics, strKaraLyrFileCRC) "
- "VALUES( %i, %i, 0, NULL, NULL, '%ul' )", iKaraokeNumber, song.idSong, crc );
+ "VALUES( %i, %i, 0, NULL, NULL, '%ul' )", iKaraokeNumber, idSong, crc );
m_pDS->exec(strSQL.c_str());
}
@@ -127,7 +127,7 @@ class CMusicDatabase : public CDatabase
void DeleteAlbumInfo();
bool LookupCDDBInfo(bool bRequery=false);
void DeleteCDDBInfo();
- void AddSong(CSong& song, bool bCheck = true);
+ int AddSong(const CSong &song, bool bCheck = true);
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);
@@ -306,7 +306,7 @@ class CMusicDatabase : public CDatabase
bool AddSongGenre(int idGenre, int idSong, int iOrder);
bool AddAlbumGenre(int idGenre, int idAlbum, int iOrder);
- void AddKaraokeData(const CSong& song);
+ void AddKaraokeData(int idSong, const CSong& song);
bool SetAlbumInfoSongs(int idAlbumInfo, const VECSONGS& songs);
bool GetAlbumInfoSongs(int idAlbumInfo, VECSONGS& songs);
private:

0 comments on commit 06e7b4d

Please sign in to comment.