// TODO: Currently no support for "embedded thumb" as there is no easy way to grab it // without sending a file that has this as it's album to this class void CGUIDialogSongInfo::OnGetThumb() { CFileItemList items; // Grab the thumbnail from the web CStdString thumbFromWeb; /* CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "allmusicThumb.jpg", thumbFromWeb); if (DownloadThumbnail(thumbFromWeb)) { CFileItemPtr item(new CFileItem("thumb://allmusic.com", false)); item->SetThumbnailImage(thumbFromWeb); item->SetLabel(g_localizeStrings.Get(20055)); items.Add(item); }*/ // Current thumb if (CFile::Exists(m_song->GetThumbnailImage())) { CFileItemPtr item(new CFileItem("thumb://Current", false)); item->SetThumbnailImage(m_song->GetThumbnailImage()); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } // local thumb CStdString cachedLocalThumb; CStdString localThumb(m_song->GetUserMusicThumb(true)); if (m_song->IsMusicDb()) { CFileItem item(m_song->GetMusicInfoTag()->GetURL(), false); localThumb = item.GetUserMusicThumb(true); } if (CFile::Exists(localThumb)) { CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "localthumb.jpg", cachedLocalThumb); CPicture pic; if (pic.DoCreateThumbnail(localThumb, cachedLocalThumb)) { CFileItemPtr item(new CFileItem("thumb://Local", false)); item->SetThumbnailImage(cachedLocalThumb); 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 // which is probably the allmusic.com thumb. These could be wrong, so allow the user // to delete the incorrect thumb CFileItemPtr item(new CFileItem("thumb://None", false)); item->SetThumbnailImage("defaultAlbumCover.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); } CStdString result; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, g_settings.m_musicSources, g_localizeStrings.Get(1030), result)) return; // user cancelled 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(CUtil::GetCachedAlbumThumb(m_song->GetMusicInfoTag()->GetAlbum(), m_song->GetMusicInfoTag()->GetArtist())); if (result == "thumb://None") { // cache the default thumb CPicture pic; pic.CacheSkinImage("defaultAlbumCover.png", cachedThumb); } else if (result == "thumb://allmusic.com") CFile::Cache(thumbFromWeb, cachedThumb); else if (result == "thumb://Local") CFile::Cache(cachedLocalThumb, cachedThumb); else if (CFile::Exists(result)) { CPicture pic; pic.DoCreateThumbnail(result, cachedThumb); } m_song->SetThumbnailImage(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); // m_hasUpdatedThumb = true; }
// Get Thumb from user choice. // Options are: // 1. Current thumb // 2. IMDb thumb // 3. Local thumb // 4. No thumb (if no Local thumb is available) void CGUIWindowVideoInfo::OnGetThumb() { CFileItemList items; // Grab the thumbnails from the web CStdString strPath; CUtil::AddFileToFolder(g_advancedSettings.m_cachePath,"imdbthumbs",strPath); CUtil::WipeDir(_P(strPath)); DIRECTORY::CDirectory::Create(strPath); int i=1; for (std::vector<CScraperUrl::SUrlEntry>::iterator iter=m_movieItem->GetVideoInfoTag()->m_strPictureURL.m_url.begin();iter != m_movieItem->GetVideoInfoTag()->m_strPictureURL.m_url.end();++iter) { if (iter->m_type == CScraperUrl::URL_TYPE_SEASON) continue; CStdString thumbFromWeb; CStdString strLabel; strLabel.Format("imdbthumb%i.jpg",i); CUtil::AddFileToFolder(strPath, strLabel, thumbFromWeb); if (CScraperUrl::DownloadThumbnail(thumbFromWeb,*iter)) { CStdString strItemPath; strItemPath.Format("thumb://IMDb%i",i++); CFileItem *item = new CFileItem(strItemPath, false); item->SetThumbnailImage(thumbFromWeb); CStdString strLabel; item->SetLabel(g_localizeStrings.Get(20015)); items.Add(item); } } if (CFile::Exists(m_movieItem->GetThumbnailImage())) { CFileItem *item = new CFileItem("thumb://Current", false); item->SetThumbnailImage(m_movieItem->GetThumbnailImage()); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } CStdString cachedLocalThumb; CStdString localThumb(m_movieItem->GetUserVideoThumb()); if (CFile::Exists(localThumb)) { CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "localthumb.jpg", cachedLocalThumb); CPicture pic; pic.DoCreateThumbnail(localThumb, cachedLocalThumb); CFileItem *item = new CFileItem("thumb://Local", false); item->SetThumbnailImage(cachedLocalThumb); item->SetLabel(g_localizeStrings.Get(20017)); items.Add(item); } else { // no local thumb exists, so we are just using the IMDb thumb or cached thumb // which is probably the IMDb thumb. These could be wrong, so allow the user // to delete the incorrect thumb CFileItem *item = new CFileItem("thumb://None", false); item->SetThumbnailImage("defaultVideoBig.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); } CStdString result; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, g_settings.m_videoSources, g_localizeStrings.Get(20019), result)) return; // user cancelled 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 CFileItem item(*m_movieItem->GetVideoInfoTag()); CStdString cachedThumb(item.GetCachedVideoThumb()); if (result.Mid(0,12) == "thumb://IMDb") { CStdString strFile; CUtil::AddFileToFolder(strPath,"imdbthumb"+result.Mid(12)+".jpg",strFile); if (CFile::Exists(strFile)) CFile::Cache(strFile, cachedThumb); else result = "thumb://None"; } else if (result == "thumb://Local") CFile::Cache(cachedLocalThumb, cachedThumb); else if (CFile::Exists(result)) { CPicture pic; pic.DoCreateThumbnail(result, cachedThumb); } else result = "thumb://None"; if (result == "thumb://None") { // cache the default thumb CPicture pic; pic.CacheSkinImage("defaultVideoBig.png", cachedThumb); } CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show m_movieItem->SetThumbnailImage(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(); }
// TODO: Currently no support for "embedded thumb" as there is no easy way to grab it // without sending a file that has this as it's album to this class void CGUIWindowMusicInfo::OnGetThumb() { CFileItemList items; // Grab the thumbnail from the web CStdString thumbFromWeb; CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "allmusicThumb", thumbFromWeb); int iDownloaded=DownloadThumbnail(thumbFromWeb,true); if (iDownloaded > 0) { for (int i=0;i<iDownloaded;++i) { CStdString strThumb; strThumb.Format("thumb://Remote%i",i); CFileItem *item = new CFileItem(strThumb, false); strThumb.Format("%s%i.tbn",thumbFromWeb,i); item->SetThumbnailImage(strThumb); item->SetLabel(g_localizeStrings.Get(20055)); items.Add(item); } } // Current thumb if (CFile::Exists(m_albumItem->GetThumbnailImage())) { CFileItem *item = new CFileItem("thumb://Current", false); item->SetThumbnailImage(m_albumItem->GetThumbnailImage()); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } // local thumb CStdString cachedLocalThumb; CStdString localThumb; if (m_bArtistInfo) { CMusicDatabase database; database.Open(); CStdString strArtistPath; database.GetArtistPath(m_artist.idArtist,strArtistPath); CUtil::AddFileToFolder(strArtistPath,"folder.jpg",localThumb); } else CStdString localThumb = m_albumItem->GetUserMusicThumb(); if (CFile::Exists(localThumb)) { CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "localthumb.jpg", cachedLocalThumb); CPicture pic; if (pic.DoCreateThumbnail(localThumb, cachedLocalThumb)) { CFileItem *item = new CFileItem("thumb://Local", false); item->SetThumbnailImage(cachedLocalThumb); item->SetLabel(g_localizeStrings.Get(20017)); items.Add(item); } } CFileItem *item = new CFileItem("thumb://None", false); if (m_bArtistInfo) item->SetThumbnailImage("defaultArtistBig.png"); else item->SetThumbnailImage("defaultAlbumCover.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); CStdString result; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, g_settings.m_musicSources, g_localizeStrings.Get(1030), result)) return; // user cancelled 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 = CUtil::GetCachedAlbumThumb(m_album.strAlbum, m_album.strArtist); if (result == "thumb://None") { // cache the default thumb CPicture pic; pic.CacheSkinImage("defaultAlbumCover.png", cachedThumb); } else if (result.Left(14).Equals("thumb://Remote")) CFile::Cache(thumbFromWeb+result.Mid(14)+".tbn", cachedThumb); else if (result == "thumb://Local") CFile::Cache(cachedLocalThumb, cachedThumb); else if (CFile::Exists(result)) { CPicture pic; pic.DoCreateThumbnail(result, cachedThumb); } m_albumItem->SetThumbnailImage(cachedThumb); 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); g_graphicsContext.SendMessage(msg); // Update our screen Update(); }
void CGUIWindowMusicNav::SetThumb(int iItem, CONTEXT_BUTTON button) { CFileItem* pItem = m_vecItems->Get(iItem); CFileItemList items; CStdString picturePath; CStdString strPath=pItem->m_strPath; CStdString strThumb; CStdString cachedThumb; if (button == CONTEXT_BUTTON_SET_ARTIST_THUMB) { long idArtist = -1; if (pItem->IsMusicDb()) { CUtil::RemoveSlashAtEnd(strPath); int nPos=strPath.ReverseFind("/"); if (nPos>-1) { // try to guess where the user should start // browsing for the artist thumb idArtist=atol(strPath.Mid(nPos+1)); } } else if (pItem->IsVideoDb()) idArtist = m_musicdatabase.GetArtistByName(pItem->GetLabel()); m_musicdatabase.GetArtistPath(idArtist, picturePath); cachedThumb = pItem->GetCachedArtistThumb(); CArtist artist; m_musicdatabase.GetArtistInfo(idArtist,artist); int i=1; for (std::vector<CScraperUrl::SUrlEntry>::iterator iter=artist.thumbURL.m_url.begin();iter != artist.thumbURL.m_url.end();++iter) { CStdString thumbFromWeb; CStdString strLabel; strLabel.Format("allmusicthumb%i.jpg",i); CUtil::AddFileToFolder("z:\\", strLabel, thumbFromWeb); if (CScraperUrl::DownloadThumbnail(thumbFromWeb,*iter)) { CStdString strItemPath; strItemPath.Format("thumb://Remote%i",i++); CFileItem *item = new CFileItem(strItemPath, false); item->SetThumbnailImage(thumbFromWeb); CStdString strLabel; item->SetLabel(g_localizeStrings.Get(20015)); items.Add(item); } } } else { strPath = m_vecItems->Get(iItem)->m_strPath; strPath.Replace("plugin://music/","Q:\\plugins\\music\\"); strPath.Replace("/","\\"); picturePath = strPath; CFileItem item(strPath,true); cachedThumb = item.GetCachedProgramThumb(); } if (XFILE::CFile::Exists(cachedThumb)) { CFileItem *item = new CFileItem("thumb://Current", false); item->SetThumbnailImage(cachedThumb); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } if (button == CONTEXT_BUTTON_SET_PLUGIN_THUMB) { if (items.Size() == 0) { CFileItem item2(strPath,false); CUtil::AddFileToFolder(strPath,"default.py",item2.m_strPath); if (XFILE::CFile::Exists(item2.GetCachedProgramThumb())) { CFileItem *item = new CFileItem("thumb://Current", false); item->SetThumbnailImage(item2.GetCachedProgramThumb()); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } } CUtil::AddFileToFolder(strPath,"default.tbn",strThumb); if (XFILE::CFile::Exists(strThumb)) { CFileItem* item = new CFileItem(strThumb,false); item->SetThumbnailImage(strThumb); item->SetLabel(g_localizeStrings.Get(20017)); items.Add(item); } } CUtil::AddFileToFolder(picturePath,"folder.jpg",strThumb); if (XFILE::CFile::Exists(strThumb)) { CFileItem* pItem = new CFileItem(strThumb,false); pItem->SetLabel(g_localizeStrings.Get(20017)); pItem->SetThumbnailImage(strThumb); items.Add(pItem); } CFileItem* nItem = new CFileItem("thumb://None",false); nItem->SetLabel(g_localizeStrings.Get(20018)); if (button == CONTEXT_BUTTON_SET_ARTIST_THUMB) nItem->SetThumbnailImage("DefaultArtistBig.png"); else nItem->SetThumbnailImage("DefaultFolderBig.png"); items.Add(nItem); if (CGUIDialogFileBrowser::ShowAndGetImage(items, g_settings.m_musicSources, g_localizeStrings.Get(20019), picturePath)) { CPicture picture; if (picturePath.Equals("thumb://Current")) return; if (picturePath.Equals("thumb://None")) { XFILE::CFile::Delete(cachedThumb); if (button == CONTEXT_BUTTON_SET_PLUGIN_THUMB) { CPicture picture; picture.CacheSkinImage("DefaultFolderBig.png",cachedThumb); CFileItem item2(strPath,false); CUtil::AddFileToFolder(strPath,"default.py",item2.m_strPath); XFILE::CFile::Delete(item2.GetCachedProgramThumb()); } } else if (button == CONTEXT_BUTTON_SET_PLUGIN_THUMB) XFILE::CFile::Cache(picturePath,cachedThumb); if (picturePath.Equals("thumb://None") || picture.DoCreateThumbnail(items.Get(picturePath)->GetThumbnailImage(), cachedThumb)) { CMusicDatabaseDirectory dir; dir.ClearDirectoryCache(m_vecItems->m_strPath); CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS); g_graphicsContext.SendMessage(msg); Update(m_vecItems->m_strPath); } else CLog::Log(LOGERROR, " %s Could not cache artist/plugin thumb: %s", __FUNCTION__, picturePath.c_str()); } }
// TODO: Currently no support for "embedded thumb" as there is no easy way to grab it // without sending a file that has this as it's album to this class void CGUIWindowMusicInfo::OnGetThumb() { CFileItemList items; // Grab the thumbnail from the web CStdString thumbFromWeb; CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "allmusicThumb", thumbFromWeb); CScraperUrl url; if (m_bArtistInfo) url = m_artist.thumbURL; else url = m_album.thumbURL; for (unsigned int i = 0; i < url.m_url.size(); i++) { CStdString strThumb; strThumb.Format("thumb://Remote%i",i); CFileItemPtr item(new CFileItem(strThumb, false)); item->SetThumbnailImage("http://this.is/a/thumb/from/the/web"); item->SetIconImage("defaultPicture.png"); item->GetVideoInfoTag()->m_strPictureURL.m_url.push_back(url.m_url[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); } // Current thumb if (CFile::Exists(m_albumItem->GetThumbnailImage())) { CFileItemPtr item(new CFileItem("thumb://Current", false)); item->SetThumbnailImage(m_albumItem->GetThumbnailImage()); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } // local thumb CStdString cachedLocalThumb; CStdString localThumb; if (m_bArtistInfo) { CMusicDatabase database; database.Open(); CStdString strArtistPath; database.GetArtistPath(m_artist.idArtist,strArtistPath); CUtil::AddFileToFolder(strArtistPath,"folder.jpg",localThumb); } else CStdString localThumb = m_albumItem->GetUserMusicThumb(); if (CFile::Exists(localThumb)) { CUtil::AddFileToFolder(g_advancedSettings.m_cachePath, "localthumb.jpg", cachedLocalThumb); CPicture pic; if (pic.DoCreateThumbnail(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://None", false)); if (m_bArtistInfo) item->SetThumbnailImage("defaultArtistBig.png"); else item->SetThumbnailImage("defaultAlbumCover.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); CStdString result; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, g_settings.m_musicSources, g_localizeStrings.Get(1030), result)) return; // user cancelled 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 = CUtil::GetCachedAlbumThumb(m_album.strAlbum, m_album.strArtist); if (result.Left(14).Equals("thumb://Remote")) { CStdString strFile; CFileItem chosen(result, false); CStdString thumb = chosen.GetCachedPictureThumb(); if (CFile::Exists(thumb)) { // NOTE: This could fail if the thumbloader was too slow and the user too impatient CFile::Cache(thumb, cachedThumb); } else result = "thumb://None"; } if (result == "thumb://None") { // cache the default thumb CPicture pic; pic.CacheSkinImage("defaultAlbumCover.png", cachedThumb); } else if (result == "thumb://Local") CFile::Cache(cachedLocalThumb, cachedThumb); else if (CFile::Exists(result)) { CPicture pic; pic.DoCreateThumbnail(result, cachedThumb); } m_albumItem->SetThumbnailImage(cachedThumb); 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); g_graphicsContext.SendMessage(msg); // Update our screen Update(); }