[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / music / MusicDbUrl.cpp
blob3b4893bc183becf2ef1187d0a37021120982927e
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 XFILE;
17 using namespace XFILE::MUSICDATABASEDIRECTORY;
19 CMusicDbUrl::CMusicDbUrl()
20 : CDbUrl()
21 { }
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())
29 return false;
31 std::string path = m_url.Get();
33 // Parse path for directory node types and query params
34 NODE_TYPE dirType;
35 NODE_TYPE childType;
36 CQueryParams queryParams;
37 if (!CMusicDatabaseDirectory::GetDirectoryNodeInfo(path, dirType, childType, queryParams))
38 return false;
40 switch (dirType)
42 case NODE_TYPE_ARTIST:
43 m_type = "artists";
44 break;
46 case NODE_TYPE_ALBUM:
47 case NODE_TYPE_ALBUM_RECENTLY_ADDED:
48 case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
49 case NODE_TYPE_ALBUM_TOP100:
50 m_type = "albums";
51 break;
53 case NODE_TYPE_DISC:
54 m_type = "discs";
55 break;
57 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
58 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
59 case NODE_TYPE_ALBUM_TOP100_SONGS:
60 case NODE_TYPE_SONG:
61 case NODE_TYPE_SONG_TOP100:
62 case NODE_TYPE_SINGLES:
63 m_type = "songs";
64 break;
66 default:
67 break;
70 switch (childType)
72 case NODE_TYPE_ARTIST:
73 m_type = "artists";
74 break;
76 case NODE_TYPE_ALBUM:
77 case NODE_TYPE_ALBUM_RECENTLY_ADDED:
78 case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
79 case NODE_TYPE_ALBUM_TOP100:
80 m_type = "albums";
81 break;
83 case NODE_TYPE_DISC:
84 m_type = "discs";
85 break;
87 case NODE_TYPE_SONG:
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:
93 m_type = "songs";
94 break;
96 case NODE_TYPE_GENRE:
97 m_type = "genres";
98 break;
100 case NODE_TYPE_SOURCE:
101 m_type = "sources";
102 break;
104 case NODE_TYPE_ROLE:
105 m_type = "roles";
106 break;
108 case NODE_TYPE_YEAR:
109 m_type = "years";
110 break;
112 case NODE_TYPE_TOP100:
113 m_type = "top100";
114 break;
116 case NODE_TYPE_ROOT:
117 case NODE_TYPE_OVERVIEW:
118 default:
119 return false;
122 if (m_type.empty())
123 return false;
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);
148 return true;
151 bool CMusicDbUrl::validateOption(const std::string &key, const CVariant &value)
153 if (!CDbUrl::validateOption(key, value))
154 return false;
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"))
159 return true;
161 if (!value.isString())
162 return false;
164 CSmartPlaylist xspFilter;
165 if (!xspFilter.LoadFromJson(value.asString()))
166 return false;
168 // check if the filter playlist matches the item type
169 return xspFilter.GetType() == m_type;