| 1 |
/* |
| 2 |
* Copyright (C) 2013-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "SmartPlaylistFileItemListModifier.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "URL.h" |
| 13 |
#include "playlists/SmartPlayList.h" |
| 14 |
#include "utils/StringUtils.h" |
| 15 |
|
| 16 |
#include <string> |
| 17 |
|
| 18 |
#define URL_OPTION_XSP "xsp" |
| 19 |
#define PROPERTY_SORT_ORDER "sort.order" |
| 20 |
#define PROPERTY_SORT_ASCENDING "sort.ascending" |
| 21 |
|
| 22 |
bool CSmartPlaylistFileItemListModifier::CanModify(const CFileItemList &items) const |
| 23 |
{ |
| 24 |
return !GetUrlOption(items.GetPath(), URL_OPTION_XSP).empty(); |
| 25 |
} |
| 26 |
|
| 27 |
bool CSmartPlaylistFileItemListModifier::Modify(CFileItemList &items) const |
| 28 |
{ |
| 29 |
if (items.HasProperty(PROPERTY_SORT_ORDER)) |
| 30 |
return false; |
| 31 |
|
| 32 |
std::string xspOption = GetUrlOption(items.GetPath(), URL_OPTION_XSP); |
| 33 |
if (xspOption.empty()) |
| 34 |
return false; |
| 35 |
|
| 36 |
// check for smartplaylist-specific sorting information |
| 37 |
CSmartPlaylist xsp; |
| 38 |
if (!xsp.LoadFromJson(xspOption)) |
| 39 |
return false; |
| 40 |
|
| 41 |
items.SetProperty(PROPERTY_SORT_ORDER, (int)xsp.GetOrder()); |
| 42 |
items.SetProperty(PROPERTY_SORT_ASCENDING, xsp.GetOrderDirection() == SortOrderAscending); |
| 43 |
|
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
std::string CSmartPlaylistFileItemListModifier::GetUrlOption(const std::string &path, const std::string &option) |
| 48 |
{ |
| 49 |
if (path.empty() || option.empty()) |
| 50 |
return StringUtils::Empty; |
| 51 |
|
| 52 |
CURL url(path); |
| 53 |
return url.GetOption(option); |
| 54 |
} |