Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[infoscanner] add song and album art to the database on scan

  • Loading branch information...
commit a29d9944fc9779d04b30285f16291950cb773c70 1 parent 7097064
authored June 09, 2012
35  xbmc/music/MusicDatabase.cpp
@@ -271,7 +271,9 @@ void CMusicDatabase::CreateViews()
271 271
 int CMusicDatabase::AddAlbum(const CAlbum &album, vector<int> &songIDs)
272 272
 {
273 273
   // add the album
274  
-  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);
  274
+  int idAlbum = AddAlbum(album.strAlbum, StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(album.genre, g_advancedSettings.m_musicItemSeparator), album.iYear, album.bCompilation);
  275
+
  276
+  SetArtForItem(idAlbum, "album", album.art);
275 277
 
276 278
   // add the songs
277 279
   for (VECSONGS::const_iterator i = album.songs.begin(); i != album.songs.end(); ++i)
@@ -297,13 +299,12 @@ int CMusicDatabase::AddSong(const CSong& song, bool bCheck, int idAlbum)
297 299
     if (NULL == m_pDS.get()) return -1;
298 300
 
299 301
     int idPath = AddPath(strPath);
300  
-    int idThumb = AddThumb(song.strThumb);
301 302
     if (idAlbum < 0)
302 303
     {
303 304
       if (!song.albumArtist.empty())  // have an album artist
304  
-        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);
  305
+        idAlbum = AddAlbum(song.strAlbum, StringUtils::Join(song.albumArtist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator), song.iYear, song.bCompilation);
305 306
       else
306  
-        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);
  307
+        idAlbum = AddAlbum(song.strAlbum, StringUtils::Join(song.artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(song.genre, g_advancedSettings.m_musicItemSeparator), song.iYear, song.bCompilation);
307 308
     }
308 309
 
309 310
     DWORD crc = ComputeCRC(song.strFileName);
@@ -341,7 +342,7 @@ int CMusicDatabase::AddSong(const CSong& song, bool bCheck, int idAlbum)
341 342
 
342 343
       // we use replace because it can handle both inserting a new song
343 344
       // and replacing an existing song's record if the given idSong already exists
344  
-      strSQL=PrepareSQL("replace into song (idSong,idAlbum,idPath,strArtists,strGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,strMusicBrainzTrackID,strMusicBrainzArtistID,strMusicBrainzAlbumID,strMusicBrainzAlbumArtistID,strMusicBrainzTRMID,iTimesPlayed,iStartOffset,iEndOffset,idThumb,lastplayed,rating,comment) values (%s,%i,%i,'%s','%s','%s',%i,%i,%i,'%ul','%s','%s','%s','%s','%s','%s'",
  345
+      strSQL=PrepareSQL("replace into song (idSong,idAlbum,idPath,strArtists,strGenres,strTitle,iTrack,iDuration,iYear,dwFileNameCRC,strFileName,strMusicBrainzTrackID,strMusicBrainzArtistID,strMusicBrainzAlbumID,strMusicBrainzAlbumArtistID,strMusicBrainzTRMID,iTimesPlayed,iStartOffset,iEndOffset,lastplayed,rating,comment) values (%s,%i,%i,'%s','%s','%s',%i,%i,%i,'%ul','%s','%s','%s','%s','%s','%s'",
345 346
                     strIdSong.c_str(),
346 347
                     idAlbum, idPath, 
347 348
                     StringUtils::Join(song.artist, g_advancedSettings.m_musicItemSeparator).c_str(),
@@ -356,11 +357,11 @@ int CMusicDatabase::AddSong(const CSong& song, bool bCheck, int idAlbum)
356 357
                     song.strMusicBrainzTRMID.c_str());
357 358
 
358 359
       if (song.lastPlayed.IsValid())
359  
-        strSQL1=PrepareSQL(",%i,%i,%i,%i,'%s','%c','%s')",
360  
-                      song.iTimesPlayed, song.iStartOffset, song.iEndOffset, idThumb, song.lastPlayed.GetAsDBDateTime().c_str(), song.rating, song.strComment.c_str());
  360
+        strSQL1=PrepareSQL(",%i,%i,%i,'%s','%c','%s')",
  361
+                      song.iTimesPlayed, song.iStartOffset, song.iEndOffset, song.lastPlayed.GetAsDBDateTime().c_str(), song.rating, song.strComment.c_str());
361 362
       else
362  
-        strSQL1=PrepareSQL(",%i,%i,%i,%i,NULL,'%c','%s')",
363  
-                      song.iTimesPlayed, song.iStartOffset, song.iEndOffset, idThumb, song.rating, song.strComment.c_str());
  363
+        strSQL1=PrepareSQL(",%i,%i,%i,NULL,'%c','%s')",
  364
+                      song.iTimesPlayed, song.iStartOffset, song.iEndOffset, song.rating, song.strComment.c_str());
364 365
       strSQL+=strSQL1;
365 366
 
366 367
       m_pDS->exec(strSQL.c_str());
@@ -371,6 +372,9 @@ int CMusicDatabase::AddSong(const CSong& song, bool bCheck, int idAlbum)
371 372
         idSong = song.idSong;
372 373
     }
373 374
 
  375
+    if (!song.strThumb.empty())
  376
+      SetArtForItem(idSong, "song", "thumb", song.strThumb);
  377
+
374 378
     for (unsigned int index = 0; index < song.albumArtist.size(); index++)
