Merge pull request #26166 from ksooo/improve-plugin-ctx-menus
[xbmc.git] / xbmc / utils / ContentUtils.cpp
blobb0ebc675fc6006d5fe905ff9368327360809962a
1 /*
2 * Copyright (C) 2005-2020 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 "ContentUtils.h"
11 #include "FileItem.h"
12 #include "utils/StringUtils.h"
13 #include "video/VideoInfoTag.h"
15 namespace
17 bool HasPreferredArtType(const CFileItem& item)
19 return item.HasVideoInfoTag() && (item.GetVideoInfoTag()->m_type == MediaTypeMovie ||
20 item.GetVideoInfoTag()->m_type == MediaTypeTvShow ||
21 item.GetVideoInfoTag()->m_type == MediaTypeSeason ||
22 item.GetVideoInfoTag()->m_type == MediaTypeVideoCollection);
25 std::string GetPreferredArtType(const MediaType& type)
27 if (type == MediaTypeMovie || type == MediaTypeTvShow || type == MediaTypeSeason ||
28 type == MediaTypeVideoCollection)
30 return "poster";
32 return "thumb";
34 } // namespace
36 const std::string ContentUtils::GetPreferredArtImage(const CFileItem& item)
38 if (HasPreferredArtType(item))
40 auto preferredArtType = GetPreferredArtType(item.GetVideoInfoTag()->m_type);
41 if (item.HasArt(preferredArtType))
43 return item.GetArt(preferredArtType);
46 return item.GetArt("thumb");
49 std::unique_ptr<CFileItem> ContentUtils::GeneratePlayableTrailerItem(const CFileItem& item,
50 const std::string& label)
52 std::unique_ptr<CFileItem> trailerItem = std::make_unique<CFileItem>();
53 trailerItem->SetPath(item.GetVideoInfoTag()->m_strTrailer);
54 CVideoInfoTag* videoInfoTag = trailerItem->GetVideoInfoTag();
55 *videoInfoTag = *item.GetVideoInfoTag();
56 videoInfoTag->m_streamDetails.Reset();
57 videoInfoTag->m_strTitle = StringUtils::Format("{} ({})", videoInfoTag->m_strTitle, label);
58 trailerItem->SetArt(item.GetArt());
59 videoInfoTag->m_iDbId = -1;
60 videoInfoTag->m_iFileId = -1;
61 return trailerItem;