Merge pull request #26264 from the-black-eagle/mka_end_durations
[xbmc.git] / xbmc / addons / PluginSource.cpp
blobc61d7b1fae6e13867c005195f9a3046874eacde4
1 /*
2 * Copyright (C) 2005-2018 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 "PluginSource.h"
11 #include "URL.h"
12 #include "addons/addoninfo/AddonInfo.h"
13 #include "addons/addoninfo/AddonType.h"
14 #include "utils/StringUtils.h"
16 #include <utility>
18 namespace ADDON
21 CPluginSource::CPluginSource(const AddonInfoPtr& addonInfo, AddonType addonType)
22 : CAddon(addonInfo, addonType)
24 std::string provides = addonInfo->Type(addonType)->GetValue("provides").asString();
26 for (const auto& values : addonInfo->Type(addonType)->GetValues())
28 if (values.first != "medialibraryscanpath")
29 continue;
31 std::string url = "plugin://" + ID() + '/';
32 std::string content = values.second.GetValue("medialibraryscanpath@content").asString();
33 std::string path = values.second.GetValue("medialibraryscanpath").asString();
34 if (!path.empty() && path.front() == '/')
35 path.erase(0, 1);
36 if (path.compare(0, url.size(), url))
37 path.insert(0, url);
38 m_mediaLibraryScanPaths[content].push_back(CURL(path).GetFileName());
41 SetProvides(provides);
44 void CPluginSource::SetProvides(const std::string &content)
46 if (!content.empty())
48 std::vector<std::string> provides = StringUtils::Split(content, ' ');
49 for (std::vector<std::string>::const_iterator i = provides.begin(); i != provides.end(); ++i)
51 Content content = Translate(*i);
52 if (content != UNKNOWN)
53 m_providedContent.insert(content);
56 if (Type() == AddonType::SCRIPT && m_providedContent.empty())
57 m_providedContent.insert(EXECUTABLE);
60 CPluginSource::Content CPluginSource::Translate(const std::string &content)
62 if (content == "audio")
63 return CPluginSource::AUDIO;
64 else if (content == "image")
65 return CPluginSource::IMAGE;
66 else if (content == "executable")
67 return CPluginSource::EXECUTABLE;
68 else if (content == "video")
69 return CPluginSource::VIDEO;
70 else if (content == "game")
71 return CPluginSource::GAME;
72 else
73 return CPluginSource::UNKNOWN;
76 bool CPluginSource::HasType(AddonType type) const
78 return ((type == AddonType::VIDEO && Provides(VIDEO)) ||
79 (type == AddonType::AUDIO && Provides(AUDIO)) ||
80 (type == AddonType::IMAGE && Provides(IMAGE)) ||
81 (type == AddonType::GAME && Provides(GAME)) ||
82 (type == AddonType::EXECUTABLE && Provides(EXECUTABLE)) || (type == CAddon::Type()));
85 } /*namespace ADDON*/