Skip to content

Commit

Permalink
[video] Fix resume of Non-Videodatabase items if 'play next video aut…
Browse files Browse the repository at this point in the history
…omatically' is active.
  • Loading branch information
ksooo committed Dec 16, 2024
1 parent 757de49 commit abfa810
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions xbmc/FileItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,18 @@ bool CFileItem::LoadDetails()
return false;
}

if (GetProperty("IsVideoFolder").asBoolean(false))
{
const std::shared_ptr<CFileItem> 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;
Expand Down
41 changes: 41 additions & 0 deletions xbmc/video/VideoUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,45 @@ ResumeInformation GetStackPartResumeInformation(const CFileItem& item, unsigned
return resumeInfo;
}

std::shared_ptr<CFileItem> 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<CFileItem> loadedItem{std::make_shared<CFileItem>(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
8 changes: 8 additions & 0 deletions xbmc/video/VideoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include <memory>
#include <string>

class CFileItem;
Expand Down Expand Up @@ -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<CFileItem> LoadVideoFilesFolderInfo(const CFileItem& folder);

} // namespace KODI::VIDEO::UTILS
4 changes: 4 additions & 0 deletions xbmc/video/guilib/VideoGUIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ void CAsyncGetItemsForPlaylist::GetItemsForPlaylist(const std::shared_ptr<CFileI
content = "files";

items.SetContent(content);

// Get play counts and resume bookmarks for the items.
db.GetPlayCounts(items.GetPath(), items);
}
}

Expand Down Expand Up @@ -424,6 +427,7 @@ void PlayItem(
}

const auto parentItem = std::make_shared<CFileItem>(parentPath, true);
parentItem->SetProperty("IsVideoFolder", true);
parentItem->LoadDetails();
if (item->GetStartOffset() == STARTOFFSET_RESUME)
parentItem->SetStartOffset(STARTOFFSET_RESUME);
Expand Down

0 comments on commit abfa810

Please sign in to comment.