2 * Copyright (C) 2013-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.
9 #include "SmartPlaylistFileItemListModifier.h"
12 #include "FileItemList.h"
14 #include "playlists/SmartPlayList.h"
15 #include "utils/StringUtils.h"
19 #define URL_OPTION_XSP "xsp"
20 #define PROPERTY_SORT_ORDER "sort.order"
21 #define PROPERTY_SORT_ASCENDING "sort.ascending"
23 namespace KODI::PLAYLIST
26 bool CSmartPlaylistFileItemListModifier::CanModify(const CFileItemList
&items
) const
28 return !GetUrlOption(items
.GetPath(), URL_OPTION_XSP
).empty();
31 bool CSmartPlaylistFileItemListModifier::Modify(CFileItemList
&items
) const
33 if (items
.HasProperty(PROPERTY_SORT_ORDER
))
36 std::string xspOption
= GetUrlOption(items
.GetPath(), URL_OPTION_XSP
);
37 if (xspOption
.empty())
40 // check for smartplaylist-specific sorting information
42 if (!xsp
.LoadFromJson(xspOption
))
45 items
.SetProperty(PROPERTY_SORT_ORDER
, (int)xsp
.GetOrder());
46 items
.SetProperty(PROPERTY_SORT_ASCENDING
, xsp
.GetOrderDirection() == SortOrderAscending
);
51 std::string
CSmartPlaylistFileItemListModifier::GetUrlOption(const std::string
&path
, const std::string
&option
)
53 if (path
.empty() || option
.empty())
54 return StringUtils::Empty
;
57 return url
.GetOption(option
);
60 } // namespace KODI::PLAYLIST