diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/video/jobs/VideoLibraryMarkWatchedJob.cpp | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/video/jobs/VideoLibraryMarkWatchedJob.cpp')
-rw-r--r-- | xbmc/video/jobs/VideoLibraryMarkWatchedJob.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/xbmc/video/jobs/VideoLibraryMarkWatchedJob.cpp b/xbmc/video/jobs/VideoLibraryMarkWatchedJob.cpp new file mode 100644 index 0000000..25381bb --- /dev/null +++ b/xbmc/video/jobs/VideoLibraryMarkWatchedJob.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2014-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include <vector> + +#include "VideoLibraryMarkWatchedJob.h" +#include "FileItem.h" +#include "Util.h" +#include "filesystem/Directory.h" +#ifdef HAS_UPNP +#include "network/upnp/UPnP.h" +#endif +#include "pvr/PVRManager.h" +#include "pvr/recordings/PVRRecordings.h" +#include "profiles/ProfileManager.h" +#include "settings/SettingsComponent.h" +#include "ServiceBroker.h" +#include "utils/URIUtils.h" +#include "video/VideoDatabase.h" + +CVideoLibraryMarkWatchedJob::CVideoLibraryMarkWatchedJob(const std::shared_ptr<CFileItem>& item, + bool mark) + : m_item(item), m_mark(mark) +{ } + +CVideoLibraryMarkWatchedJob::~CVideoLibraryMarkWatchedJob() = default; + +bool CVideoLibraryMarkWatchedJob::operator==(const CJob* job) const +{ + if (strcmp(job->GetType(), GetType()) != 0) + return false; + + const CVideoLibraryMarkWatchedJob* markJob = dynamic_cast<const CVideoLibraryMarkWatchedJob*>(job); + if (markJob == NULL) + return false; + + return m_item->IsSamePath(markJob->m_item.get()) && markJob->m_mark == m_mark; +} + +bool CVideoLibraryMarkWatchedJob::Work(CVideoDatabase &db) +{ + const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); + + if (!profileManager->GetCurrentProfile().canWriteDatabases()) + return false; + + CFileItemList items; + items.Add(CFileItemPtr(new CFileItem(*m_item))); + + if (m_item->m_bIsFolder) + CUtil::GetRecursiveListing(m_item->GetPath(), items, "", XFILE::DIR_FLAG_NO_FILE_INFO); + + std::vector<CFileItemPtr> markItems; + for (int i = 0; i < items.Size(); i++) + { + CFileItemPtr item = items.Get(i); + if (item->HasVideoInfoTag() && m_mark == (item->GetVideoInfoTag()->GetPlayCount() > 0)) + continue; + +#ifdef HAS_UPNP + if (URIUtils::IsUPnP(item->GetPath()) && UPNP::CUPnP::MarkWatched(*item, m_mark)) + continue; +#endif + + if (item->HasPVRRecordingInfoTag() && + CServiceBroker::GetPVRManager().Recordings()->MarkWatched(item->GetPVRRecordingInfoTag(), m_mark)) + { + CDateTime newLastPlayed; + if (m_mark) + newLastPlayed = db.IncrementPlayCount(*item); + else + newLastPlayed = db.SetPlayCount(*item, 0); + + if (newLastPlayed.IsValid()) + item->GetVideoInfoTag()->m_lastPlayed = newLastPlayed; + + continue; + } + + markItems.push_back(item); + } + + if (markItems.empty()) + return true; + + db.BeginTransaction(); + + for (std::vector<CFileItemPtr>::const_iterator iter = markItems.begin(); iter != markItems.end(); ++iter) + { + const CFileItemPtr& item = *iter; + + std::string path(item->GetPath()); + if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->GetPath().empty()) + path = item->GetVideoInfoTag()->GetPath(); + + // With both mark as watched and unwatched we want the resume bookmarks to be reset + db.ClearBookMarksOfFile(path, CBookmark::RESUME); + + CDateTime newLastPlayed; + if (m_mark) + newLastPlayed = db.IncrementPlayCount(*item); + else + newLastPlayed = db.SetPlayCount(*item, 0); + + if (newLastPlayed.IsValid() && item->HasVideoInfoTag()) + item->GetVideoInfoTag()->m_lastPlayed = newLastPlayed; + } + + db.CommitTransaction(); + db.Close(); + + return true; +} |