bool CFanart::DownloadImage(const CStdString &url, const CStdString &destination) const { // Ideally we'd just call CPicture::CacheImage() directly, but for some // reason curl doesn't seem to like downloading these for us CHTTP http; #ifdef RESAMPLE_CACHED_IMAGES CStdString tempFile = _P("Z:\\fanart_download.jpg"); if (http.Download(url, tempFile)) { CPicture pic; pic.CacheImage(tempFile, destination); XFILE::CFile::Delete(tempFile); return true; } return false; #else return http.Download(url, destination); #endif }
// Allow user to select a Fanart void CGUIWindowVideoInfo::OnGetFanart() { CFileItemList items; // Grab the thumbnails from the web CStdString strPath; CUtil::AddFileToFolder(g_advancedSettings.m_cachePath,"fanartthumbs",strPath); CUtil::WipeDir(strPath); DIRECTORY::CDirectory::Create(strPath); for (unsigned int i = 0; i < m_movieItem->GetVideoInfoTag()->m_fanart.GetNumFanarts(); i++) { CStdString thumbFromWeb; CStdString strLabel; strLabel.Format("fanart_thumb_%i.jpg", i); CUtil::AddFileToFolder(strPath, strLabel, thumbFromWeb); if (m_movieItem->GetVideoInfoTag()->m_fanart.DownloadThumb(i, thumbFromWeb)) { CStdString strItemPath; strItemPath.Format("thumb://FANART_%i",i); CFileItem *item = new CFileItem(strItemPath, false); item->SetThumbnailImage(thumbFromWeb); CStdString strLabel; item->SetLabel(g_localizeStrings.Get(20015)); items.Add(item); } else CLog::Log(LOGDEBUG, "Unable to download fanart thumb #%d", i); } CFileItem *itemNone = new CFileItem("thumb://None", false); itemNone->SetThumbnailImage("defaultVideoBig.png"); itemNone->SetLabel(g_localizeStrings.Get(20018)); items.Add(itemNone); CStdString result; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, g_settings.m_videoSources, g_localizeStrings.Get(20019), result)) return; // user cancelled // delete the thumbnail if that's what the user wants, else overwrite with the // new thumbnail CFileItem item(*m_movieItem->GetVideoInfoTag()); CStdString cachedThumb(item.GetCachedVideoFanart()); if (result.Mid(0,15) == "thumb://FANART_") { CStdString strFile; CUtil::AddFileToFolder(strPath,"fanart_thumb_"+result.Mid(15)+".jpg",strFile); int iFanart = atoi(result.Mid(15).c_str()); if (CFile::Exists(strFile)) { // set new primary fanart, and update our database accordingly m_movieItem->GetVideoInfoTag()->m_fanart.SetPrimaryFanart(iFanart); m_database.SetDetailsForTvShow(m_movieItem->m_strPath, *m_movieItem->GetVideoInfoTag()); // download the fullres fanart image. TODO: FANART - this could take some time, so should probably be backgrounded m_movieItem->GetVideoInfoTag()->m_fanart.DownloadImage(cachedThumb); } else result = "thumb://None"; } else if (CFile::Exists(result)) { // local file CPicture pic; pic.CacheImage(result, cachedThumb); } else result = "thumb://None"; if (result == "thumb://None") { // remove the cached art if (CFile::Exists(cachedThumb)) CFile::Delete(cachedThumb); } CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show // 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); g_graphicsContext.SendMessage(msg); // Update our screen Update(); }
// Allow user to select a Fanart void CGUIWindowMusicInfo::OnGetFanart() { CFileItemList items; CFileItemPtr itemNone(new CFileItem("fanart://None", false)); itemNone->SetThumbnailImage("DefaultArtistBig.png"); itemNone->SetLabel(g_localizeStrings.Get(20018)); items.Add(itemNone); CMusicDatabase database; database.Open(); CStdString strArtistPath; database.GetArtistPath(m_artist.idArtist,strArtistPath); CStdString cachedThumb(itemNone->GetCachedFanart(strArtistPath)); if (CFile::Exists(cachedThumb)) { CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false)); itemCurrent->SetThumbnailImage(cachedThumb); itemCurrent->SetLabel(g_localizeStrings.Get(20016)); items.Add(itemCurrent); } CFileItem item(strArtistPath,true); CStdString strLocal = item.CacheFanart(true); if (!strLocal.IsEmpty()) { CFileItemPtr itemLocal(new CFileItem("fanart://Local",false)); itemLocal->SetThumbnailImage(strLocal); itemLocal->SetLabel(g_localizeStrings.Get(20017)); items.Add(itemLocal); } CStdString result; VECSOURCES sources(g_settings.m_musicSources); g_mediaManager.GetLocalDrives(sources); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20019), result)) return; // user cancelled // delete the thumbnail if that's what the user wants, else overwrite with the // new thumbnail if (result.Equals("fanart://Current")) return; if (result.Equals("fanart://Local")) result = strLocal; if (CFile::Exists(cachedThumb)) CFile::Delete(cachedThumb); if (!result.Equals("thumb://None") && CFile::Exists(result)) { // local file CPicture pic; pic.CacheImage(result, cachedThumb); } // 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); g_graphicsContext.SendMessage(msg); // Update our screen Update(); }
// Allow user to select a Fanart void CGUIWindowVideoInfo::OnGetFanart() { CFileItemList items; // ensure the fanart is unpacked m_movieItem->GetVideoInfoTag()->m_fanart.Unpack(); // Grab the thumbnails from the web CStdString strPath; CUtil::AddFileToFolder(g_advancedSettings.m_cachePath,"fanartthumbs",strPath); CUtil::WipeDir(strPath); DIRECTORY::CDirectory::Create(strPath); for (unsigned int i = 0; i < m_movieItem->GetVideoInfoTag()->m_fanart.GetNumFanarts(); i++) { CStdString strItemPath; strItemPath.Format("fanart://Remote%i",i); CFileItemPtr item(new CFileItem(strItemPath, false)); item->SetThumbnailImage("http://this.is/a/thumb/from/the/web"); item->SetIconImage("defaultPicture.png"); item->GetVideoInfoTag()->m_fanart = m_movieItem->GetVideoInfoTag()->m_fanart; item->SetProperty("fanart_number", (int)i); item->SetLabel(g_localizeStrings.Get(415)); item->SetProperty("labelonthumbload", g_localizeStrings.Get(20015)); // make sure any previously cached thumb is removed if (CFile::Exists(item->GetCachedPictureThumb())) CFile::Delete(item->GetCachedPictureThumb()); items.Add(item); } CFileItem item(*m_movieItem->GetVideoInfoTag()); CStdString cachedThumb(item.GetCachedFanart()); CStdString strLocal = item.CacheFanart(true); if (!strLocal.IsEmpty()) { CFileItemPtr itemLocal(new CFileItem("fanart://Local",false)); itemLocal->SetThumbnailImage(strLocal); itemLocal->SetLabel(g_localizeStrings.Get(20017)); items.Add(itemLocal); } if (CFile::Exists(cachedThumb)) { CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false)); itemCurrent->SetThumbnailImage(cachedThumb); itemCurrent->SetLabel(g_localizeStrings.Get(20016)); items.Add(itemCurrent); } CFileItemPtr itemNone(new CFileItem("fanart://None", false)); itemNone->SetThumbnailImage("defaultVideoBig.png"); itemNone->SetLabel(g_localizeStrings.Get(20018)); items.Add(itemNone); CStdString result; VECSOURCES sources(g_settings.m_videoSources); g_mediaManager.GetLocalDrives(sources); bool flip=false; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20019), result, &flip) || result.Equals("fanart://Current")) return; // user cancelled if (CFile::Exists(cachedThumb)) CFile::Delete(cachedThumb); if (result.Equals("fanart://Local")) result = strLocal; if (result.Left(15) == "fanart://Remote") { int iFanart = atoi(result.Mid(15).c_str()); // set new primary fanart, and update our database accordingly m_movieItem->GetVideoInfoTag()->m_fanart.SetPrimaryFanart(iFanart); CVideoDatabase db; if (db.Open()) { db.UpdateFanart(*m_movieItem, GetContentType(m_movieItem.get())); db.Close(); } // download the fullres fanart image CStdString tempFile = "special://temp/fanart_download.jpg"; CAsyncFileCopy downloader; bool succeeded = downloader.Copy(m_movieItem->GetVideoInfoTag()->m_fanart.GetImageURL(), tempFile, g_localizeStrings.Get(13413)); if (succeeded) { CPicture pic; if (flip) pic.ConvertFile(tempFile, cachedThumb,0,1920,-1,100,true); else pic.CacheImage(tempFile, cachedThumb); } CFile::Delete(tempFile); if (!succeeded) return; // failed or cancelled download, so don't do anything } else if (CFile::Exists(result)) { // local file CPicture pic; if (flip) pic.ConvertFile(result, cachedThumb,0,1920,-1,100,true); else pic.CacheImage(result, cachedThumb); } CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show if (CFile::Exists(cachedThumb)) m_movieItem->SetProperty("fanart_image", cachedThumb); else m_movieItem->ClearProperty("fanart_image"); m_hasUpdatedThumb = true; // Update our screen Update(); }