Skip to content

Commit

Permalink
Merge pull request xbmc#1109 from jmarshallnz/music_thumbs_to_cache
Browse files Browse the repository at this point in the history
Music thumbs to cache
  • Loading branch information
jmarshallnz committed Jul 4, 2012
2 parents 9080eab + f878229 commit f70b7d7
Show file tree
Hide file tree
Showing 111 changed files with 1,411 additions and 2,313 deletions.
350 changes: 42 additions & 308 deletions lib/cximage-6.0/CxImage/DllInterface.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lib/cximage-6.0/CxImage/ximaenc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,19 @@ CxImage::CxImage(BYTE * buffer, DWORD size, DWORD imagetype)
* \param imagetype: file format, see ENUM_CXIMAGE_FORMATS
* \return true if everything is ok
*/
#ifdef XBMC
bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype, int &width, int &height)
{
CxMemFile file(buffer,size);
return Decode(&file,imagetype,width,height);
}
#else
bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype)
{
CxMemFile file(buffer,size);
return Decode(&file,imagetype);
}
#endif
////////////////////////////////////////////////////////////////////////////////
/**
* Loads an image from file handle.
Expand Down
9 changes: 8 additions & 1 deletion lib/cximage-6.0/CxImage/ximage.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ typedef struct tagCxTextInfo
bool Load(const char * filename, DWORD imagetype, int &iWidth, int &iHeight);
bool Decode(FILE * hFile, DWORD imagetype, int &iWidth, int &iHeight);
bool Decode(CxFile * hFile, DWORD imagetype, int &iWidth, int &iHeight);
bool Decode(BYTE *buffer, DWORD size, DWORD imagetype, int &iWidth, int &iHeight);
bool Load(const char * filename, DWORD imagetype)
{
int iWidth=0;
Expand All @@ -538,12 +539,18 @@ typedef struct tagCxTextInfo
int iHeight=0;
return Decode(hFile, imagetype, iWidth, iHeight);
};
bool Decode(BYTE *buffer, unsigned int size, DWORD imagetype)
{
int iWidth=0;
int iHeight=0;
return Decode(buffer, size, imagetype, iWidth, iHeight);
};
#else
bool Load(const char * filename, DWORD imagetype);
bool Decode(FILE * hFile, DWORD imagetype);
bool Decode(CxFile * hFile, DWORD imagetype);
#endif
bool Decode(BYTE * buffer, DWORD size, DWORD imagetype);
#endif

bool CheckFormat(CxFile * hFile, DWORD imagetype = 0);
bool CheckFormat(BYTE * buffer, DWORD size, DWORD imagetype = 0);
Expand Down
1 change: 0 additions & 1 deletion xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "input/KeyboardLayoutConfiguration.h"
#include "LangInfo.h"
#include "Util.h"
#include "pictures/Picture.h"
#include "guilib/TextureManager.h"
#include "cores/dvdplayer/DVDFileInfo.h"
#include "cores/AudioEngine/AEFactory.h"
Expand Down
2 changes: 1 addition & 1 deletion xbmc/ApplicationMessenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ void CApplicationMessenger::MediaPlay(string filename)
{
CFileItem item(filename, false);
if (item.IsAudio())
item.SetMusicThumb();
CMusicThumbLoader::FillThumb(item);
else
CVideoThumbLoader::FillThumb(item);
item.FillInDefaultIcon();
Expand Down
205 changes: 2 additions & 203 deletions xbmc/FileItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "Util.h"
#include "pictures/Picture.h"
#include "playlists/PlayListFactory.h"
#include "utils/Crc32.h"
#include "filesystem/DirectoryCache.h"
Expand Down Expand Up @@ -55,7 +54,6 @@
#include "utils/log.h"
#include "utils/Variant.h"
#include "music/karaoke/karaokelyricsfactory.h"
#include "ThumbnailCache.h"
#include "utils/Mime.h"
#include "utils/CharsetConverter.h"

Expand Down Expand Up @@ -91,10 +89,6 @@ CFileItem::CFileItem(const CStdString &path, const CAlbum& album)
m_strLabel2 = StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator);
URIUtils::AddSlashAtEnd(m_strPath);
GetMusicInfoTag()->SetAlbum(album);
if (album.thumbURL.m_url.size() > 0)
m_strThumbnailImage = album.thumbURL.m_url[0].m_url;
else
m_strThumbnailImage.clear();
m_bIsAlbum = true;
CMusicDatabase::SetPropertiesFromAlbum(*this,album);
}
Expand All @@ -110,7 +104,6 @@ CFileItem::CFileItem(const CMusicInfoTag& music)
m_bIsFolder = URIUtils::HasSlashAtEnd(m_strPath);
*GetMusicInfoTag() = music;
FillInDefaultIcon();
SetCachedMusicThumb();
}

CFileItem::CFileItem(const CVideoInfoTag& movie)
Expand Down Expand Up @@ -1013,31 +1006,6 @@ void CFileItem::FillInDefaultIcon()
}
}

CStdString CFileItem::GetCachedArtistThumb() const
{
return CThumbnailCache::GetArtistThumb(*this);
}

void CFileItem::SetCachedArtistThumb()
{
CStdString thumb(GetCachedArtistThumb());
if (CFile::Exists(thumb))
{
// found it, we are finished.
SetThumbnailImage(thumb);
}
}

// set the album thumb for a file or folder
void CFileItem::SetMusicThumb(bool alwaysCheckRemote /* = true */)
{
if (HasThumbnail()) return;

SetCachedMusicThumb();
if (!HasThumbnail())
SetUserMusicThumb(alwaysCheckRemote);
}

