[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / music / MusicDbUrl.cpp
blobc11ac931fbe29257e44d69f36f1c21f10119e58c
1 /*
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.
7 */
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 KODI;
17 using namespace XFILE;
18 using namespace XFILE::MUSICDATABASEDIRECTORY;
20 CMusicDbUrl::CMusicDbUrl()
21 : CDbUrl()
22 { }
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())
30 return false;
32 std::string path = m_url.Get();
34 // Parse path for directory node types and query params
35 NODE_TYPE dirType;
36 NODE_TYPE childType;
37 CQueryParams queryParams;
38 if (!CMusicDatabaseDirectory::GetDirectoryNodeInfo(path, dirType, childType, queryParams))
39 return false;
41 switch (dirType)
43 case NODE_TYPE_ARTIST:
44 m_type = "artists";
45 break;
47 case NODE_TYPE_ALBUM:
48 case NODE_TYPE_ALBUM_RECENTLY_ADDED:
49 case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
50 case NODE_TYPE_ALBUM_TOP100:
51 m_type = "albums";
52 break;
54 case NODE_TYPE_DISC:
55 m_type = "discs";
56 break;
58 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
59 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
60 case NODE_TYPE_ALBUM_TOP100_SONGS:
61 case NODE_TYPE_SONG:
62 case NODE_TYPE_SONG_TOP100:
63 case NODE_TYPE_SINGLES:
64 m_type = "songs";
65 break;
67 default:
68 break;
71 switch (childType)
73 case NODE_TYPE_ARTIST:
74 m_type = "artists";
75 break;
77 case NODE_TYPE_ALBUM:
78 case NODE_TYPE_ALBUM_RECENTLY_ADDED:
79 case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
80 case NODE_TYPE_ALBUM_TOP100:
81 m_type = "albums";
82 break;
84 case NODE_TYPE_DISC:
85 m_type = "discs";
86 break;
88 case NODE_TYPE_SONG:
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:
94 m_type = "songs";
95 break;
97 case NODE_TYPE_GENRE:
98 m_type = "genres";
99 break;
101 case NODE_TYPE_SOURCE:
102 m_type = "sources";
103 break;
105 case NODE_TYPE_ROLE:
106 m_type = "roles";
107 break;
109 case NODE_TYPE_YEAR:
110 m_type = "years";
111 break;
113 case NODE_TYPE_TOP100:
114 m_type = "top100";
115 break;
117 case NODE_TYPE_ROOT:
118 case NODE_TYPE_OVERVIEW:
119 default:
120 return false;
123 if (m_type.empty())
124 return false;
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);
149 return true;
152 bool CMusicDbUrl::validateOption(const std::string &key, const CVariant &value)
154 if (!CDbUrl::validateOption(key, value))
155 return false;
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"))
160 return true;
162 if (!value.isString())
163 return false;
165 PLAYLIST::CSmartPlaylist xspFilter;
166 if (!xspFilter.LoadFromJson(value.asString()))
167 return false;
169 // check if the filter playlist matches the item type
170 return xspFilter.GetType() == m_type;