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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* Copyright (C) 2012-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "MusicDbUrl.h"
#include "filesystem/MusicDatabaseDirectory.h"
#include "playlists/SmartPlayList.h"
#include "utils/StringUtils.h"
#include "utils/Variant.h"
using namespace std;
using namespace XFILE;
using namespace XFILE::MUSICDATABASEDIRECTORY;
CMusicDbUrl::CMusicDbUrl()
: CDbUrl()
{ }
CMusicDbUrl::~CMusicDbUrl()
{ }
bool CMusicDbUrl::parse()
{
// the URL must start with musicdb://
if (!m_url.IsProtocol("musicdb") || m_url.GetFileName().empty())
return false;
CStdString path = m_url.Get();
NODE_TYPE dirType = CMusicDatabaseDirectory::GetDirectoryType(path);
NODE_TYPE childType = CMusicDatabaseDirectory::GetDirectoryChildType(path);
switch (dirType)
{
case NODE_TYPE_ARTIST:
m_type = "artists";
break;
case NODE_TYPE_ALBUM:
case NODE_TYPE_ALBUM_RECENTLY_ADDED:
case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
case NODE_TYPE_ALBUM_TOP100:
case NODE_TYPE_ALBUM_COMPILATIONS:
case NODE_TYPE_YEAR_ALBUM:
m_type = "albums";
break;
case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
case NODE_TYPE_ALBUM_TOP100_SONGS:
case NODE_TYPE_ALBUM_COMPILATIONS_SONGS:
case NODE_TYPE_SONG:
case NODE_TYPE_SONG_TOP100:
case NODE_TYPE_YEAR_SONG:
case NODE_TYPE_SINGLES:
m_type = "songs";
break;
default:
break;
}
switch (childType)
{
case NODE_TYPE_ARTIST:
m_type = "artists";
break;
case NODE_TYPE_ALBUM:
case NODE_TYPE_ALBUM_RECENTLY_ADDED:
case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
case NODE_TYPE_ALBUM_TOP100:
case NODE_TYPE_YEAR_ALBUM:
m_type = "albums";
break;
case NODE_TYPE_SONG:
case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
case NODE_TYPE_ALBUM_TOP100_SONGS:
case NODE_TYPE_ALBUM_COMPILATIONS_SONGS:
case NODE_TYPE_SONG_TOP100:
case NODE_TYPE_YEAR_SONG:
case NODE_TYPE_SINGLES:
m_type = "songs";
break;
case NODE_TYPE_GENRE:
m_type = "genres";
break;
case NODE_TYPE_YEAR:
m_type = "years";
break;
case NODE_TYPE_ALBUM_COMPILATIONS:
m_type = "albums";
break;
case NODE_TYPE_TOP100:
m_type = "top100";
break;
case NODE_TYPE_ROOT:
case NODE_TYPE_OVERVIEW:
default:
return false;
}
if (m_type.empty())
return false;
// parse query params
CQueryParams queryParams;
CDirectoryNode::GetDatabaseInfo(path, queryParams);
// retrieve and parse all options
AddOptions(m_url.GetOptions());
// add options based on the node type
if (dirType == NODE_TYPE_SINGLES || childType == NODE_TYPE_SINGLES)
AddOption("singles", true);
// add options based on the QueryParams
if (queryParams.GetArtistId() != -1)
AddOption("artistid", (int)queryParams.GetArtistId());
if (queryParams.GetAlbumId() != -1)
AddOption("albumid", (int)queryParams.GetAlbumId());
if (queryParams.GetGenreId() != -1)
AddOption("genreid", (int)queryParams.GetGenreId());
if (queryParams.GetSongId() != -1)
AddOption("songid", (int)queryParams.GetSongId());
if (queryParams.GetYear() != -1)
AddOption("year", (int)queryParams.GetYear());
return true;
}
bool CMusicDbUrl::validateOption(const std::string &key, const CVariant &value)
{
if (!CDbUrl::validateOption(key, value))
return false;
// if the value is empty it will remove the option which is ok
// otherwise we only care about the "filter" option here
if (value.empty() || !StringUtils::EqualsNoCase(key, "filter"))
return true;
if (!value.isString())
return false;
CSmartPlaylist xspFilter;
if (!xspFilter.LoadFromJson(value.asString()))
return false;
// check if the filter playlist matches the item type
return xspFilter.GetType() == m_type;
}
|