Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
pass the tvshow CVideoInfoTag to OnProcessSeriesFolder and AddVideo t…
…o save doing constant db lookups (2 per episode added)
  • Loading branch information
Jonathan Marshall committed Oct 11, 2012
1 parent 0a2f36a commit c241e0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
14 changes: 7 additions & 7 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -8669,7 +8669,7 @@ void CVideoDatabase::ImportFromXML(const CStdString &path)
if (ImportArtFromXML(movie->FirstChild("art"), artwork))
item.SetArt(artwork);
bool useFolders = info.m_basePath.IsEmpty() ? LookupByFolders(item.GetPath()) : false;
scanner.AddVideo(&item, CONTENT_MOVIES, useFolders, true, -1, true);
scanner.AddVideo(&item, CONTENT_MOVIES, useFolders, true, NULL, true);
CStdString strFileName(info.m_strTitle);
if (iVersion >= 1 && info.m_iYear > 0)
strFileName.AppendFormat("_%i", info.m_iYear);
Expand All @@ -8683,7 +8683,7 @@ void CVideoDatabase::ImportFromXML(const CStdString &path)
if (ImportArtFromXML(movie->FirstChild("art"), artwork))
item.SetArt(artwork);
bool useFolders = info.m_basePath.IsEmpty() ? LookupByFolders(item.GetPath()) : false;
scanner.AddVideo(&item, CONTENT_MUSICVIDEOS, useFolders, true, -1, true);
scanner.AddVideo(&item, CONTENT_MUSICVIDEOS, useFolders, true, NULL, true);
CStdString strFileName(StringUtils::Join(info.m_artist, g_advancedSettings.m_videoItemSeparator) + "." + info.m_strTitle);
if (iVersion >= 1 && info.m_iYear > 0)
strFileName.AppendFormat("_%i", info.m_iYear);
Expand All @@ -8696,12 +8696,12 @@ void CVideoDatabase::ImportFromXML(const CStdString &path)
info.Load(movie);
URIUtils::AddSlashAtEnd(info.m_strPath);
DeleteTvShow(info.m_strPath);
CFileItem item(info);
CFileItem showItem(info);
map<string, string> artwork;
if (ImportArtFromXML(movie->FirstChild("art"), artwork))
item.SetArt(artwork);
bool useFolders = info.m_basePath.IsEmpty() ? LookupByFolders(item.GetPath(), true) : false;
int showID = scanner.AddVideo(&item, CONTENT_TVSHOWS, useFolders, true, -1, true);
showItem.SetArt(artwork);
bool useFolders = info.m_basePath.IsEmpty() ? LookupByFolders(showItem.GetPath(), true) : false;
int showID = scanner.AddVideo(&showItem, CONTENT_TVSHOWS, useFolders, true, NULL, true);
// season artwork
TiXmlNode *art = movie->FirstChild("art");
if (art)
Expand Down Expand Up @@ -8734,7 +8734,7 @@ void CVideoDatabase::ImportFromXML(const CStdString &path)
map<string, string> artwork;
if (ImportArtFromXML(movie->FirstChild("art"), artwork))
item.SetArt(artwork);
scanner.AddVideo(&item,CONTENT_TVSHOWS, false, false, showID, true);
scanner.AddVideo(&item,CONTENT_TVSHOWS, false, false, showItem.GetVideoInfoTag(), true);
episode = episode->NextSiblingElement("episodedetails");
}
}
Expand Down
31 changes: 15 additions & 16 deletions xbmc/video/VideoInfoScanner.cpp
Expand Up @@ -640,8 +640,9 @@ namespace VIDEO
if (m_handle)
m_handle->SetText(Prettify(item->GetPath()));

CStdString showTitle = m_database.GetTvShowTitleById(showID);
return OnProcessSeriesFolder(files, scraper, useLocal, showID, showTitle, progress);
CVideoInfoTag showInfo;
m_database.GetTvShowInfo("", showInfo, showID);
return OnProcessSeriesFolder(files, scraper, useLocal, showInfo, progress);
}

