Permalink
Browse files

[info dialogs] set thumb/fanart from the db in the song, album, and a…

…rtist dialogs
  • Loading branch information...
Jonathan Marshall
Jonathan Marshall committed Jul 2, 2012
1 parent 43bdd51 commit c089cc86262305795981fb824c74c2665a8a2868
@@ -42,7 +42,6 @@
#include "utils/URIUtils.h"
#include "utils/StringUtils.h"
#include "TextureCache.h"
-#include "ThumbnailCache.h"
using namespace std;
using namespace XFILE;
@@ -88,7 +87,6 @@ bool CGUIDialogMusicInfo::OnMessage(CGUIMessage& message)
CGUIDialog::OnMessage(message);
m_bViewReview = true;
m_bRefresh = false;
- RefreshThumb();
Update();
return true;
}
@@ -162,15 +160,24 @@ void CGUIDialogMusicInfo::SetAlbum(const CAlbum& album, const CStdString &path)
m_albumItem->GetMusicInfoTag()->SetGenre(m_album.genre);
m_albumItem->GetMusicInfoTag()->SetDatabaseId(m_album.idAlbum, "album");
CMusicDatabase::SetPropertiesFromAlbum(*m_albumItem,m_album);
- m_albumItem->SetMusicThumb();
- // set the artist thumb
- CFileItem artist(StringUtils::Join(m_album.artist, g_advancedSettings.m_musicItemSeparator));
- artist.SetCachedArtistThumb();
- if (CFile::Exists(artist.GetThumbnailImage()))
- m_albumItem->SetProperty("artistthumb", artist.GetThumbnailImage());
- CStdString strFanart = m_albumItem->GetCachedFanart();
- if (CFile::Exists(strFanart))
- m_albumItem->SetProperty("fanart_image",strFanart);
+
+ CMusicThumbLoader loader;
+ loader.LoadItem(m_albumItem.get());
+
+ // set the artist thumb, fanart
+ if (!m_album.artist.empty())
+ {
+ CMusicDatabase db;
+ db.Open();
+ map<string, string> artwork;
+ if (db.GetArtistArtForItem(m_album.idAlbum, "album", artwork))
+ {
+ if (artwork.find("thumb") != artwork.end())
+ m_albumItem->SetProperty("artistthumb", artwork["thumb"]);
+ if (artwork.find("fanart") != artwork.end())
+ m_albumItem->SetProperty("fanart_image",artwork["fanart"]);
+ }
+ }
m_hasUpdatedThumb = false;
m_bArtistInfo = false;
m_albumSongs->SetContent("albums");
@@ -188,10 +195,10 @@ void CGUIDialogMusicInfo::SetArtist(const CArtist& artist, const CStdString &pat
m_albumItem->GetMusicInfoTag()->SetGenre(m_artist.genre);
m_albumItem->GetMusicInfoTag()->SetDatabaseId(m_artist.idArtist, "artist");
CMusicDatabase::SetPropertiesFromArtist(*m_albumItem,m_artist);
- CStdString strFanart = m_albumItem->GetCachedFanart();
- if (CFile::Exists(strFanart))
- m_albumItem->SetProperty("fanart_image",strFanart);
- m_albumItem->SetCachedArtistThumb();
+
+ CMusicThumbLoader loader;
+ loader.LoadItem(m_albumItem.get());
+
m_hasUpdatedThumb = false;
m_bArtistInfo = true;
m_albumSongs->SetContent("artists");
@@ -317,49 +324,11 @@ void CGUIDialogMusicInfo::SetLabel(int iControl, const CStdString& strLabel)
}
}
-void CGUIDialogMusicInfo::RefreshThumb()
-{
- CStdString thumbImage = m_albumItem->GetThumbnailImage();
- if (!m_albumItem->HasThumbnail())
- {
- if (m_bArtistInfo)
- thumbImage = m_albumItem->GetCachedArtistThumb();
- else
- thumbImage = CThumbnailCache::GetAlbumThumb(m_album);
-
- if (!CFile::Exists(thumbImage))
- {
- DownloadThumbnail(thumbImage);
- m_hasUpdatedThumb = true;
- }
- }
- if (!CFile::Exists(thumbImage) )
- {
- if (m_bArtistInfo)
- thumbImage = "DefaultArtist.png";
- else
- thumbImage = "DefaultAlbumCover.png";
- }
-
- m_albumItem->SetThumbnailImage(thumbImage);
-}
-
bool CGUIDialogMusicInfo::NeedRefresh() const
{
return m_bRefresh;
}
-bool CGUIDialogMusicInfo::DownloadThumbnail(const CStdString &thumbFile)
-{
- const CScraperUrl &url = (m_bArtistInfo) ? m_artist.thumbURL : m_album.thumbURL;
- for (unsigned int i = 0; i < url.m_url.size(); ++i)
- {
- if (CScraperUrl::DownloadThumbnail(thumbFile, url.m_url[i]))
- return true;
- }
- return false;
-}
-
void CGUIDialogMusicInfo::OnInitWindow()
{
CGUIDialog::OnInitWindow();
@@ -448,34 +417,28 @@ void CGUIDialogMusicInfo::OnGetThumb()
if (result == "thumb://Current")
return; // user chose the one they have
- // delete the thumbnail if that's what the user wants, else overwrite with the
- // new thumbnail
- CStdString cachedThumb;
- if (m_bArtistInfo)
- cachedThumb = m_albumItem->GetCachedArtistThumb();
- else
- cachedThumb = CThumbnailCache::GetAlbumThumb(m_album);
-
- CTextureCache::Get().ClearCachedImage(cachedThumb, true);
+ CStdString newThumb;
if (result.Left(14) == "thumb://Remote")
{
int number = atoi(result.Mid(14));
- CFile::Cache(thumbs[number], cachedThumb);
+ newThumb = thumbs[number];
}
else if (result == "thumb://Local")
- CFile::Cache(localThumb, cachedThumb);
+ newThumb = localThumb;
else if (CFile::Exists(result))
- CPicture::CreateThumbnail(result, cachedThumb);
- else
- result = "thumb://None";
+ newThumb = result;
+ else // none
+ newThumb = "-"; // force local thumbs to be ignored
- if (result == "thumb://None")
- { // clear this thumb (note - it'll likely be recached, nothing we can do about that at this point)
- CTextureCache::Get().ClearCachedImage(cachedThumb, true);
- cachedThumb = "";
+ // update thumb in the database
+ CMusicDatabase db;
+ if (db.Open())
+ {
+ db.SetArtForItem(m_albumItem->GetMusicInfoTag()->GetDatabaseId(), m_albumItem->GetMusicInfoTag()->GetType(), "thumb", newThumb);
+ db.Close();
}
- m_albumItem->SetThumbnailImage(cachedThumb);
+ m_albumItem->SetThumbnailImage(newThumb);
m_hasUpdatedThumb = true;
// tell our GUI to completely reload all controls (as some of them
@@ -492,11 +455,10 @@ void CGUIDialogMusicInfo::OnGetFanart()
{
CFileItemList items;
- CStdString cachedThumb(CThumbnailCache::GetThumb(m_artist.strArtist,g_settings.GetMusicFanartFolder()));
- if (CFile::Exists(cachedThumb))
+ if (m_albumItem->HasProperty("fanart_image"))
{
CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false));
- itemCurrent->SetThumbnailImage(cachedThumb);
+ itemCurrent->SetThumbnailImage(m_albumItem->GetProperty("fanart_image").asString());
itemCurrent->SetLabel(g_localizeStrings.Get(20440));
items.Add(itemCurrent);
}
@@ -557,31 +519,31 @@ void CGUIDialogMusicInfo::OnGetFanart()
if (result.Equals("fanart://Local"))
result = strLocal;
- CTextureCache::Get().ClearCachedImage(cachedThumb, true);
-
- if (!result.Equals("fanart://None"))
- { // local file
- if (result.Left(15) == "fanart://Remote")
- {
- int iFanart = atoi(result.Mid(15).c_str());
- m_artist.fanart.SetPrimaryFanart(iFanart);
- // download the fullres fanart image
- CStdString tempFile = "special://temp/fanart_download.jpg";
- CAsyncFileCopy downloader;
- if (!downloader.Copy(m_artist.fanart.GetImageURL(), tempFile, g_localizeStrings.Get(13413)))
- return;
- result = tempFile;
- }
+ if (result.Left(15) == "fanart://Remote")
+ {
+ int iFanart = atoi(result.Mid(15).c_str());
+ m_artist.fanart.SetPrimaryFanart(iFanart);
+ result = m_artist.fanart.GetImageURL();
+ }
+ else if (result.Equals("fanart://None") || !CFile::Exists(result))
+ result.clear();
- if (flip)
- CPicture::ConvertFile(result, cachedThumb,0,1920,-1,100,true);
- else
- CPicture::CacheFanart(result, cachedThumb);
+ if (flip && !result.empty())
+ result = CTextureCache::GetWrappedImageURL(result, "", "flipped");
- m_albumItem->SetProperty("fanart_image",cachedThumb);
- m_hasUpdatedThumb = true;
+ // update thumb in the database
+ CMusicDatabase db;
+ if (db.Open())
+ {
+ db.SetArtForItem(m_albumItem->GetMusicInfoTag()->GetDatabaseId(), m_albumItem->GetMusicInfoTag()->GetType(), "fanart", result);
+ db.Close();
}
+ if (!result.empty())
+ m_albumItem->SetProperty("fanart_image",result);
+ else
+ m_albumItem->ClearProperty("fanart_image");
+ m_hasUpdatedThumb = true;
// tell our GUI to completely reload all controls (as some of them
// are likely to have had this image in use so will need refreshing)
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS);
@@ -40,7 +40,6 @@ class CGUIDialogMusicInfo :
void SetArtist(const CArtist& artist, const CStdString &path);
bool NeedRefresh() const;
bool HasUpdatedThumb() const { return m_hasUpdatedThumb; };
- void RefreshThumb();
virtual bool HasListItems() const { return true; };
virtual CFileItemPtr GetCurrentListItem(int offset = 0);
@@ -49,7 +48,6 @@ class CGUIDialogMusicInfo :
virtual void OnInitWindow();
void Update();
void SetLabel(int iControl, const CStdString& strLabel);
- bool DownloadThumbnail(const CStdString &thumbFile);
void OnGetThumb();
void OnGetFanart();
void SetSongs(const VECSONGS &songs);
@@ -40,7 +40,6 @@
#include "guilib/LocalizeStrings.h"
#include "TextureCache.h"
#include "music/Album.h"
-#include "ThumbnailCache.h"
using namespace XFILE;
@@ -197,12 +196,14 @@ void CGUIDialogSongInfo::SetSong(CFileItem *item)
m_startRating = m_song->GetMusicInfoTag()->GetRating();
MUSIC_INFO::CMusicInfoLoader::LoadAdditionalTagInfo(m_song.get());
// set artist thumb as well
- if (m_song->HasMusicInfoTag())
+ if (m_song->HasMusicInfoTag() && !m_song->GetMusicInfoTag()->GetArtist().empty())
{
- CFileItem artist(StringUtils::Join(m_song->GetMusicInfoTag()->GetArtist(), g_advancedSettings.m_musicItemSeparator));
- artist.SetCachedArtistThumb();
- if (CFile::Exists(artist.GetThumbnailImage()))
- m_song->SetProperty("artistthumb", artist.GetThumbnailImage());
+ CMusicDatabase db;
+ db.Open();
+ int idArtist = db.GetArtistByName(m_song->GetMusicInfoTag()->GetArtist()[0]);
+ std::string thumb = db.GetArtForItem(idArtist, "artist", "thumb");
+ if (!thumb.empty())
+ m_song->SetProperty("artistthumb", thumb);
}
m_needsUpdate = false;
}
@@ -266,14 +267,10 @@ void CGUIDialogSongInfo::OnGetThumb()
}
if (CFile::Exists(localThumb))
{
- URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "localthumb.jpg", cachedLocalThumb);
- if (CPicture::CreateThumbnail(localThumb, cachedLocalThumb))
- {
- CFileItemPtr item(new CFileItem("thumb://Local", false));
- item->SetThumbnailImage(cachedLocalThumb);
- item->SetLabel(g_localizeStrings.Get(20017));
- items.Add(item);
- }
+ CFileItemPtr item(new CFileItem("thumb://Local", false));
+ item->SetThumbnailImage(localThumb);
+ item->SetLabel(g_localizeStrings.Get(20017));
+ items.Add(item);
}
else
{ // no local thumb exists, so we are just using the allmusic.com thumb or cached thumb
@@ -295,22 +292,25 @@ void CGUIDialogSongInfo::OnGetThumb()
// delete the thumbnail if that's what the user wants, else overwrite with the
// new thumbnail
- CStdString cachedThumb(CThumbnailCache::GetAlbumThumb(m_song->GetMusicInfoTag()));
-
- CTextureCache::Get().ClearCachedImage(cachedThumb, true);
+ CStdString newThumb;
if (result == "thumb://None")
- {
- CFile::Delete(cachedThumb);
- cachedThumb = "";
- }
+ newThumb = "-";
else if (result == "thumb://allmusic.com")
- CFile::Cache(thumbFromWeb, cachedThumb);
+ newThumb = thumbFromWeb;
else if (result == "thumb://Local")
- CFile::Cache(cachedLocalThumb, cachedThumb);
- else if (CFile::Exists(result))
- CPicture::CreateThumbnail(result, cachedThumb);
+ newThumb = localThumb;
+ else
+ newThumb = result;
+
+ // update thumb in the database
+ CMusicDatabase db;
+ if (db.Open())
+ {
+ db.SetArtForItem(m_song->GetMusicInfoTag()->GetDatabaseId(), m_song->GetMusicInfoTag()->GetType(), "thumb", newThumb);
+ db.Close();
+ }
- m_song->SetThumbnailImage(cachedThumb);
+ m_song->SetThumbnailImage(newThumb);
// tell our GUI to completely reload all controls (as some of them
// are likely to have had this image in use so will need refreshing)
@@ -409,8 +409,6 @@ void CGUIWindowMusicBase::ShowArtistInfo(const CArtist& artist, const CStdString
if (bShowInfo)
pDlgArtistInfo->DoModal();
- else
- pDlgArtistInfo->RefreshThumb(); // downloads the thumb if we don't already have one
if (!pDlgArtistInfo->NeedRefresh())
{
@@ -453,8 +451,6 @@ void CGUIWindowMusicBase::ShowArtistInfo(const CArtist& artist, const CStdString
pDlgArtistInfo->SetArtist(info.GetArtist(), path);
if (bShowInfo)
pDlgArtistInfo->DoModal();
- else
- pDlgArtistInfo->RefreshThumb(); // downloads the thumb if we don't already have one
CArtist artistInfo = info.GetArtist();
artistInfo.idArtist = artist.idArtist;
@@ -502,8 +498,6 @@ void CGUIWindowMusicBase::ShowAlbumInfo(const CAlbum& album, const CStdString& p
pDlgAlbumInfo->SetAlbum(albumInfo, path);
if (bShowInfo)
pDlgAlbumInfo->DoModal();
- else
- pDlgAlbumInfo->RefreshThumb(); // downloads the thumb if we don't already have one
if (!pDlgAlbumInfo->NeedRefresh())
{
@@ -550,8 +544,6 @@ void CGUIWindowMusicBase::ShowAlbumInfo(const CAlbum& album, const CStdString& p
pDlgAlbumInfo->SetAlbum(info.GetAlbum(), path);
if (bShowInfo)
pDlgAlbumInfo->DoModal();
- else
- pDlgAlbumInfo->RefreshThumb(); // downloads the thumb if we don't already have one
CAlbum albumInfo = info.GetAlbum();
albumInfo.idAlbum = album.idAlbum;

0 comments on commit c089cc8

Please sign in to comment.