Permalink
Browse files

move video (files and embedded) thumbs to the texture cache

  • Loading branch information...
1 parent 8c53e69 commit 6c1daa062611eafd156046b4c2a30d5613c229b9 Jonathan Marshall committed Feb 29, 2012
View
3 xbmc/ApplicationMessenger.cpp
@@ -69,6 +69,7 @@
#include "utils/JobManager.h"
#include "storage/DetectDVDType.h"
+#include "ThumbLoader.h"
using namespace std;
@@ -829,7 +830,7 @@ void CApplicationMessenger::MediaPlay(string filename)
if (item.IsAudio())
item.SetMusicThumb();
else
- item.SetVideoThumb();
+ item.SetThumbnailImage(CVideoThumbLoader::GetLocalThumb(item));
item.FillInDefaultIcon();
MediaPlay(item);
View
18 xbmc/GUIInfoManager.cpp
@@ -3579,12 +3579,16 @@ void CGUIInfoManager::SetCurrentMovie(CFileItem &item)
}
// Find a thumb for this file.
- item.SetVideoThumb();
if (!item.HasThumbnail())
{
- CStdString thumbURL = CVideoThumbLoader::GetEmbeddedThumbURL(item);
- if (!CTextureCache::Get().GetCachedImage(thumbURL).IsEmpty())
- item.SetThumbnailImage(thumbURL);
+ CStdString thumb = CVideoThumbLoader::GetLocalThumb(item);
+ if (thumb.IsEmpty())
+ {
+ CStdString thumb = CVideoThumbLoader::GetEmbeddedThumbURL(item);
+ if (CTextureCache::Get().GetCachedImage(thumb).IsEmpty())
+ thumb.clear();
+ }
+ item.SetThumbnailImage(thumb);
}
// find a thumb for this stream
@@ -3602,9 +3606,9 @@ void CGUIInfoManager::SetCurrentMovie(CFileItem &item)
{
CLog::Log(LOGDEBUG,"Streaming media detected... using %s to find a thumb", g_application.m_strPlayListFile.c_str());
CFileItem thumbItem(g_application.m_strPlayListFile,false);
- thumbItem.SetVideoThumb();
- if (thumbItem.HasThumbnail())
- item.SetThumbnailImage(thumbItem.GetThumbnailImage());
+ CStdString thumb = CVideoThumbLoader::GetLocalThumb(thumbItem);
+ if (!thumb.IsEmpty())
+ item.SetThumbnailImage(thumb);
}
}
View
52 xbmc/ThumbLoader.cpp
@@ -207,6 +207,7 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
|| pItem->IsParentFolder())
return false;
+ // resume point
if (pItem->HasVideoInfoTag() && pItem->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds == 0)
{
CVideoDatabase db;
@@ -216,29 +217,36 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
db.Close();
}
- CStdString cachedThumb(pItem->GetCachedVideoThumb());
-
+ // fanart
if (!pItem->HasProperty("fanart_image"))
{
- if (pItem->CacheLocalFanart())
- pItem->SetProperty("fanart_image",pItem->GetCachedFanart());
+ CStdString fanart = GetCachedImage(*pItem, "fanart");
+ if (fanart.IsEmpty())
+ {
+ fanart = pItem->GetLocalFanart();
+ if (!fanart.IsEmpty()) // cache it
+ SetCachedImage(*pItem, "fanart", fanart);
+ }
+ if (!fanart.IsEmpty())
+ {
+ CTextureCache::Get().BackgroundCacheImage(fanart);
+ pItem->SetProperty("fanart_image", fanart);
+ }
}
+ // thumbnails
if (!pItem->HasThumbnail())
{
- pItem->SetUserVideoThumb();
- if (CFile::Exists(cachedThumb))
- pItem->SetThumbnailImage(cachedThumb);
- else if (!pItem->m_bIsFolder && pItem->IsVideo())
+ CStdString thumb = GetLocalThumb(*pItem);
+ if (thumb.IsEmpty() && !pItem->m_bIsFolder && pItem->IsVideo())
{
// create unique thumb for auto generated thumbs
CStdString thumbURL = GetEmbeddedThumbURL(*pItem);
- cachedThumb = CTextureCache::Get().GetCachedImage(thumbURL);
- if (!cachedThumb.IsEmpty())
+ if (!CTextureCache::Get().GetCachedImage(thumbURL).IsEmpty())
{
pItem->SetProperty("HasAutoThumb", true);
pItem->SetProperty("AutoThumbImage", thumbURL);
- pItem->SetThumbnailImage(cachedThumb);
+ pItem->SetThumbnailImage(thumbURL);
}
else if (g_guiSettings.GetBool("myvideos.extractthumb") &&
g_guiSettings.GetBool("myvideos.extractflags"))
@@ -250,13 +258,17 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
CThumbExtractor* extract = new CThumbExtractor(item, path, true, thumbURL);
AddJob(extract);
- return true;
}
+ return true;
+ }
+ if (!thumb.IsEmpty())
+ {
+ CTextureCache::Get().BackgroundCacheImage(thumb);
+ pItem->SetThumbnailImage(thumb);
}
}
- else if (!pItem->GetThumbnailImage().Left(10).Equals("special://"))
- LoadRemoteThumb(pItem);
+ // flag extraction
if (!pItem->m_bIsFolder &&
pItem->HasVideoInfoTag() &&
g_guiSettings.GetBool("myvideos.extractflags") &&
@@ -274,6 +286,18 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
return true;
}
+CStdString CVideoThumbLoader::GetLocalThumb(const CFileItem &item)
+{
+ CStdString thumb = GetCachedImage(item, "thumb");
+ if (thumb.IsEmpty())
+ {
+ thumb = item.GetUserVideoThumb();
+ if (!thumb.IsEmpty())
+ SetCachedImage(item, "thumb", thumb);
+ }
+ return thumb;
+}
+
CStdString CVideoThumbLoader::GetEmbeddedThumbURL(const CFileItem &item)
{
CStdString path(item.GetPath());
View
6 xbmc/ThumbLoader.h
@@ -92,6 +92,12 @@ class CVideoThumbLoader : public CThumbLoader, public CJobQueue
virtual bool LoadItem(CFileItem* pItem);
void SetStreamDetailsObserver(IStreamDetailsObserver *pObs) { m_pStreamDetailsObs = pObs; }
+ /*! \brief Get a local thumb for a video item
+ \param item a video CFileItem.
+ \return the URL for the local thumb
+ */
+ static CStdString GetLocalThumb(const CFileItem &item);
+
/*! \brief helper function to retrieve a thumb URL for embedded video thumbs
\param item a video CFileItem.
\return a URL for the embedded thumb.
View
4 xbmc/dialogs/GUIDialogContextMenu.cpp
@@ -552,9 +552,7 @@ bool CGUIDialogContextMenu::OnContextButton(const CStdString &type, const CFileI
URIUtils::RemoveSlashAtEnd(cachedThumb);
cachedThumb = CThumbnailCache::GetMusicThumb(cachedThumb);
}
- else if (type == "video")
- cachedThumb = item->GetCachedVideoThumb();
- else // assume "programs"
+ else // programs, video, pictures
{ // store the thumb for this share
CTextureDatabase db;
if (db.Open())
View
7 xbmc/interfaces/http-api/XBMChttp.cpp
@@ -52,6 +52,7 @@
#include "utils/log.h"
#include "TextureCache.h"
#include "ThumbnailCache.h"
+#include "ThumbLoader.h"
#ifdef _WIN32
extern "C" FILE *fopen_utf8(const char *_Filename, const char *_Mode);
@@ -1255,11 +1256,11 @@ int CXbmcHttp::xbmcGetMovieDetails(int numParas, CStdString paras[])
cast += character;
}*/
output += closeTag+openTag+"Cast:" + cast;
- item->SetVideoThumb();
- if (!item->HasThumbnail())
+ thumb = CVideoThumbLoader::GetLocalThumb(*item);
+ if (thumb.IsEmpty())
thumb = "[None]";
else
- thumb = item->GetCachedVideoThumb();
+ thumb = CTextureCache::Get().CheckAndCacheImage(thumb);
output += closeTag+openTag+"Thumb:" + thumb;
m_database.Close();
delete item;
View
3 xbmc/network/UPnP.cpp
@@ -58,6 +58,7 @@
#include "utils/TimeUtils.h"
#include "utils/md5.h"
#include "guilib/Key.h"
+#include "ThumbLoader.h"
using namespace std;
using namespace MUSIC_INFO;
@@ -926,7 +927,7 @@ CUPnPServer::Build(CFileItemPtr item,
}
if (!item->HasThumbnail() )
- item->SetCachedVideoThumb();
+ item->SetThumbnailImage(CThumbLoader::GetCachedImage(*item, "thumb"));
}
}
View
4 xbmc/pictures/PictureThumbLoader.cpp
@@ -68,8 +68,8 @@ bool CPictureThumbLoader::LoadItem(CFileItem* pItem)
}
else if (pItem->IsVideo() && !pItem->IsZIP() && !pItem->IsRAR() && !pItem->IsCBZ() && !pItem->IsCBR() && !pItem->IsPlayList())
{ // video
- thumb = pItem->GetCachedVideoThumb();
- if (!CFile::Exists(thumb))
+ CStdString thumb = CVideoThumbLoader::GetLocalThumb(*pItem);
+ if (thumb.IsEmpty())
{
CStdString thumbURL = CVideoThumbLoader::GetEmbeddedThumbURL(*pItem);
CStdString cachedThumb = CTextureCache::Get().GetCachedImage(thumbURL);
View
6 xbmc/video/VideoInfoScanner.cpp
@@ -46,6 +46,7 @@
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
+#include "ThumbLoader.h"
using namespace std;
using namespace XFILE;
@@ -1516,11 +1517,10 @@ namespace VIDEO
void CVideoInfoScanner::ApplyThumbToFolder(const CStdString &folder, const CStdString &imdbThumb)
{
// copy icon to folder also;
- if (CFile::Exists(imdbThumb))
+ if (!imdbThumb.IsEmpty())
{
CFileItem folderItem(folder, true);
- CStdString strThumb(folderItem.GetCachedVideoThumb());
- CFile::Cache(imdbThumb.c_str(), strThumb.c_str(), NULL, NULL);
+ CThumbLoader::SetCachedImage(folderItem, "thumb", imdbThumb);
}
}
View
43 xbmc/video/dialogs/GUIDialogVideoInfo.cpp
@@ -410,17 +410,17 @@ void CGUIDialogVideoInfo::Refresh()
bool hasUpdatedThumb = false;
CStdString thumbImage = m_movieItem->GetThumbnailImage();
if (thumbImage.IsEmpty())
- thumbImage = m_movieItem->GetCachedVideoThumb();
+ thumbImage = CThumbLoader::GetCachedImage(*m_movieItem, "thumb");
- if (!CFile::Exists(thumbImage) || m_movieItem->GetProperty("HasAutoThumb") == "1")
+ if (thumbImage.IsEmpty() || m_movieItem->GetProperty("HasAutoThumb") == "1")
{ // don't have a thumb already, try and grab one
- m_movieItem->SetUserVideoThumb();
- if (m_movieItem->GetThumbnailImage() != thumbImage)
- thumbImage = m_movieItem->GetThumbnailImage();
- if (!CFile::Exists(thumbImage) && strImage.size() > 0)
- CScraperUrl::DownloadThumbnail(thumbImage,m_movieItem->GetVideoInfoTag()->m_strPictureURL.GetFirstThumb());
+ CStdString localThumb = m_movieItem->GetUserVideoThumb();
+ if (!localThumb.IsEmpty())
+ thumbImage = localThumb;
+ if (thumbImage.IsEmpty() && strImage.size() > 0)
+ thumbImage = CScraperUrl::GetThumbURL(m_movieItem->GetVideoInfoTag()->m_strPictureURL.GetFirstThumb());
- if (CFile::Exists(thumbImage))
+ if (!thumbImage.IsEmpty())
{
if (m_movieItem->HasProperty("set_folder_thumb"))
VIDEO::CVideoInfoScanner::ApplyThumbToFolder(m_movieItem->GetProperty("set_folder_thumb").asString(), thumbImage);
@@ -679,38 +679,31 @@ void CGUIDialogVideoInfo::OnGetThumb()
if (result == "thumb://Current")
return; // user chose the one they have
+ CStdString newThumb;
// delete the thumbnail if that's what the user wants, else overwrite with the
// new thumbnail
CFileItem item(*m_movieItem->GetVideoInfoTag());
- CStdString cachedThumb(item.GetCachedVideoThumb());
- if (!m_movieItem->m_bIsFolder && m_movieItem->GetVideoInfoTag()->m_iSeason > -1)
- cachedThumb = item.GetCachedEpisodeThumb();
- CTextureCache::Get().ClearCachedImage(cachedThumb, true);
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")
- {
- CFile::Delete(m_movieItem->GetCachedVideoThumb());
- CFile::Delete(m_movieItem->GetCachedEpisodeThumb());
- cachedThumb.Empty();
- }
+ // update any cached texture
+ CThumbLoader::SetCachedImage(item, "thumb", newThumb);
CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show
- m_movieItem->SetThumbnailImage(cachedThumb);
+ m_movieItem->SetThumbnailImage(newThumb);
if (m_movieItem->HasProperty("set_folder_thumb"))
{ // have a folder thumb to set as well
- VIDEO::CVideoInfoScanner::ApplyThumbToFolder(m_movieItem->GetProperty("set_folder_thumb").asString(), cachedThumb);
+ VIDEO::CVideoInfoScanner::ApplyThumbToFolder(m_movieItem->GetProperty("set_folder_thumb").asString(), newThumb);
}
m_hasUpdatedThumb = true;
View
16 xbmc/video/windows/GUIWindowVideoBase.cpp
@@ -1763,22 +1763,6 @@ bool CGUIWindowVideoBase::StackingAvailable(const CFileItemList &items) const
void CGUIWindowVideoBase::OnPrepareFileItems(CFileItemList &items)
{
- if (!items.GetPath().Equals("plugin://video/"))
- items.SetCachedVideoThumbs();
-
- if (items.GetContent() != "episodes")
- { // we don't set cached fanart for episodes, as this requires a db fetch per episode
- for (int i = 0; i < items.Size(); ++i)
- {
- CFileItemPtr item = items[i];
- if (!item->HasProperty("fanart_image"))
- {
- CStdString art = item->GetCachedFanart();
- if (CFile::Exists(art))
- item->SetProperty("fanart_image", art);
- }
- }
- }
}
void CGUIWindowVideoBase::AddToDatabase(int iItem)

0 comments on commit 6c1daa0

Please sign in to comment.