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