2 * Copyright (C) 2012-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 "MusicDbUrl.h"
11 #include "filesystem/MusicDatabaseDirectory.h"
12 #include "playlists/SmartPlayList.h"
13 #include "utils/StringUtils.h"
14 #include "utils/Variant.h"
17 using namespace XFILE
;
18 using namespace XFILE::MUSICDATABASEDIRECTORY
;
20 CMusicDbUrl::CMusicDbUrl()
24 CMusicDbUrl::~CMusicDbUrl() = default;
26 bool CMusicDbUrl::parse()
28 // the URL must start with musicdb://
29 if (!m_url
.IsProtocol("musicdb") || m_url
.GetFileName().empty())
32 std::string path
= m_url
.Get();
34 // Parse path for directory node types and query params
37 CQueryParams queryParams
;
38 if (!CMusicDatabaseDirectory::GetDirectoryNodeInfo(path
, dirType
, childType
, queryParams
))
43 case NODE_TYPE_ARTIST
:
48 case NODE_TYPE_ALBUM_RECENTLY_ADDED
:
49 case NODE_TYPE_ALBUM_RECENTLY_PLAYED
:
50 case NODE_TYPE_ALBUM_TOP100
:
58 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS
:
59 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS
:
60 case NODE_TYPE_ALBUM_TOP100_SONGS
:
62 case NODE_TYPE_SONG_TOP100
:
63 case NODE_TYPE_SINGLES
:
73 case NODE_TYPE_ARTIST
:
78 case NODE_TYPE_ALBUM_RECENTLY_ADDED
:
79 case NODE_TYPE_ALBUM_RECENTLY_PLAYED
:
80 case NODE_TYPE_ALBUM_TOP100
:
89 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS
:
90 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS
:
91 case NODE_TYPE_ALBUM_TOP100_SONGS
:
92 case NODE_TYPE_SONG_TOP100
:
93 case NODE_TYPE_SINGLES
:
101 case NODE_TYPE_SOURCE
:
113 case NODE_TYPE_TOP100
:
118 case NODE_TYPE_OVERVIEW
:
126 // retrieve and parse all options
127 AddOptions(m_url
.GetOptions());
129 // add options based on the node type
130 if (dirType
== NODE_TYPE_SINGLES
|| childType
== NODE_TYPE_SINGLES
)
131 AddOption("singles", true);
133 // add options based on the QueryParams
134 if (queryParams
.GetArtistId() != -1)
135 AddOption("artistid", (int)queryParams
.GetArtistId());
136 if (queryParams
.GetAlbumId() != -1)
137 AddOption("albumid", (int)queryParams
.GetAlbumId());
138 if (queryParams
.GetGenreId() != -1)
139 AddOption("genreid", (int)queryParams
.GetGenreId());
140 if (queryParams
.GetSongId() != -1)
141 AddOption("songid", (int)queryParams
.GetSongId());
142 if (queryParams
.GetYear() != -1)
143 AddOption("year", (int)queryParams
.GetYear());
145 // Decode legacy use of "musicdb://compilations/" path for filtered albums
146 if (m_url
.GetFileName() == "compilations/")
147 AddOption("compilation", true);
152 bool CMusicDbUrl::validateOption(const std::string
&key
, const CVariant
&value
)
154 if (!CDbUrl::validateOption(key
, value
))
157 // if the value is empty it will remove the option which is ok
158 // otherwise we only care about the "filter" option here
159 if (value
.empty() || !StringUtils::EqualsNoCase(key
, "filter"))
162 if (!value
.isString())
165 PLAYLIST::CSmartPlaylist xspFilter
;
166 if (!xspFilter
.LoadFromJson(value
.asString()))
169 // check if the filter playlist matches the item type
170 return xspFilter
.GetType() == m_type
;