diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index f818cc86518bb..24231624c3723 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -2293,6 +2293,18 @@ bool CFileItem::LoadDetails() return false; } + if (GetProperty("IsVideoFolder").asBoolean(false)) + { + const std::shared_ptr loadedItem{VIDEO::UTILS::LoadVideoFilesFolderInfo(*this)}; + if (loadedItem) + { + UpdateInfo(*loadedItem); + return true; + } + CLog::LogF(LOGERROR, "Error filling video files folder item details (path={})", GetPath()); + return false; + } + //! @todo add support for other types on demand. CLog::LogF(LOGDEBUG, "Unsupported item type (path={})", GetPath()); return false; diff --git a/xbmc/video/VideoUtils.cpp b/xbmc/video/VideoUtils.cpp index 4248e9e7a60dd..834a687d5df6e 100644 --- a/xbmc/video/VideoUtils.cpp +++ b/xbmc/video/VideoUtils.cpp @@ -239,4 +239,45 @@ ResumeInformation GetStackPartResumeInformation(const CFileItem& item, unsigned return resumeInfo; } +std::shared_ptr LoadVideoFilesFolderInfo(const CFileItem& folder) +{ + CVideoDatabase db; + if (!db.Open()) + { + CLog::LogF(LOGERROR, "Cannot open VideoDatabase"); + return {}; + } + + CFileItemList items; + XFILE::CDirectory::GetDirectory(folder.GetDynPath(), items, "", XFILE::DIR_FLAG_DEFAULTS); + + db.GetPlayCounts(items.GetPath(), items); + + std::shared_ptr loadedItem{std::make_shared(folder)}; + loadedItem->SetProperty("total", 0); + loadedItem->SetProperty("watched", 0); + loadedItem->SetProperty("unwatched", 0); + loadedItem->SetProperty("inprogress", 0); + + for (const auto& item : items) + { + if (item->HasVideoInfoTag()) + { + loadedItem->IncrementProperty("total", 1); + if (item->GetVideoInfoTag()->GetPlayCount() == 0) + { + loadedItem->IncrementProperty("unwatched", 1); + } + else + { + loadedItem->IncrementProperty("watched", 1); + } + if (item->GetVideoInfoTag()->GetResumePoint().IsPartWay()) + { + loadedItem->IncrementProperty("inprogress", 1); + } + } + } + return loadedItem; +} } // namespace KODI::VIDEO::UTILS diff --git a/xbmc/video/VideoUtils.h b/xbmc/video/VideoUtils.h index 2ee611c4e81e3..484c030dc369f 100644 --- a/xbmc/video/VideoUtils.h +++ b/xbmc/video/VideoUtils.h @@ -8,6 +8,7 @@ #pragma once +#include #include class CFileItem; @@ -64,4 +65,11 @@ ResumeInformation GetItemResumeInformation(const CFileItem& item); */ ResumeInformation GetStackPartResumeInformation(const CFileItem& item, unsigned int partNumber); +/*! + \brief For a given non-library folder containing video files, load info from the video database. + \param folder The folder to load + \return The item containing the folder including loaded info. + */ +std::shared_ptr LoadVideoFilesFolderInfo(const CFileItem& folder); + } // namespace KODI::VIDEO::UTILS diff --git a/xbmc/video/guilib/VideoGUIUtils.cpp b/xbmc/video/guilib/VideoGUIUtils.cpp index 736ca56a62f0e..be4e6491e0c9c 100644 --- a/xbmc/video/guilib/VideoGUIUtils.cpp +++ b/xbmc/video/guilib/VideoGUIUtils.cpp @@ -220,6 +220,9 @@ void CAsyncGetItemsForPlaylist::GetItemsForPlaylist(const std::shared_ptr(parentPath, true); + parentItem->SetProperty("IsVideoFolder", true); + parentItem->LoadDetails(); if (item->GetStartOffset() == STARTOFFSET_RESUME) parentItem->SetStartOffset(STARTOFFSET_RESUME);