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"
16 using namespace XFILE
;
17 using namespace XFILE::MUSICDATABASEDIRECTORY
;
19 CMusicDbUrl::CMusicDbUrl()
23 CMusicDbUrl::~CMusicDbUrl() = default;
25 bool CMusicDbUrl::parse()
27 // the URL must start with musicdb://
28 if (!m_url
.IsProtocol("musicdb") || m_url
.GetFileName().empty())
31 std::string path
= m_url
.Get();
33 // Parse path for directory node types and query params
36 CQueryParams queryParams
;
37 if (!CMusicDatabaseDirectory::GetDirectoryNodeInfo(path
, dirType
, childType
, queryParams
))
42 case NODE_TYPE_ARTIST
:
47 case NODE_TYPE_ALBUM_RECENTLY_ADDED
:
48 case NODE_TYPE_ALBUM_RECENTLY_PLAYED
:
49 case NODE_TYPE_ALBUM_TOP100
:
57 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS
:
58 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS
:
59 case NODE_TYPE_ALBUM_TOP100_SONGS
:
61 case NODE_TYPE_SONG_TOP100
:
62 case NODE_TYPE_SINGLES
:
72 case NODE_TYPE_ARTIST
:
77 case NODE_TYPE_ALBUM_RECENTLY_ADDED
:
78 case NODE_TYPE_ALBUM_RECENTLY_PLAYED
:
79 case NODE_TYPE_ALBUM_TOP100
:
88 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS
:
89 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS
:
90 case NODE_TYPE_ALBUM_TOP100_SONGS
:
91 case NODE_TYPE_SONG_TOP100
:
92 case NODE_TYPE_SINGLES
:
100 case NODE_TYPE_SOURCE
:
112 case NODE_TYPE_TOP100
:
117 case NODE_TYPE_OVERVIEW
:
125 // retrieve and parse all options
126 AddOptions(m_url
.GetOptions());
128 // add options based on the node type
129 if (dirType
== NODE_TYPE_SINGLES
|| childType
== NODE_TYPE_SINGLES
)
130 AddOption("singles", true);
132 // add options based on the QueryParams
133 if (queryParams
.GetArtistId() != -1)
134 AddOption("artistid", (int)queryParams
.GetArtistId());
135 if (queryParams
.GetAlbumId() != -1)
136 AddOption("albumid", (int)queryParams
.GetAlbumId());
137 if (queryParams
.GetGenreId() != -1)
138 AddOption("genreid", (int)queryParams
.GetGenreId());
139 if (queryParams
.GetSongId() != -1)
140 AddOption("songid", (int)queryParams
.GetSongId());
141 if (queryParams
.GetYear() != -1)
142 AddOption("year", (int)queryParams
.GetYear());
144 // Decode legacy use of "musicdb://compilations/" path for filtered albums
145 if (m_url
.GetFileName() == "compilations/")
146 AddOption("compilation", true);
151 bool CMusicDbUrl::validateOption(const std::string
&key
, const CVariant
&value
)
153 if (!CDbUrl::validateOption(key
, value
))
156 // if the value is empty it will remove the option which is ok
157 // otherwise we only care about the "filter" option here
158 if (value
.empty() || !StringUtils::EqualsNoCase(key
, "filter"))
161 if (!value
.isString())
164 CSmartPlaylist xspFilter
;
165 if (!xspFilter
.LoadFromJson(value
.asString()))
168 // check if the filter playlist matches the item type
169 return xspFilter
.GetType() == m_type
;