void CFileItem::RemoveExtension()
{
if (m_bIsFolder)
Expand Down Expand Up @@ -1829,21 +1797,6 @@ void CFileItemList::FillInDefaultIcons()
}
}

void CFileItemList::SetMusicThumbs()
{
CSingleLock lock(m_lock);
//cache thumbnails directory
g_directoryCache.InitMusicThumbCache();

for (int i = 0; i < (int)m_items.size(); ++i)
{
CFileItemPtr pItem = m_items[i];
pItem->SetMusicThumb();
}

g_directoryCache.ClearMusicThumbCache();
}

int CFileItemList::GetFolderCount() const
{
CSingleLock lock(m_lock);
Expand Down Expand Up @@ -1992,6 +1945,8 @@ void CFileItemList::FilterCueItems()
SYSTEMTIME dateTime;
tag.GetReleaseDate(dateTime);
if (dateTime.wYear) song.iYear = dateTime.wYear;
if (song.embeddedArt.empty() && !tag.GetCoverArtInfo().empty())
song.embeddedArt = tag.GetCoverArtInfo();
}
if (!song.iDuration && tag.GetDuration() > 0)
{ // must be the last song
Expand Down Expand Up @@ -2444,84 +2399,6 @@ bool CFileItemList::AlwaysCache() const
return false;
}

void CFileItemList::SetCachedMusicThumbs()
{
CSingleLock lock(m_lock);
// TODO: Investigate caching time to see if it speeds things up
for (unsigned int i = 0; i < m_items.size(); ++i)
{
CFileItemPtr pItem = m_items[i];
pItem->SetCachedMusicThumb();
}
}

void CFileItem::SetCachedMusicThumb()
{
// if it already has a thumbnail, then return
if (HasThumbnail() || m_bIsShareOrDrive) return ;

// streams do not have thumbnails
if (IsInternetStream()) return ;

// music db items already have thumbs or there is no thumb available
if (IsMusicDb()) return;

// ignore the parent dir items
if (IsParentFolder()) return;

CStdString cachedThumb(GetPreviouslyCachedMusicThumb());
if (!cachedThumb.IsEmpty())
SetThumbnailImage(cachedThumb);
// SetIconImage(cachedThumb);
}

CStdString CFileItem::GetPreviouslyCachedMusicThumb() const
{
// look if an album thumb is available,
// could be any file with tags loaded or
// a directory in album window
CStdString strAlbum, strArtist;
if (HasMusicInfoTag() && m_musicInfoTag->Loaded())
{
strAlbum = m_musicInfoTag->GetAlbum();
if (!m_musicInfoTag->GetAlbumArtist().empty())
strArtist = StringUtils::Join(m_musicInfoTag->GetAlbumArtist(), g_advancedSettings.m_musicItemSeparator);
else
strArtist = StringUtils::Join(m_musicInfoTag->GetArtist(), g_advancedSettings.m_musicItemSeparator);
}
if (!strAlbum.IsEmpty() && !strArtist.IsEmpty())
{
// try permanent album thumb using "album name + artist name"
CStdString thumb(CThumbnailCache::GetAlbumThumb(strAlbum, strArtist));
if (CFile::Exists(thumb))
return thumb;
}

// if a file, try to find a cached filename.tbn
if (!m_bIsFolder)
{
// look for locally cached tbn
CStdString thumb(CThumbnailCache::GetMusicThumb(m_strPath));
if (CFile::Exists(thumb))
return thumb;
}

// try and find a cached folder thumb (folder.jpg or folder.tbn)
CStdString strPath;
if (!m_bIsFolder)
URIUtils::GetDirectory(m_strPath, strPath);
else
strPath = m_strPath;
// music thumbs are cached without slash at end
URIUtils::RemoveSlashAtEnd(strPath);

CStdString thumb(CThumbnailCache::GetMusicThumb(strPath));
if (CFile::Exists(thumb))
return thumb;

return "";
}