void CVideoInfoScanner::EnumerateSeriesFolder(CFileItem* item, EPISODELIST& episodeList)
Expand Down Expand Up @@ -1035,7 +1036,7 @@ namespace VIDEO
return episodeInfo.cDate.IsValid();
}

long CVideoInfoScanner::AddVideo(CFileItem *pItem, const CONTENT_TYPE &content, bool videoFolder /* = false */, bool useLocal /* = true */, int idShow /* = -1 */, bool libraryImport /* = false */)
long CVideoInfoScanner::AddVideo(CFileItem *pItem, const CONTENT_TYPE &content, bool videoFolder /* = false */, bool useLocal /* = true */, const CVideoInfoTag *showInfo /* = NULL */, bool libraryImport /* = false */)
{
// ensure our database is open (this can get called via other classes)
if (!m_database.Open())
Expand All @@ -1059,10 +1060,9 @@ namespace VIDEO

CStdString strTitle(movieDetails.m_strTitle);

if (idShow > -1 && content == CONTENT_TVSHOWS)
if (showInfo && content == CONTENT_TVSHOWS)
{
CStdString strShowTitle = m_database.GetTvShowTitleById(idShow);
strTitle.Format("%s - %ix%i - %s", strShowTitle.c_str(), movieDetails.m_iSeason, movieDetails.m_iEpisode, strTitle.c_str());
strTitle.Format("%s - %ix%i - %s", showInfo->m_strTitle.c_str(), movieDetails.m_iSeason, movieDetails.m_iEpisode, strTitle.c_str());
}

if (m_handle)
Expand Down Expand Up @@ -1106,6 +1106,7 @@ namespace VIDEO
{
// we add episode then set details, as otherwise set details will delete the
// episode then add, which breaks multi-episode files.
int idShow = showInfo ? showInfo->m_iDbId : -1;
int idEpisode = m_database.AddEpisode(idShow, pItem->GetPath());
lResult = m_database.SetDetailsForEpisode(pItem->GetPath(), movieDetails, art, idShow, idEpisode);
movieDetails.m_iDbId = lResult;
Expand Down Expand Up @@ -1228,11 +1229,11 @@ namespace VIDEO
return thumb;
}

INFO_RET CVideoInfoScanner::OnProcessSeriesFolder(EPISODELIST& files, const ADDON::ScraperPtr &scraper, bool useLocal, int idShow, const CStdString& strShowTitle, CGUIDialogProgress* pDlgProgress /* = NULL */)
INFO_RET CVideoInfoScanner::OnProcessSeriesFolder(EPISODELIST& files, const ADDON::ScraperPtr &scraper, bool useLocal, const CVideoInfoTag& showInfo, CGUIDialogProgress* pDlgProgress /* = NULL */)
{
if (pDlgProgress)
{
pDlgProgress->SetLine(1, strShowTitle);
pDlgProgress->SetLine(1, showInfo.m_strTitle);
pDlgProgress->SetLine(2, 20361);
pDlgProgress->SetPercentage(0);
pDlgProgress->ShowProgressBar(true);
Expand Down Expand Up @@ -1279,20 +1280,18 @@ namespace VIDEO
if (result == CNfoFile::FULL_NFO)
{
m_nfoReader.GetDetails(*item.GetVideoInfoTag());
if (AddVideo(&item, CONTENT_TVSHOWS, file->isFolder, true, idShow) < 0)
if (AddVideo(&item, CONTENT_TVSHOWS, file->isFolder, true, &showInfo) < 0)
return INFO_ERROR;
continue;
}

if (!hasEpisodeGuide)
{
// fetch episode guide
CVideoInfoTag details;
m_database.GetTvShowInfo(item.GetPath(), details, idShow);
if (!details.m_strEpisodeGuide.IsEmpty())
if (!showInfo.m_strEpisodeGuide.IsEmpty())
{
CScraperUrl url;
url.ParseEpisodeGuide(details.m_strEpisodeGuide);
url.ParseEpisodeGuide(showInfo.m_strEpisodeGuide);

if (pDlgProgress)
{
Expand Down Expand Up @@ -1379,7 +1378,7 @@ namespace VIDEO
guide = candidates->begin() + index;
bFound = true;
CLog::Log(LOGDEBUG,"%s fuzzy title match for show: '%s', title: '%s', match: '%s', score: %f >= %f",
__FUNCTION__, strShowTitle.c_str(), file->strTitle.c_str(), titles[index].c_str(), matchscore, minscore);
__FUNCTION__, showInfo.m_strTitle.c_str(), file->strTitle.c_str(), titles[index].c_str(), matchscore, minscore);
}
}
}
Expand All @@ -1398,13 +1397,13 @@ namespace VIDEO
if (item.GetVideoInfoTag()->m_iEpisode == -1)
item.GetVideoInfoTag()->m_iEpisode = guide->iEpisode;

if (AddVideo(&item, CONTENT_TVSHOWS, file->isFolder, useLocal, idShow) < 0)
if (AddVideo(&item, CONTENT_TVSHOWS, file->isFolder, useLocal, &showInfo) < 0)
return INFO_ERROR;
}
else
{
CLog::Log(LOGDEBUG,"%s - no match for show: '%s', season: %d, episode: %d.%d, airdate: '%s', title: '%s'",
__FUNCTION__, strShowTitle.c_str(), file->iSeason, file->iEpisode, file->iSubepisode,
__FUNCTION__, showInfo.m_strTitle.c_str(), file->iSeason, file->iEpisode, file->iSubepisode,
file->cDate.GetAsLocalizedDate().c_str(), file->strTitle.c_str());
}
}
Expand Down
9 changes: 4 additions & 5 deletions xbmc/video/VideoInfoScanner.h
Expand Up @@ -69,11 +69,11 @@ namespace VIDEO
\param content content type of the item.
\param videoFolder whether the video is represented by a folder (single movie per folder). Defaults to false.
\param useLocal whether to use local information for artwork etc.
\param idShow database id of the tvshow if we're adding an episode. Defaults to -1.
\param showInfo pointer to CVideoInfoTag details for the show if this is an episode. Defaults to NULL.
\param libraryImport Whether this call belongs to a full library import or not. Defaults to false.
\return database id of the added item, or -1 on failure.
*/
long AddVideo(CFileItem *pItem, const CONTENT_TYPE &content, bool videoFolder = false, bool useLocal = true, int idShow = -1, bool libraryImport = false);
long AddVideo(CFileItem *pItem, const CONTENT_TYPE &content, bool videoFolder = false, bool useLocal = true, const CVideoInfoTag *showInfo = NULL, bool libraryImport = false);