375 379
     {
376 380
       int idAlbumArtist = AddArtist(song.albumArtist[index]);
@@ -443,7 +447,7 @@ int CMusicDatabase::UpdateSong(const CSong& song, int idSong /* = -1 */)
443 447
   return newSong.idSong;
444 448
 }
445 449
 
446  
-int CMusicDatabase::AddAlbum(const CStdString& strAlbum1, const CStdString &strArtist, int idThumb, const CStdString& strGenre, int year, bool bCompilation)
  450
+int CMusicDatabase::AddAlbum(const CStdString& strAlbum1, const CStdString &strArtist, const CStdString& strGenre, int year, bool bCompilation)
447 451
 {
448 452
   CStdString strSQL;
449 453
   try
@@ -452,13 +456,6 @@ int CMusicDatabase::AddAlbum(const CStdString& strAlbum1, const CStdString &strA
452 456
     strAlbum.TrimLeft(" ");
453 457
     strAlbum.TrimRight(" ");
454 458
 
455  
-    if (strAlbum.IsEmpty())
456  
-    {
457  
-      // album tag is empty, so we treat this as a single, or a collection of singles,
458  
-      // so we don't specify a thumb
459  
-      idThumb = AddThumb("");
460  
-    }
461  
-
462 459
     if (NULL == m_pDB.get()) return -1;
463 460
     if (NULL == m_pDS.get()) return -1;
464 461
 
@@ -475,7 +472,7 @@ int CMusicDatabase::AddAlbum(const CStdString& strAlbum1, const CStdString &strA
475 472
     {
476 473
       m_pDS->close();
477 474
       // doesnt exists, add it
478  
-      strSQL=PrepareSQL("insert into album (idAlbum, strAlbum, strArtists, strGenres, iYear, bCompilation, idThumb) values( NULL, '%s', '%s', '%s', %i, %i, %i)", strAlbum.c_str(), strArtist.c_str(), strGenre.c_str(), year, bCompilation, idThumb);
  475
+      strSQL=PrepareSQL("insert into album (idAlbum, strAlbum, strArtists, strGenres, iYear, bCompilation) values( NULL, '%s', '%s', '%s', %i, %i)", strAlbum.c_str(), strArtist.c_str(), strGenre.c_str(), year, bCompilation);
479 476
       m_pDS->exec(strSQL.c_str());
480 477
 
481 478
       CAlbumCache album;
@@ -495,7 +492,7 @@ int CMusicDatabase::AddAlbum(const CStdString& strAlbum1, const CStdString &strA
495 492
       album.artist = StringUtils::Split(strArtist, g_advancedSettings.m_musicItemSeparator);
496 493
       m_albumCache.insert(pair<CStdString, CAlbumCache>(album.strAlbum + strArtist, album));
497 494
       m_pDS->close();
498  
-      strSQL=PrepareSQL("update album set strGenres='%s', iYear=%i, idThumb=%i where idAlbum=%i", strGenre.c_str(), year, idThumb, album.idAlbum);
  495
+      strSQL=PrepareSQL("update album set strGenres='%s', iYear=%i where idAlbum=%i", strGenre.c_str(), year, album.idAlbum);
499 496
       m_pDS->exec(strSQL.c_str());
500 497
       // and clear the link tables - these are updated in AddSong()
501 498
       strSQL=PrepareSQL("delete from album_artist where idAlbum=%i", album.idAlbum);
2  xbmc/music/MusicDatabase.h
@@ -304,7 +304,7 @@ class CMusicDatabase : public CDatabase
304 304
   const char *GetBaseDBName() const { return "MyMusic"; };
305 305
 
306 306
   int AddSong(const CSong& song, bool bCheck = true, int idAlbum = -1);
307  
-  int AddAlbum(const CStdString& strAlbum1, const CStdString &strArtist1, int idThumb, const CStdString& strGenre, int year, bool bCompilation);
  307
+  int AddAlbum(const CStdString& strAlbum1, const CStdString &strArtist1, const CStdString& strGenre, int year, bool bCompilation);
308 308
   int AddGenre(const CStdString& strGenre);
309 309
   int AddArtist(const CStdString& strArtist);
310 310
   int AddPath(const CStdString& strPath);
12  xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -1219,12 +1219,14 @@ void CMusicInfoScanner::GetAlbumArtwork(long id, const CAlbum &album)
1219 1219
 {
1220 1220
   if (album.thumbURL.m_url.size())
1221 1221
   {
1222  
-    CStdString thumb;
1223  
-    if (!m_musicDatabase.GetAlbumThumb(id, thumb) || thumb.IsEmpty() || !XFILE::CFile::Exists(thumb))
  1222
+    if (!m_musicDatabase.GetArtForItem(id, "album", "thumb").empty())
1224 1223
     {
1225  
-      thumb = CThumbnailCache::GetAlbumThumb(album);
1226  
-      CScraperUrl::DownloadThumbnail(thumb,album.thumbURL.m_url[0]);
1227  
-      m_musicDatabase.SaveAlbumThumb(id, thumb);
  1224
+      string thumb = CScraperUrl::GetThumbURL(album.thumbURL.GetFirstThumb());
  1225
+      if (!thumb.empty())
  1226
+      {
  1227
+        CTextureCache::Get().BackgroundCacheImage(thumb);
  1228
+        m_musicDatabase.SetArtForItem(id, "album", "thumb", thumb);
  1229
+      }
1228 1230
     }
1229 1231
   }
1230 1232
 }

0 notes on commit a29d994

Please sign in to comment.
Something went wrong with that request. Please try again.