Skip to content

Commit

Permalink
on scan, add actor thumbs to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Marshall committed May 8, 2012
1 parent 61f1129 commit 0dd283a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
20 changes: 11 additions & 9 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -1244,12 +1244,13 @@ int CVideoDatabase::AddCountry(const CStdString& strCountry)
return AddToTable("country", "idCountry", "strCountry", strCountry);
}

int CVideoDatabase::AddActor(const CStdString& strActor, const CStdString& thumbURLs)
int CVideoDatabase::AddActor(const CStdString& strActor, const CStdString& thumbURLs, const CStdString &thumb)
{
try
{
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;
int idActor = -1;
CStdString strSQL=PrepareSQL("select idActor from actors where strActor like '%s'", strActor.c_str());
m_pDS->query(strSQL.c_str());
if (m_pDS->num_rows() == 0)
Expand All @@ -1258,22 +1259,23 @@ int CVideoDatabase::AddActor(const CStdString& strActor, const CStdString& thumb
// doesnt exists, add it
strSQL=PrepareSQL("insert into actors (idActor, strActor, strThumb) values( NULL, '%s','%s')", strActor.c_str(),thumbURLs.c_str());
m_pDS->exec(strSQL.c_str());
int idActor = (int)m_pDS->lastinsertid();
return idActor;
idActor = (int)m_pDS->lastinsertid();
}
else
{
int idActor = m_pDS->fv("idActor").get_asInt();
idActor = m_pDS->fv("idActor").get_asInt();
m_pDS->close();
// update the thumb url's
if (!thumbURLs.IsEmpty())
{
strSQL=PrepareSQL("update actors set strThumb='%s' where idActor=%i",thumbURLs.c_str(),idActor);
m_pDS->exec(strSQL.c_str());
}
return idActor;
}

// add artwork
if (!thumb.IsEmpty())
SetArtForItem(idActor, "actor", "thumb", thumb);
return idActor;
}
catch (...)
{
Expand Down Expand Up @@ -1837,7 +1839,7 @@ int CVideoDatabase::SetDetailsForMovie(const CStdString& strFilenameAndPath, con
int order = 0;
for (CVideoInfoTag::iCast it = details.m_cast.begin(); it != details.m_cast.end(); ++it)
{
int idActor = AddActor(it->strName,it->thumbUrl.m_xml);
int idActor = AddActor(it->strName, it->thumbUrl.m_xml, it->thumb);
AddActorToMovie(idMovie, idActor, it->strRole, order++);
}

Expand Down Expand Up @@ -1913,7 +1915,7 @@ int CVideoDatabase::SetDetailsForTvShow(const CStdString& strPath, const CVideoI
int order = 0;
for (CVideoInfoTag::iCast it = details.m_cast.begin(); it != details.m_cast.end(); ++it)
{
int idActor = AddActor(it->strName,it->thumbUrl.m_xml);
int idActor = AddActor(it->strName, it->thumbUrl.m_xml, it->thumb);
AddActorToTvShow(idTvShow, idActor, it->strRole, order++);
}

Expand Down Expand Up @@ -1987,7 +1989,7 @@ int CVideoDatabase::SetDetailsForEpisode(const CStdString& strFilenameAndPath, c
int order = 0;
for (CVideoInfoTag::iCast it = details.m_cast.begin(); it != details.m_cast.end(); ++it)
{
int idActor = AddActor(it->strName,it->thumbUrl.m_xml);
int idActor = AddActor(it->strName, it->thumbUrl.m_xml, it->thumb);
AddActorToEpisode(idEpisode, idActor, it->strRole, order++);
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/VideoDatabase.h
Expand Up @@ -661,7 +661,7 @@ class CVideoDatabase : public CDatabase

int AddToTable(const CStdString& table, const CStdString& firstField, const CStdString& secondField, const CStdString& value);
int AddGenre(const CStdString& strGenre1);
int AddActor(const CStdString& strActor, const CStdString& strThumb);
int AddActor(const CStdString& strActor, const CStdString& thumbURL, const CStdString &thumb = "");
int AddCountry(const CStdString& strCountry);
int AddSet(const CStdString& strSet);
int AddStudio(const CStdString& strStudio1);
Expand Down
19 changes: 9 additions & 10 deletions xbmc/video/VideoInfoScanner.cpp
Expand Up @@ -1665,23 +1665,22 @@ namespace VIDEO
m_database.Close();
}

void CVideoInfoScanner::FetchActorThumbs(const vector<SActorInfo>& actors, const CStdString& strPath)
void CVideoInfoScanner::FetchActorThumbs(vector<SActorInfo>& actors, const CStdString& strPath)
{
for (unsigned int i=0;i<actors.size();++i)
for (vector<SActorInfo>::iterator i = actors.begin(); i != actors.end(); ++i)
{
CFileItem item;
item.SetLabel(actors[i].strName);
CStdString strThumb = item.GetCachedActorThumb();
if (!CFile::Exists(strThumb))
if (i->thumb.IsEmpty())
{
CStdString thumbFile = actors[i].strName;
CStdString thumbFile = i->strName;
thumbFile.Replace(" ","_");
thumbFile += ".tbn";
CStdString strLocal = URIUtils::AddFileToFolder(URIUtils::AddFileToFolder(strPath, ".actors"), thumbFile);
if (CFile::Exists(strLocal))
CPicture::CreateThumbnail(strLocal, strThumb);
else if (!actors[i].thumbUrl.GetFirstThumb().m_url.IsEmpty())
DownloadImage(CScraperUrl::GetThumbURL(actors[i].thumbUrl.GetFirstThumb()), strThumb);
i->thumb = strLocal;
else if (!i->thumbUrl.GetFirstThumb().m_url.IsEmpty())
i->thumb = CScraperUrl::GetThumbURL(i->thumbUrl.GetFirstThumb());
if (!i->thumb.IsEmpty())
CTextureCache::Get().BackgroundCacheImage(strLocal);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion xbmc/video/VideoInfoScanner.h
Expand Up @@ -195,7 +195,13 @@ namespace VIDEO
*/
bool GetAirDateFromRegExp(CRegExp &reg, SEpisode &episodeInfo);

void FetchActorThumbs(const std::vector<SActorInfo>& actors, const CStdString& strPath);
/*! \brief Fetch thumbs for actors
Updates each actor with their thumb (local or online)
\param actors - vector of SActorInfo
\param strPath - path on filesystem to look for local thumbs
*/
void FetchActorThumbs(std::vector<SActorInfo>& actors, const CStdString& strPath);

static int GetPathHash(const CFileItemList &items, CStdString &hash);

/*! \brief Retrieve a "fast" hash of the given directory (if available)
Expand Down
2 changes: 2 additions & 0 deletions xbmc/video/VideoInfoTag.cpp
Expand Up @@ -284,6 +284,7 @@ void CVideoInfoTag::Archive(CArchive& ar)
{
ar << m_cast[i].strName;
ar << m_cast[i].strRole;
ar << m_cast[i].thumb;
ar << m_cast[i].thumbUrl.m_xml;
}

Expand Down Expand Up @@ -355,6 +356,7 @@ void CVideoInfoTag::Archive(CArchive& ar)
SActorInfo info;
ar >> info.strName;
ar >> info.strRole;
ar >> info.thumb;
CStdString strXml;
ar >> strXml;
info.thumbUrl.ParseString(strXml);
Expand Down
1 change: 1 addition & 0 deletions xbmc/video/VideoInfoTag.h
Expand Up @@ -38,6 +38,7 @@ struct SActorInfo
CStdString strName;
CStdString strRole;
CScraperUrl thumbUrl;
CStdString thumb;
};

class CVideoInfoTag : public IArchivable, public ISerializable
Expand Down

0 comments on commit 0dd283a

Please sign in to comment.