/*! \brief Retrieve information for a list of items and add them to the database.
\param items list of items to retrieve info for.
Expand Down Expand Up @@ -193,13 +193,12 @@ namespace VIDEO
the episodes. INFO_ADDED then indicates we've added one or more episodes.
\param files the episode files to process.
\param scraper scraper to use for finding online info
\param idShow the database id of the show.
\param strShowTitle the title of the show.
\param showInfo information for the show.
\param pDlgProcess progress dialog to update during processing. Defaults to NULL.
\return INFO_ERROR on failure, INFO_CANCELLED on cancellation,
INFO_NOT_FOUND if an episode isn't found, or INFO_ADDED if all episodes are added.
*/
INFO_RET OnProcessSeriesFolder(EPISODELIST& files, const ADDON::ScraperPtr &scraper, bool useLocal, int idShow, const CStdString& strShowTitle, CGUIDialogProgress* pDlgProgress = NULL);
INFO_RET OnProcessSeriesFolder(EPISODELIST& files, const ADDON::ScraperPtr &scraper, bool useLocal, const CVideoInfoTag& showInfo, CGUIDialogProgress* pDlgProgress = NULL);

void EnumerateSeriesFolder(CFileItem* item, EPISODELIST& episodeList);
bool EnumerateEpisodeItem(const CFileItemPtr item, EPISODELIST& episodeList);
Expand Down

0 comments on commit c241e0c

Please sign in to comment.