Permalink
Browse files

[thumbloader] retreive art for library music in the thumbloader

  • Loading branch information...
1 parent 3e594ad commit a46667f39d281ed35308388f9bdbd66edf1559d4 Jonathan Marshall committed May 13, 2012
View
@@ -37,6 +37,7 @@
#include "video/VideoDatabase.h"
#include "cores/dvdplayer/DVDFileInfo.h"
#include "video/VideoInfoScanner.h"
+#include "music/tags/MusicInfoTag.h"
using namespace XFILE;
using namespace std;
@@ -487,17 +488,52 @@ CStdString CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
CMusicThumbLoader::CMusicThumbLoader() : CThumbLoader(1)
{
+ m_database = new CMusicDatabase;
}
CMusicThumbLoader::~CMusicThumbLoader()
{
+ delete m_database;
+}
+
+void CMusicThumbLoader::OnLoaderStart()
+{
+ m_database->Open();
+}
+
+void CMusicThumbLoader::OnLoaderFinish()
+{
+ m_database->Close();
}
bool CMusicThumbLoader::LoadItem(CFileItem* pItem)
{
- if (pItem->m_bIsShareOrDrive) return true;
+ if (pItem->m_bIsShareOrDrive)
+ return true;
+
+ if (pItem->HasMusicInfoTag() && pItem->GetArt().empty())
+ {
+ if (FillLibraryArt(*pItem))
+ return true;
+ if (pItem->GetMusicInfoTag()->GetType() == "artist")
+ return true; // no fallback
+ }
+
if (!pItem->HasThumbnail())
pItem->SetUserMusicThumb();
return true;
}
+bool CMusicThumbLoader::FillLibraryArt(CFileItem &item)
+{
+ CMusicInfoTag &tag = *item.GetMusicInfoTag();
+ if (tag.GetDatabaseId() > -1 && !tag.GetType().empty())
+ {
+ m_database->Open();
+ map<string, string> artwork;
+ if (m_database->GetArtForItem(tag.GetDatabaseId(), tag.GetType(), artwork))
+ item.SetArt(artwork);
+ m_database->Close();
+ }
+ return !item.GetArt().empty();
+}
View
@@ -30,6 +30,7 @@
class CStreamDetails;
class IStreamDetailsObserver;
class CVideoDatabase;
+class CMusicDatabase;
/*!
\ingroup thumbs,jobs
@@ -161,5 +162,17 @@ class CMusicThumbLoader : public CThumbLoader
CMusicThumbLoader();
virtual ~CMusicThumbLoader();
virtual bool LoadItem(CFileItem* pItem);
+
+ /*! \brief helper function to fill the art for a video library item
+ \param item a video CFileItem
+ \return true if we fill art, false otherwise
+ */
+ bool FillLibraryArt(CFileItem &item);
+
+protected:
+ virtual void OnLoaderStart();
+ virtual void OnLoaderFinish();
+
+ CMusicDatabase *m_database;
};
#endif
@@ -1150,7 +1150,6 @@ bool CMusicDatabase::SearchArtists(const CStdString& search, CFileItemList &arti
label.Format("A %s", m_pDS->fv(1).get_asString()); // sort label is stored in the title tag
pItem->GetMusicInfoTag()->SetTitle(label);
pItem->GetMusicInfoTag()->SetDatabaseId(m_pDS->fv(0).get_asInt(), "artist");
- pItem->SetCachedArtistThumb();
artists.Add(pItem);
m_pDS->next();
}
@@ -2873,8 +2872,6 @@ bool CMusicDatabase::GetArtistsByWhere(const CStdString& strBaseDir, const CStdS
strDir.Format("%ld/", artist.idArtist);
pItem->SetPath(strBaseDir + strDir);
pItem->GetMusicInfoTag()->SetDatabaseId(artist.idArtist, "artist");
- if (CFile::Exists(pItem->GetCachedArtistThumb()))
- pItem->SetThumbnailImage(pItem->GetCachedArtistThumb());
pItem->SetIconImage("DefaultArtist.png");
SetPropertiesFromArtist(*pItem,artist);
@@ -264,6 +264,20 @@ bool CGUIWindowMusicNav::OnClick(int iItem)
return CGUIWindowMusicBase::OnClick(iItem);
}
+bool CGUIWindowMusicNav::Update(const CStdString &strDirectory)
+{
+ if (m_thumbLoader.IsLoading())
+ m_thumbLoader.StopThread();
+
+ if (CGUIWindowMusicBase::Update(strDirectory))
+ {
+ m_thumbLoader.Load(*m_vecItems);
+ return true;
+ }
+
+ return false;
+}
+
bool CGUIWindowMusicNav::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
{
if (m_bDisplayEmptyDatabaseMessage)
@@ -272,19 +286,13 @@ bool CGUIWindowMusicNav::GetDirectory(const CStdString &strDirectory, CFileItemL
if (strDirectory.IsEmpty())
AddSearchFolder();
- if (m_thumbLoader.IsLoading())
- m_thumbLoader.StopThread();
-
bool bResult = CGUIWindowMusicBase::GetDirectory(strDirectory, items);
if (bResult)
{
if (items.IsPlayList())
OnRetrieveMusicInfo(items);
if (!items.IsMusicDb())
- {
items.SetCachedMusicThumbs();
- m_thumbLoader.Load(*m_vecItems);
- }
}
// update our content in the info manager
@@ -793,8 +801,6 @@ void CGUIWindowMusicNav::FrameMove()
void CGUIWindowMusicNav::OnPrepareFileItems(CFileItemList &items)
{
CGUIWindowMusicBase::OnPrepareFileItems(items);
- // set fanart
- SetupFanart(items);
}
void CGUIWindowMusicNav::AddSearchFolder()
@@ -42,6 +42,7 @@ class CGUIWindowMusicNav : public CGUIWindowMusicBase, public IBackgroundLoaderO
protected:
virtual void OnItemLoaded(CFileItem* pItem) {};
// override base class methods
+ virtual bool Update(const CStdString &strDirectory);
virtual bool GetDirectory(const CStdString &strDirectory, CFileItemList &items);
virtual void UpdateButtons();
virtual void PlayItem(int iItem);

0 comments on commit a46667f

Please sign in to comment.