CStdString CFileItem::GetUserMusicThumb(bool alwaysCheckRemote /* = false */) const
{
if (m_strPath.IsEmpty()
Expand Down Expand Up @@ -2554,37 +2431,10 @@ CStdString CFileItem::GetUserMusicThumb(bool alwaysCheckRemote /* = false */) co
}
}
}
// this adds support for files which inherit a folder.jpg icon which has not been cached yet.
// this occurs when queueing a top-level folder which has not been traversed yet.
else if (!IsRemote() || alwaysCheckRemote || g_guiSettings.GetBool("musicfiles.findremotethumbs"))
{
CStdString strFolder, strFile;
URIUtils::Split(m_strPath, strFolder, strFile);
if (!m_strPath.Equals(strFolder)) // any more parents to inherit from?
{
CFileItem folderItem(strFolder, true);
folderItem.SetMusicThumb(alwaysCheckRemote);
if (folderItem.HasThumbnail())
return folderItem.GetThumbnailImage();
}
}
// No thumb found
return "";
}

void CFileItem::SetUserMusicThumb(bool alwaysCheckRemote /* = false */)
{
// caches as the local thumb
CStdString thumb(GetUserMusicThumb(alwaysCheckRemote));
if (!thumb.IsEmpty())
{
CStdString cachedThumb(CThumbnailCache::GetMusicThumb(m_strPath));
CPicture::CreateThumbnail(thumb, cachedThumb);
}

SetCachedMusicThumb();
}

// Gets the .tbn filename from a file or folder name.
// <filename>.ext -> <filename>.tbn
// <foldername>/ -> <foldername>.tbn
Expand Down Expand Up @@ -2798,20 +2648,6 @@ bool CFileItem::testGetBaseMoviePath()
}
#endif

bool CFileItem::CacheLocalFanart() const
{
// first check for an already cached fanart image
CStdString cachedFanart(GetCachedFanart());
if (CFile::Exists(cachedFanart))
return true;

// we don't have a cached image, so let's see if the user has a local image, and cache it if so
CStdString localFanart(GetLocalFanart());
if (!localFanart.IsEmpty())
return CPicture::CacheFanart(localFanart, cachedFanart);
return false;
}

CStdString CFileItem::GetLocalFanart() const
{
if (IsVideoDb())
Expand Down Expand Up @@ -2912,43 +2748,6 @@ CStdString CFileItem::GetLocalMetadataPath() const
return parent;
}

CStdString CFileItem::GetCachedFanart() const
{
return CThumbnailCache::GetFanart(*this);
}

CStdString CFileItem::GetCachedThumb(const CStdString &path, const CStdString &path2, bool split)
{
return CThumbnailCache::GetThumb(path, path2, split);
}

/*void CFileItem::SetThumb()
{
// we need to know the type of file at this point
// as differing views have differing inheritance rules for thumbs:
// Videos:
// Folders only use <foldername>/folder.jpg or <foldername>.tbn
// Files use <filename>.tbn
// * Thumbs are cached from here using file or folder path
// Music:
// Folders only use <foldername>/folder.jpg or <foldername>.tbn
// Files use <filename>.tbn or the album/path cached thumb or inherit from the folder
// * Thumbs are cached from here using file or folder path
// Programs:
// Folders only use <foldername>/folder.jpg or <foldername>.tbn
// Files use <filename>.tbn or the embedded xbe. Shortcuts have the additional step of the <thumbnail> tag to check
// * Thumbs are cached from here using file or folder path
// Pictures:
// Folders use <foldername>/folder.jpg or <foldername>.tbn, or auto-generated from 4 images in the folder
// Files use <filename>.tbn or a resized version of the picture
// * Thumbs are cached from here using file or folder path
}*/

bool CFileItem::LoadMusicTag()
{
// not audio
Expand Down
Loading

0 comments on commit f70b7d7

Please sign in to comment.