diff options
author | Arne Morten Kvarving <spiff@kodi.tv> | 2024-09-10 15:31:53 +0200 |
---|---|---|
committer | Arne Morten Kvarving <spiff@kodi.tv> | 2024-09-15 12:49:18 +0200 |
commit | 3490ec436585bd8965b4d90b5da7deba388405c5 (patch) | |
tree | 43a45906fc932be01644084b4f35e3ee86ebc854 | |
parent | 09ffb617dbc786bd3a4deb342af8aa0299c37cfc (diff) |
move GetLocalArtBaseFilename to ArtUtils
-rw-r--r-- | xbmc/FileItem.cpp | 48 | ||||
-rw-r--r-- | xbmc/FileItem.h | 17 | ||||
-rw-r--r-- | xbmc/utils/ArtUtils.cpp | 40 | ||||
-rw-r--r-- | xbmc/utils/ArtUtils.h | 9 | ||||
-rw-r--r-- | xbmc/utils/test/TestArtUtils.cpp | 39 | ||||
-rw-r--r-- | xbmc/video/VideoInfoScanner.cpp | 12 |
6 files changed, 99 insertions, 66 deletions
diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index 9efa598f82..89b15d80a8 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -1957,59 +1957,13 @@ std::string CFileItem::FindLocalArt(const std::string &artFile, bool useFolder) return ""; } -std::string CFileItem::GetLocalArtBaseFilename() const -{ - bool useFolder = false; - return GetLocalArtBaseFilename(useFolder); -} - -std::string CFileItem::GetLocalArtBaseFilename(bool& useFolder) const -{ - std::string strFile; - if (IsStack()) - { - std::string strPath; - URIUtils::GetParentPath(m_strPath,strPath); - strFile = URIUtils::AddFileToFolder( - strPath, URIUtils::GetFileName(CStackDirectory::GetStackedTitlePath(m_strPath))); - } - - std::string file = strFile.empty() ? m_strPath : strFile; - if (URIUtils::IsInRAR(file) || URIUtils::IsInZIP(file)) - { - std::string strPath = URIUtils::GetDirectory(file); - std::string strParent; - URIUtils::GetParentPath(strPath,strParent); - strFile = URIUtils::AddFileToFolder(strParent, URIUtils::GetFileName(file)); - } - - if (IsMultiPath()) - strFile = CMultiPathDirectory::GetFirstPath(m_strPath); - - if (IsOpticalMediaFile()) - { // optical media files should be treated like folders - useFolder = true; - strFile = GetLocalMetadataPath(); - } - else if (useFolder && !(m_bIsFolder && !IsFileFolder())) - { - file = strFile.empty() ? m_strPath : strFile; - strFile = URIUtils::GetDirectory(file); - } - - if (strFile.empty()) - strFile = GetDynPath(); - - return strFile; -} - std::string CFileItem::GetLocalArt(const std::string& artFile, bool useFolder) const { // no retrieving of empty art files from folders if (useFolder && artFile.empty()) return ""; - std::string strFile = GetLocalArtBaseFilename(useFolder); + std::string strFile = ART::GetLocalArtBaseFilename(*this, useFolder); if (strFile.empty()) // empty filepath -> nothing to find return ""; diff --git a/xbmc/FileItem.h b/xbmc/FileItem.h index afaaf47c6a..7766982de5 100644 --- a/xbmc/FileItem.h +++ b/xbmc/FileItem.h @@ -397,23 +397,6 @@ public: CPictureInfoTag* GetPictureInfoTag(); - /*! - \brief Assemble the base filename of local artwork for an item, - accounting for archives, stacks and multi-paths, and BDMV/VIDEO_TS folders. - `useFolder` is set to false - \return the path to the base filename for artwork lookup. - \sa GetLocalArt - */ - std::string GetLocalArtBaseFilename() const; - /*! - \brief Assemble the base filename of local artwork for an item, - accounting for archives, stacks and multi-paths, and BDMV/VIDEO_TS folders. - \param useFolder whether to look in the folder for the art file. Defaults to false. - \return the path to the base filename for artwork lookup. - \sa GetLocalArt - */ - std::string GetLocalArtBaseFilename(bool& useFolder) const; - /*! \brief Assemble the filename of a particular piece of local artwork for an item. No file existence check is typically performed. \param artFile the art file to search for. diff --git a/xbmc/utils/ArtUtils.cpp b/xbmc/utils/ArtUtils.cpp index b1e90855fd..386a0f1183 100644 --- a/xbmc/utils/ArtUtils.cpp +++ b/xbmc/utils/ArtUtils.cpp @@ -178,6 +178,46 @@ std::string GetFolderThumb(const CFileItem& item, const std::string& folderJPG / return URIUtils::AddFileToFolder(strFolder, folderJPG); } +std::string GetLocalArtBaseFilename(const CFileItem& item, bool& useFolder) +{ + std::string strFile; + if (item.IsStack()) + { + std::string strPath; + URIUtils::GetParentPath(item.GetPath(), strPath); + strFile = URIUtils::AddFileToFolder( + strPath, URIUtils::GetFileName(CStackDirectory::GetStackedTitlePath(item.GetPath()))); + } + + std::string file = strFile.empty() ? item.GetPath() : strFile; + if (URIUtils::IsInRAR(file) || URIUtils::IsInZIP(file)) + { + std::string strPath = URIUtils::GetDirectory(file); + std::string strParent; + URIUtils::GetParentPath(strPath, strParent); + strFile = URIUtils::AddFileToFolder(strParent, URIUtils::GetFileName(file)); + } + + if (item.IsMultiPath()) + strFile = CMultiPathDirectory::GetFirstPath(item.GetPath()); + + if (item.IsOpticalMediaFile()) + { // optical media files should be treated like folders + useFolder = true; + strFile = item.GetLocalMetadataPath(); + } + else if (useFolder && !(item.m_bIsFolder && !item.IsFileFolder())) + { + file = strFile.empty() ? item.GetPath() : strFile; + strFile = URIUtils::GetDirectory(file); + } + + if (strFile.empty()) + strFile = item.GetDynPath(); + + return strFile; +} + std::string GetLocalFanart(const CFileItem& item) { if (VIDEO::IsVideoDb(item)) diff --git a/xbmc/utils/ArtUtils.h b/xbmc/utils/ArtUtils.h index 07671d28dd..4063f389ee 100644 --- a/xbmc/utils/ArtUtils.h +++ b/xbmc/utils/ArtUtils.h @@ -27,6 +27,15 @@ void FillInDefaultIcon(CFileItem& item); std::string GetFolderThumb(const CFileItem& item, const std::string& folderJPG = "folder.jpg"); /*! + \brief Assemble the base filename of local artwork for an item, + accounting for archives, stacks and multi-paths, and BDMV/VIDEO_TS folders. + \param useFolder whether to look in the folder for the art file. Defaults to false. + \return the path to the base filename for artwork lookup. + \sa GetLocalArt + */ +std::string GetLocalArtBaseFilename(const CFileItem& item, bool& useFolder); + +/*! \brief Get the local fanart for item if it exists \return path to the local fanart for this item, or empty if none exists \sa GetFolderThumb, GetTBNFile diff --git a/xbmc/utils/test/TestArtUtils.cpp b/xbmc/utils/test/TestArtUtils.cpp index f373634e55..59d827e322 100644 --- a/xbmc/utils/test/TestArtUtils.cpp +++ b/xbmc/utils/test/TestArtUtils.cpp @@ -47,6 +47,32 @@ std::string unique_path(const std::string& input) return ret; } +struct ArtFilenameTest +{ + std::string path; + std::string result; + bool isFolder = false; + bool result_folder = false; + bool force_use_folder = false; +}; + +class GetLocalArtBaseFilenameTest : public testing::WithParamInterface<ArtFilenameTest>, + public testing::Test +{ +}; + +const auto local_art_filename_tests = std::array{ + ArtFilenameTest{"/home/user/foo.avi", "/home/user/foo.avi"}, + ArtFilenameTest{"stack:///home/user/foo-cd1.avi , /home/user/foo-cd2.avi", + "/home/user/foo.avi"}, + ArtFilenameTest{"zip://%2fhome%2fuser%2fbar.zip/foo.avi", "/home/user/foo.avi"}, + ArtFilenameTest{"multipath://%2fhome%2fuser%2fbar%2f/%2fhome%2fuser%2ffoo%2f", + "/home/user/bar/", true, true}, + ArtFilenameTest{"/home/user/VIDEO_TS/VIDEO_TS.IFO", "/home/user/", false, true}, + ArtFilenameTest{"/home/user/BDMV/index.bdmv", "/home/user/", false, true}, + ArtFilenameTest{"/home/user/foo.avi", "/home/user/", false, true, true}, +}; + struct FanartTest { std::string path; @@ -173,6 +199,19 @@ TEST_P(FolderThumbTest, GetFolderThumb) INSTANTIATE_TEST_SUITE_P(TestArtUtils, FolderThumbTest, testing::ValuesIn(folder_thumb_tests)); +TEST_P(GetLocalArtBaseFilenameTest, GetLocalArtBaseFilename) +{ + CFileItem item(GetParam().path, GetParam().isFolder); + bool useFolder = GetParam().force_use_folder ? true : GetParam().isFolder; + const std::string res = ART::GetLocalArtBaseFilename(item, useFolder); + EXPECT_EQ(res, GetParam().result); + EXPECT_EQ(useFolder, GetParam().result_folder); +} + +INSTANTIATE_TEST_SUITE_P(TestArtUtils, + GetLocalArtBaseFilenameTest, + testing::ValuesIn(local_art_filename_tests)); + TEST_P(GetLocalFanartTest, GetLocalFanart) { std::string path, file_path, uniq; diff --git a/xbmc/video/VideoInfoScanner.cpp b/xbmc/video/VideoInfoScanner.cpp index 9dc3588a5c..c02ee60282 100644 --- a/xbmc/video/VideoInfoScanner.cpp +++ b/xbmc/video/VideoInfoScanner.cpp @@ -38,6 +38,7 @@ #include "settings/Settings.h" #include "settings/SettingsComponent.h" #include "tags/VideoInfoTagLoaderFactory.h" +#include "utils/ArtUtils.h" #include "utils/Digest.h" #include "utils/FileExtensionProvider.h" #include "utils/RegExp.h" @@ -1792,14 +1793,21 @@ namespace KODI::VIDEO { if (!pItem->SkipLocalArt()) { + bool useFolder = false; if (bApplyToDir && (content == CONTENT_MOVIES || content == CONTENT_MUSICVIDEOS)) { - std::string filename = pItem->GetLocalArtBaseFilename(); + std::string filename = ART::GetLocalArtBaseFilename(*pItem, useFolder); std::string directory = URIUtils::GetDirectory(filename); if (filename != directory) AddLocalItemArtwork(art, artTypes, directory, addAll, exactName); } - AddLocalItemArtwork(art, artTypes, pItem->GetLocalArtBaseFilename(), addAll, exactName); + + // Reset useFolder to false as GetLocalArtBaseFilename may modify it in + // the previous call. + useFolder = false; + + AddLocalItemArtwork(art, artTypes, ART::GetLocalArtBaseFilename(*pItem, useFolder), addAll, + exactName); } if (moviePartOfSet) |