Permalink
Browse files

[thumbs] song and album thumbs are retrieved using the thumbloader, s…

…o no need for them to be set when retrieving from the db.
  • Loading branch information...
1 parent fd9df6a commit 27e3814a0db2535b3bef2662cb7da5c27ee009a4 Jonathan Marshall committed Jun 24, 2012
View
@@ -91,10 +91,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);
}
@@ -110,7 +106,6 @@ CFileItem::CFileItem(const CMusicInfoTag& music)
m_bIsFolder = URIUtils::HasSlashAtEnd(m_strPath);
*GetMusicInfoTag() = music;
FillInDefaultIcon();
- SetCachedMusicThumb();
}
CFileItem::CFileItem(const CVideoInfoTag& movie)
@@ -570,9 +570,13 @@ bool CMusicThumbLoader::FillLibraryArt(CFileItem &item)
map<string, string> artwork;
if (m_database->GetArtForItem(tag.GetDatabaseId(), tag.GetType(), artwork))
item.SetArt(artwork);
- else
+ else if (tag.GetType() == "song")
+ { // no art for the song, try the album
+ if (m_database->GetArtForItem(tag.GetAlbumId(), "album", artwork))
+ item.SetArt(artwork);
+ }
+ else if (tag.GetType() == "artist")
{
- if (tag.GetType() == "artist")
{ // Need the artist thumb/fanart which isn't grabbed during normal directory fetches
CArtist artist;
m_database->GetArtistInfo(tag.GetDatabaseId(), artist, false);
@@ -121,8 +121,6 @@ bool CMusicDatabase::CreateTables()
m_pDS->exec("CREATE TABLE albuminfo ( idAlbumInfo integer primary key, idAlbum integer, iYear integer, strMoods text, strStyles text, strThemes text, strReview text, strImage text, strLabel text, strType text, iRating integer)\n");
CLog::Log(LOGINFO, "create albuminfosong table");
m_pDS->exec("CREATE TABLE albuminfosong ( idAlbumInfoSong integer primary key, idAlbumInfo integer, iTrack integer, strTitle text, iDuration integer)\n");
- CLog::Log(LOGINFO, "create thumb table");
- m_pDS->exec("CREATE TABLE thumb (idThumb integer primary key, strThumb varchar(256))\n");
CLog::Log(LOGINFO, "create artistnfo table");
m_pDS->exec("CREATE TABLE artistinfo ( idArtistInfo integer primary key, idArtist integer, strBorn text, strFormed text, strGenres text, strMoods text, strStyles text, strInstruments text, strBiography text, strDied text, strDisbanded text, strYearsActive text, strImage text, strFanart text)\n");
CLog::Log(LOGINFO, "create content table");
@@ -175,8 +173,6 @@ bool CMusicDatabase::CreateTables()
m_pDS->exec("CREATE UNIQUE INDEX idxSongGenre_1 ON song_genre ( idSong, idGenre )\n");
m_pDS->exec("CREATE UNIQUE INDEX idxSongGenre_2 ON song_genre ( idGenre, idSong )\n");
- CLog::Log(LOGINFO, "create thumb index");
- m_pDS->exec("CREATE INDEX idxThumb ON thumb(strThumb)");
//m_pDS->exec("CREATE INDEX idxSong ON song(dwFileNameCRC)");
CLog::Log(LOGINFO, "create artistinfo index");
m_pDS->exec("CREATE INDEX idxArtistInfo on artistinfo(idArtist)");
@@ -227,15 +223,13 @@ void CMusicDatabase::CreateViews()
" strMusicBrainzArtistID, strMusicBrainzAlbumID, strMusicBrainzAlbumArtistID,"
" strMusicBrainzTRMID, iTimesPlayed, iStartOffset, iEndOffset, lastplayed,"
" rating, comment, song.idAlbum AS idAlbum, strAlbum, strPath,"
- " strThumb, iKaraNumber, iKaraDelay, strKaraEncoding, "
+ " iKaraNumber, iKaraDelay, strKaraEncoding,"
" album.bCompilation AS bCompilation "
"FROM song"
" JOIN album ON"
" song.idAlbum=album.idAlbum"
" JOIN path ON"
" song.idPath=path.idPath"
- " LEFT OUTER JOIN thumb ON"
- " song.idThumb=thumb.idThumb"
" LEFT OUTER JOIN karaokedata ON"
" song.idSong=karaokedata.idSong");
@@ -246,12 +240,10 @@ void CMusicDatabase::CreateViews()
" album.strArtists AS strArtists,"
" album.strGenres AS strGenres, "
" album.iYear AS iYear,"
- " strThumb, idAlbumInfo, strMoods, strStyles, strThemes,"
+ " idAlbumInfo, strMoods, strStyles, strThemes,"
" strReview, strLabel, strType, strImage, iRating, "
" bCompilation "
"FROM album "
- " LEFT OUTER JOIN thumb ON"
- " album.idThumb=thumb.idThumb"
" LEFT OUTER JOIN albuminfo ON"
" album.idAlbum=albuminfo.idAlbum");
@@ -856,14 +848,11 @@ CSong CMusicDatabase::GetSongFromDataset(bool bWithMusicDbPath/*=false*/)
song.strMusicBrainzTRMID = m_pDS->fv(song_strMusicBrainzTRMID).get_asString();
song.rating = m_pDS->fv(song_rating).get_asChar();
song.strComment = m_pDS->fv(song_comment).get_asString();
- song.strThumb = m_pDS->fv(song_strThumb).get_asString();
song.iKaraokeNumber = m_pDS->fv(song_iKarNumber).get_asInt();
song.strKaraokeLyrEncoding = m_pDS->fv(song_strKarEncoding).get_asString();
song.iKaraokeDelay = m_pDS->fv(song_iKarDelay).get_asInt();
song.bCompilation = m_pDS->fv(song_bCompilation).get_asInt() == 1;
- if (song.strThumb == "NONE")
- song.strThumb.Empty();
// Get filename with full path
if (!bWithMusicDbPath)
URIUtils::AddFileToFolder(m_pDS->fv(song_strPath).get_asString(), m_pDS->fv(song_strFileName).get_asString(), song.strFileName);
@@ -916,9 +905,6 @@ void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const rec
item->GetMusicInfoTag()->SetURL(strRealPath);
item->GetMusicInfoTag()->SetCompilation(m_pDS->fv(song_bCompilation).get_asInt() == 1);
item->GetMusicInfoTag()->SetLoaded(true);
- CStdString strThumb = record->at(song_strThumb).get_asString();
- if (strThumb != "NONE")
- item->SetThumbnailImage(strThumb);
// Get filename with full path
if (strMusicDBbasePath.IsEmpty())
item->SetPath(strRealPath);
@@ -948,12 +934,6 @@ CAlbum CMusicDatabase::GetAlbumFromDataset(const dbiplus::sql_record* const reco
album.iYear = record->at(album_iYear).get_asInt();
if (imageURL)
album.thumbURL.ParseString(record->at(album_strThumbURL).get_asString());
- else
- {
- CStdString strThumb = record->at(album_strThumb).get_asString();
- if (strThumb != "NONE")
- album.thumbURL.ParseString(strThumb);
- }
album.iRating = record->at(album_iRating).get_asInt();
album.iYear = record->at(album_iYear).get_asInt();
album.strReview = record->at(album_strReview).get_asString();
@@ -3019,16 +2999,7 @@ bool CMusicDatabase::GetAlbumsNav(const CStdString& strBaseDir, CFileItemList& i
strWhere += "and albumview.strAlbum <> ''" + limit;
}
- bool bResult = GetAlbumsByWhere(strBaseDir, strWhere, "", items, sortDescription);
- if (bResult && idArtist != -1)
- {
- CStdString strArtist = GetArtistById(idArtist);
- CStdString strFanart = items.GetCachedThumb(strArtist,g_settings.GetMusicFanartFolder());
- if (CFile::Exists(strFanart))
- items.SetProperty("fanart_image",strFanart);
- }
-
- return bResult;
+ return GetAlbumsByWhere(strBaseDir, strWhere, "", items, sortDescription);
}
bool CMusicDatabase::GetAlbumsByWhere(const CStdString &baseDir, const CStdString &where, const CStdString &order, CFileItemList &items, const SortDescription &sortDescription /* = SortDescription() */)
@@ -3248,16 +3219,7 @@ bool CMusicDatabase::GetSongsNav(const CStdString& strBaseDir, CFileItemList& it
}
// run query
- bool bResult = GetSongsByWhere(strBaseDir, strWhere, items, sortDescription);
- if (bResult && idArtist != -1)
- {
- CStdString strArtist = GetArtistById(idArtist);
- CStdString strFanart = items.GetCachedThumb(strArtist,g_settings.GetMusicFanartFolder());
- if (CFile::Exists(strFanart))
- items.SetProperty("fanart_image",strFanart);
- }
-
- return bResult;
+ return GetSongsByWhere(strBaseDir, strWhere, items, sortDescription);
}
bool CMusicDatabase::UpdateOldVersion(int version)
@@ -3595,6 +3557,11 @@ bool CMusicDatabase::UpdateOldVersion(int version)
m_pDS->exec("CREATE TRIGGER delete_artist AFTER DELETE ON artist FOR EACH ROW BEGIN DELETE FROM art WHERE media_id=old.idArtist AND media_type='artist'; END");
}
+ if (version < 27)
+ {
+ m_pDS->exec("DROP TABLE thumb");
+ }
+
// always recreate the views after any table change
CreateViews();
@@ -3749,31 +3716,16 @@ bool CMusicDatabase::GetAlbumPath(int idAlbum, CStdString& path)
bool CMusicDatabase::SaveAlbumThumb(int idAlbum, const CStdString& strThumb)
{
- try
- {
- if (NULL == m_pDB.get()) return false;
- if (NULL == m_pDS.get()) return false;
-
- int idThumb=AddThumb(strThumb);
-
- if (idThumb>-1)
- {
- CStdString strSQL=PrepareSQL("UPDATE album SET idThumb=%ld where idAlbum=%ld", idThumb, idAlbum);
- CLog::Log(LOGDEBUG, "%s exec: %s", __FUNCTION__, strSQL.c_str());
- m_pDS->exec(strSQL.c_str());
- strSQL=PrepareSQL("UPDATE song SET idThumb=%ld where idAlbum=%ld", idThumb, idAlbum);
- CLog::Log(LOGDEBUG, "%s exec: %s", __FUNCTION__, strSQL.c_str());
- m_pDS->exec(strSQL.c_str());
- return true;
- }
- return false;
- }
- catch (...)
- {
- CLog::Log(LOGERROR, "%s(%i) failed", __FUNCTION__, idAlbum);
- }
-
- return false;
+ SetArtForItem(idAlbum, "album", "thumb", strThumb);
+ // TODO: We should prompt the user to update the art for songs
+ CStdString sql = PrepareSQL("UPDATE art"
+ " SET art_url='-'"
+ " WHERE media_type='song'"
+ " AND art_type='thumb'"
+ " AND media_id IN"
+ " (SELECT idSong FROM song WHERE idAlbum=%ld)", idAlbum);
+ ExecuteQuery(sql);
+ return true;
}
bool CMusicDatabase::GetAlbumThumb(int idAlbum, CStdString& strThumb)
@@ -4470,9 +4422,9 @@ void CMusicDatabase::ExportToXML(const CStdString &xmlFile, bool singleFiles, bo
if (images)
{
- CStdString strThumb;
- if (GetAlbumThumb(album.idAlbum,strThumb) && (overwrite || !CFile::Exists(URIUtils::AddFileToFolder(strPath,"folder.jpg"))))
- CFile::Cache(strThumb,URIUtils::AddFileToFolder(strPath,"folder.jpg"));
+ string thumb = GetArtForItem(album.idAlbum, "album", "thumb");
+ if (!thumb.empty() && (overwrite || !CFile::Exists(URIUtils::AddFileToFolder(strPath,"folder.jpg"))))
+ CTextureCache::Get().Export(thumb, URIUtils::AddFileToFolder(strPath,"folder.jpg"));
}
xmlDoc.Clear();
TiXmlDeclaration decl("1.0", "UTF-8", "yes");
@@ -300,7 +300,7 @@ class CMusicDatabase : public CDatabase
std::map<CStdString, CAlbumCache> m_albumCache;
virtual bool CreateTables();
- virtual int GetMinVersion() const { return 26; };
+ virtual int GetMinVersion() const { return 27; };
const char *GetBaseDBName() const { return "MyMusic"; };
int AddSong(const CSong& song, bool bCheck = true, int idAlbum = -1);
@@ -369,7 +369,6 @@ class CMusicDatabase : public CDatabase
song_idAlbum,
song_strAlbum,
song_strPath,
- song_strThumb,
song_iKarNumber,
song_iKarDelay,
song_strKarEncoding,
@@ -385,7 +384,6 @@ class CMusicDatabase : public CDatabase
album_strArtists,
album_strGenres,
album_iYear,
- album_strThumb,
album_idAlbumInfo,
album_strMoods,
album_strStyles,
@@ -226,12 +226,9 @@ void CGUIDialogMusicInfo::SetDiscography()
CFileItemPtr item(new CFileItem(m_artist.discography[i].first));
item->SetLabel2(m_artist.discography[i].second);
long idAlbum = database.GetAlbumByName(item->GetLabel(),m_artist.strArtist);
- CStdString strThumb;
- if (idAlbum != -1) // we need this slight stupidity to get correct case for the album name
- database.GetAlbumThumb(idAlbum,strThumb);
- if (!strThumb.IsEmpty() && CFile::Exists(strThumb))
- item->SetThumbnailImage(strThumb);
+ if (idAlbum != -1) // we need this slight stupidity to get correct case for the album name
+ item->SetThumbnailImage(database.GetArtForItem(idAlbum, "album", "thumb"));
else
item->SetThumbnailImage("DefaultAlbumCover.png");
@@ -178,6 +178,11 @@ const CStdString& CMusicInfoTag::GetAlbum() const
return m_strAlbum;
}
+int CMusicInfoTag::GetAlbumId() const
+{
+ return m_iAlbumId;
+}
+
const std::vector<std::string>& CMusicInfoTag::GetAlbumArtist() const
{
return m_albumArtist;
@@ -71,6 +71,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
const std::vector<std::string>& GetArtist() const;
int GetArtistId() const;
const CStdString& GetAlbum() const;
+ int GetAlbumId() const;
const std::vector<std::string>& GetAlbumArtist() const;
const std::vector<std::string> GetGenre() const;
int GetTrackNumber() const;
@@ -64,7 +64,7 @@
#include "utils/URIUtils.h"
#include "video/VideoInfoTag.h"
#include "utils/StringUtils.h"
-#include "ThumbnailCache.h"
+#include "ThumbLoader.h"
using namespace std;
using namespace XFILE;
@@ -1196,7 +1196,7 @@ void CGUIWindowMusicBase::UpdateThumb(const CAlbum &album, const CStdString &pat
saveDirThumb = false;
}
- CStdString albumThumb(CThumbnailCache::GetAlbumThumb(album));
+ CStdString albumThumb = m_musicdatabase.GetArtForItem(album.idAlbum, "album", "thumb");
// Update the thumb in the music database (songs + albums)
CStdString albumPath(path);
@@ -1243,9 +1243,8 @@ void CGUIWindowMusicBase::UpdateThumb(const CAlbum &album, const CStdString &pat
VECALBUMS albums;
CMusicInfoScanner::CategoriseAlbums(songs, albums);
if (albums.size() == 1)
- { // can cache as the folder thumb
- CStdString folderThumb(CThumbnailCache::GetMusicThumb(albumPath));
- CFile::Cache(albumThumb, folderThumb);
+ { // set as folder thumb as well
+ CThumbLoader::SetCachedImage(items, "thumb", albumPath);
}
}
@@ -1344,8 +1343,6 @@ bool CGUIWindowMusicBase::GetDirectory(const CStdString &strDirectory, CFileItem
void CGUIWindowMusicBase::OnPrepareFileItems(CFileItemList &items)
{
- if (!items.GetPath().Equals("plugin://music/"))
- items.SetCachedMusicThumbs();
}
CStdString CGUIWindowMusicBase::GetStartFolder(const CStdString &dir)
@@ -291,8 +291,6 @@ bool CGUIWindowMusicNav::GetDirectory(const CStdString &strDirectory, CFileItemL
{
if (items.IsPlayList())
OnRetrieveMusicInfo(items);
- if (!items.IsMusicDb())
- items.SetCachedMusicThumbs();
}
// update our content in the info manager
@@ -169,8 +169,6 @@ bool CGUIWindowMusicPlaylistEditor::GetDirectory(const CStdString &strDirectory,
void CGUIWindowMusicPlaylistEditor::OnPrepareFileItems(CFileItemList &items)
{
RetrieveMusicInfo();
-
- items.SetCachedMusicThumbs();
}
void CGUIWindowMusicPlaylistEditor::UpdateButtons()
@@ -209,8 +209,6 @@ bool CGUIWindowMusicSongs::GetDirectory(const CStdString &strDirectory, CFileIte
void CGUIWindowMusicSongs::OnPrepareFileItems(CFileItemList &items)
{
RetrieveMusicInfo();
-
- items.SetCachedMusicThumbs();
}
void CGUIWindowMusicSongs::UpdateButtons()
@@ -228,10 +228,6 @@ bool CRecentlyAddedJob::UpdateMusic()
CStdString strAlbum = item->GetMusicInfoTag()->GetAlbum();
CStdString strArtist = StringUtils::Join(item->GetMusicInfoTag()->GetArtist(), g_advancedSettings.m_musicItemSeparator);
- long idAlbum = musicdatabase.GetAlbumByName(strAlbum,strArtist);
- if (idAlbum != -1)
- musicdatabase.GetAlbumThumb(idAlbum,strThumb);
@Montellese
Montellese Jul 5, 2012 Member

Am I missing something here? This was the only place that filled strThumb which is used further down to fill the ListItem.X.Thumb for recently added album songs. How is this achieved now?

-
loader.LoadItem(item.get());
strRating.Format("%c", item->GetMusicInfoTag()->GetRating());
@@ -270,12 +266,14 @@ bool CRecentlyAddedJob::UpdateMusic()
CStdString value;
CStdString strPath;
CStdString strThumb;
+ CStdString strFanart;
CStdString strDBpath;
CStdString strSQLAlbum;
CAlbum& album=albums[i];
-
+
value.Format("%i", i + 1);
- musicdatabase.GetAlbumThumb(album.idAlbum,strThumb);
+ strThumb = musicdatabase.GetArtForItem(album.idAlbum, "album", "thumb");
+ strFanart = musicdatabase.GetArtistArtForItem(album.idAlbum, "album", "fanart");
strDBpath.Format("musicdb://3/%i/", album.idAlbum);
strSQLAlbum.Format("idAlbum=%i", album.idAlbum);
@@ -287,7 +285,7 @@ bool CRecentlyAddedJob::UpdateMusic()
home->SetProperty("LatestAlbum." + value + ".Rating" , musicdatabase.GetSingleValue("albumview", "iRating", strSQLAlbum));
home->SetProperty("LatestAlbum." + value + ".Path" , strDBpath);
home->SetProperty("LatestAlbum." + value + ".Thumb" , strThumb);
- home->SetProperty("LatestAlbum." + value + ".Fanart" , CFileItem::GetCachedThumb(strArtist,g_settings.GetMusicFanartFolder()));
+ home->SetProperty("LatestAlbum." + value + ".Fanart" , strFanart);
}
}
for (; i < NUM_ITEMS; ++i)

0 comments on commit 27e3814

Please sign in to comment.