[cosmetic] AddVideoAsset function cleanup
[xbmc.git] / xbmc / video / VideoEmbeddedImageFileLoader.cpp
blob9f276e20b30919aed5f771bdef977236ef52223c
1 /*
2 * Copyright (C) 2023 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "VideoEmbeddedImageFileLoader.h"
11 #include "FileItem.h"
12 #include "guilib/Texture.h"
13 #include "imagefiles/ImageFileURL.h"
14 #include "utils/EmbeddedArt.h"
15 #include "utils/StringUtils.h"
16 #include "video/VideoInfoTag.h"
17 #include "video/tags/IVideoInfoTagLoader.h"
18 #include "video/tags/VideoInfoTagLoaderFactory.h"
20 namespace KODI::VIDEO
23 bool CVideoEmbeddedImageFileLoader::CanLoad(const std::string& specialType) const
25 return StringUtils::StartsWith(specialType, "video_");
28 namespace
30 bool GetEmbeddedThumb(const std::string& path, const std::string& type, EmbeddedArt& art)
32 CFileItem item(path, false);
33 std::unique_ptr<IVideoInfoTagLoader> loader(
34 CVideoInfoTagLoaderFactory::CreateLoader(item, ADDON::ScraperPtr(), false));
35 CVideoInfoTag tag;
36 std::vector<EmbeddedArt> artv;
37 if (loader)
38 loader->Load(tag, false, &artv);
40 for (const auto& it : artv)
42 if (it.m_type == type)
44 art = it;
45 break;
48 return !art.Empty();
50 } // namespace
52 std::unique_ptr<CTexture> CVideoEmbeddedImageFileLoader::Load(
53 const IMAGE_FILES::CImageFileURL& imageFile) const
55 EmbeddedArt art;
56 if (GetEmbeddedThumb(imageFile.GetTargetFile(), imageFile.GetSpecialType().substr(6), art))
57 return CTexture::LoadFromFileInMemory(art.m_data.data(), art.m_size, art.m_mime);
58 return {};
61 } // namespace KODI::VIDEO