Merge pull request #4406 from jmarshallnz/thumb_fixes
[vuplus_xbmc] / xbmc / music / MusicThumbLoader.cpp
index 1330ff9..cb4039c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *      Copyright (C) 2012-2013 Team XBMC
- *      http://www.xbmc.org
+ *      http://xbmc.org
  *
  *  This Program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
 
 #include "MusicThumbLoader.h"
 #include "FileItem.h"
-#include "TextureCache.h"
+#include "TextureDatabase.h"
 #include "music/tags/MusicInfoTag.h"
 #include "music/tags/MusicInfoTagLoaderFactory.h"
 #include "music/infoscanner/MusicInfoScanner.h"
@@ -110,6 +110,23 @@ bool CMusicThumbLoader::LoadItemCached(CFileItem* pItem)
           pItem->SetArt("artist.fanart", fanart);
           pItem->SetArtFallback("fanart", "artist.fanart");
         }
+        else if (!pItem->GetMusicInfoTag()->GetAlbumArtist().empty() &&
+                 pItem->GetMusicInfoTag()->GetAlbumArtist()[0] != artist)
+        {
+          // If no artist fanart and the album artist is different to the artist,
+          // try to get fanart from the album artist
+          artist = pItem->GetMusicInfoTag()->GetAlbumArtist()[0];
+          idArtist = m_musicDatabase->GetArtistByName(artist);
+          if (idArtist >= 0)
+          {
+            fanart = m_musicDatabase->GetArtForItem(idArtist, "artist", "fanart");
+            if (!fanart.empty())
+            {
+              pItem->SetArt("albumartist.fanart", fanart);
+              pItem->SetArtFallback("fanart", "albumartist.fanart");
+            }
+          }
+        }
       }
       m_musicDatabase->Close();
     }
@@ -142,7 +159,7 @@ bool CMusicThumbLoader::LoadItemLookup(CFileItem* pItem)
       if (!FillThumb(*pItem, false)) // Check for user thumbs but ignore folder thumbs
       {
         // No user thumb, use embedded art
-        CStdString thumb = CTextureCache::GetWrappedImageURL(pItem->GetPath(), "music");
+        CStdString thumb = CTextureUtils::GetWrappedImageURL(pItem->GetPath(), "music");
         pItem->SetArt("thumb", thumb);
       }
     }
@@ -161,14 +178,15 @@ bool CMusicThumbLoader::FillThumb(CFileItem &item, bool folderThumbs /* = true *
   if (item.HasArt("thumb"))
     return true;
   CStdString thumb = GetCachedImage(item, "thumb");
-  if (thumb.IsEmpty())
+  if (thumb.empty())
   {
     thumb = item.GetUserMusicThumb(false, folderThumbs);
-    if (!thumb.IsEmpty())
+    if (!thumb.empty())
       SetCachedImage(item, "thumb", thumb);
   }
-  item.SetArt("thumb", thumb);
-  return !thumb.IsEmpty();
+  if (!thumb.empty())
+    item.SetArt("thumb", thumb);
+  return !thumb.empty();
 }
 
 bool CMusicThumbLoader::FillLibraryArt(CFileItem &item)
@@ -203,6 +221,16 @@ bool CMusicThumbLoader::FillLibraryArt(CFileItem &item)
         item.SetArt("artist.fanart", fanart);
         item.SetArtFallback("fanart", "artist.fanart");
       }
+      else if (tag.GetType() == "song")
+      {
+        // If no artist fanart, try for album artist fanart
+        fanart = m_musicDatabase->GetArtistArtForItem(tag.GetAlbumId(), "album", "fanart");
+        if (!fanart.empty())
+        {
+          item.SetArt("albumartist.fanart", fanart);
+          item.SetArtFallback("fanart", "albumartist.fanart");
+        }
+      }
     }
     m_musicDatabase->Close();
   }