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/filesystem/VideoDatabaseFile.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/filesystem/VideoDatabaseFile.cpp')
-rw-r--r-- | xbmc/filesystem/VideoDatabaseFile.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/xbmc/filesystem/VideoDatabaseFile.cpp b/xbmc/filesystem/VideoDatabaseFile.cpp new file mode 100644 index 0000000..036eeba --- /dev/null +++ b/xbmc/filesystem/VideoDatabaseFile.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2005-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 "VideoDatabaseFile.h" + +#include "URL.h" +#include "utils/StringUtils.h" +#include "utils/URIUtils.h" +#include "video/VideoDatabase.h" +#include "video/VideoInfoTag.h" + +using namespace XFILE; + +CVideoDatabaseFile::CVideoDatabaseFile(void) + : COverrideFile(true) +{ } + +CVideoDatabaseFile::~CVideoDatabaseFile(void) = default; + +CVideoInfoTag CVideoDatabaseFile::GetVideoTag(const CURL& url) +{ + CVideoInfoTag tag; + + std::string strFileName = URIUtils::GetFileName(url.Get()); + if (strFileName.empty()) + return tag; + + URIUtils::RemoveExtension(strFileName); + if (!StringUtils::IsNaturalNumber(strFileName)) + return tag; + long idDb = atol(strFileName.c_str()); + + VideoDbContentType type = GetType(url); + if (type == VideoDbContentType::UNKNOWN) + return tag; + + CVideoDatabase videoDatabase; + if (!videoDatabase.Open()) + return tag; + + tag = videoDatabase.GetDetailsByTypeAndId(type, idDb); + + return tag; +} + +VideoDbContentType CVideoDatabaseFile::GetType(const CURL& url) +{ + std::string strPath = URIUtils::GetDirectory(url.Get()); + if (strPath.empty()) + return VideoDbContentType::UNKNOWN; + + std::vector<std::string> pathElem = StringUtils::Split(strPath, "/"); + if (pathElem.size() == 0) + return VideoDbContentType::UNKNOWN; + + std::string itemType = pathElem.at(2); + VideoDbContentType type; + if (itemType == "movies" || itemType == "recentlyaddedmovies") + type = VideoDbContentType::MOVIES; + else if (itemType == "episodes" || itemType == "recentlyaddedepisodes" || itemType == "inprogresstvshows" || itemType == "tvshows") + type = VideoDbContentType::EPISODES; + else if (itemType == "musicvideos" || itemType == "recentlyaddedmusicvideos") + type = VideoDbContentType::MUSICVIDEOS; + else + type = VideoDbContentType::UNKNOWN; + + return type; +} + + +std::string CVideoDatabaseFile::TranslatePath(const CURL& url) +{ + std::string strFileName = URIUtils::GetFileName(url.Get()); + if (strFileName.empty()) + return ""; + + URIUtils::RemoveExtension(strFileName); + if (!StringUtils::IsNaturalNumber(strFileName)) + return ""; + long idDb = atol(strFileName.c_str()); + + VideoDbContentType type = GetType(url); + if (type == VideoDbContentType::UNKNOWN) + return ""; + + CVideoDatabase videoDatabase; + if (!videoDatabase.Open()) + return ""; + + std::string realFilename; + videoDatabase.GetFilePathById(idDb, realFilename, type); + + return realFilename; +} |