1
1
<?php
2
-
3
- class lastfmApiAlbum extends lastfmApiBase {
4
- public $ info ;
5
- public $ tags ;
2
+ /**
3
+ * File that stores api calls for album api calls
4
+ * @package album
5
+ */
6
+ /**
7
+ * Allows access to the api requests relating to albums
8
+ * @package album
9
+ */
10
+ class lastfmApiAlbum extends lastfmApi {
11
+ /**
12
+ * Stores the config values set in the call
13
+ * @access public
14
+ * @var array
15
+ */
6
16
public $ config ;
7
-
17
+ /**
18
+ * Stores the auth variables used in all api calls
19
+ * @access private
20
+ * @var array
21
+ */
8
22
private $ auth ;
23
+ /**
24
+ * States if the user has full authentication to use api requests that modify data
25
+ * @access private
26
+ * @var boolean
27
+ */
9
28
private $ fullAuth ;
10
29
30
+ /**
31
+ * @param array $auth Passes the authentication variables
32
+ * @param array $fullAuth A boolean value stating if the user has full authentication or not
33
+ * @param array $config An array of config variables related to caching and other features
34
+ */
11
35
function __construct ($ auth , $ fullAuth , $ config ) {
12
36
$ this ->auth = $ auth ;
13
37
$ this ->fullAuth = $ fullAuth ;
14
38
$ this ->config = $ config ;
15
39
}
16
40
41
+ /**
42
+ * Tag an album using a list of user supplied tags. (Requires full auth)
43
+ * @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i>, <i>tags</i>
44
+ * @return boolean
45
+ */
17
46
public function addTags ($ methodVars ) {
18
47
// Only allow full authed calls
19
48
if ( $ this ->fullAuth == TRUE ) {
@@ -67,6 +96,11 @@ public function addTags($methodVars) {
67
96
}
68
97
}
69
98
99
+ /**
100
+ * Get the metadata for an album on Last.fm using the album name or a musicbrainz id
101
+ * @param array $methodVars An array with the following required values: <i>album</i> and optional values: <i>artist</i>, <i>mbid</i>
102
+ * @return array
103
+ */
70
104
public function getInfo ($ methodVars ) {
71
105
// Set the call variables
72
106
$ vars = array (
@@ -76,33 +110,39 @@ public function getInfo($methodVars) {
76
110
'artist ' => @$ methodVars ['artist ' ],
77
111
'mbid ' => @$ methodVars ['mbid ' ]
78
112
);
113
+ $ info = array ();
79
114
80
115
if ( $ call = $ this ->apiGetCall ($ vars ) ) {
81
- $ this -> info ['name ' ] = (string ) $ call ->album ->name ;
82
- $ this -> info ['artist ' ] = (string ) $ call ->album ->artist ;
83
- $ this -> info ['lastfmid ' ] = (string ) $ call ->album ->id ;
84
- $ this -> info ['mbid ' ] = (string ) $ call ->album ->mbid ;
85
- $ this -> info ['url ' ] = (string ) $ call ->album ->url ;
86
- $ this -> info ['releasedate ' ] = strtotime (trim ((string ) $ call ->album ->releasedate ));
87
- $ this -> info ['image ' ]['small ' ] = (string ) $ call ->album ->image ;
88
- $ this -> info ['image ' ]['medium ' ] = (string ) $ call ->album ->image [1 ];
89
- $ this -> info ['image ' ]['large ' ] = (string ) $ call ->album ->image [2 ];
90
- $ this -> info ['listeners ' ] = (string ) $ call ->album ->listeners ;
91
- $ this -> info ['playcount ' ] = (string ) $ call ->album ->playcount ;
116
+ $ info ['name ' ] = (string ) $ call ->album ->name ;
117
+ $ info ['artist ' ] = (string ) $ call ->album ->artist ;
118
+ $ info ['lastfmid ' ] = (string ) $ call ->album ->id ;
119
+ $ info ['mbid ' ] = (string ) $ call ->album ->mbid ;
120
+ $ info ['url ' ] = (string ) $ call ->album ->url ;
121
+ $ info ['releasedate ' ] = strtotime (trim ((string ) $ call ->album ->releasedate ));
122
+ $ info ['image ' ]['small ' ] = (string ) $ call ->album ->image ;
123
+ $ info ['image ' ]['medium ' ] = (string ) $ call ->album ->image [1 ];
124
+ $ info ['image ' ]['large ' ] = (string ) $ call ->album ->image [2 ];
125
+ $ info ['listeners ' ] = (string ) $ call ->album ->listeners ;
126
+ $ info ['playcount ' ] = (string ) $ call ->album ->playcount ;
92
127
$ i = 0 ;
93
128
foreach ( $ call ->album ->toptags ->tag as $ tags ) {
94
- $ this -> info ['toptags ' ][$ i ]['name ' ] = (string ) $ tags ->name ;
95
- $ this -> info ['toptags ' ][$ i ]['url ' ] = (string ) $ tags ->url ;
129
+ $ info ['toptags ' ][$ i ]['name ' ] = (string ) $ tags ->name ;
130
+ $ info ['toptags ' ][$ i ]['url ' ] = (string ) $ tags ->url ;
96
131
$ i ++;
97
132
}
98
133
99
- return $ this -> info ;
134
+ return $ info ;
100
135
}
101
136
else {
102
137
return FALSE ;
103
138
}
104
139
}
105
140
141
+ /**
142
+ * Get the tags applied by an individual user to an album on Last.fm
143
+ * @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i>
144
+ * @return array
145
+ */
106
146
public function getTags ($ methodVars ) {
107
147
// Only allow full authed calls
108
148
if ( $ this ->fullAuth == TRUE ) {
@@ -119,18 +159,19 @@ public function getTags($methodVars) {
119
159
// Generate a call signiture
120
160
$ sig = $ this ->apiSig ($ this ->auth ->secret , $ vars );
121
161
$ vars ['api_sig ' ] = $ sig ;
162
+ $ tags = array ();
122
163
123
164
// Make the call
124
165
if ( $ call = $ this ->apiGetCall ($ vars ) ) {
125
166
if ( count ($ call ->tags ->tag ) > 0 ) {
126
167
$ i = 0 ;
127
168
foreach ( $ call ->tags ->tag as $ tag ) {
128
- $ this -> tags [$ i ]['name ' ] = (string ) $ tag ->name ;
129
- $ this -> tags [$ i ]['url ' ] = (string ) $ tag ->url ;
169
+ $ tags [$ i ]['name ' ] = (string ) $ tag ->name ;
170
+ $ tags [$ i ]['url ' ] = (string ) $ tag ->url ;
130
171
$ i ++;
131
172
}
132
173
133
- return $ this -> tags ;
174
+ return $ tags ;
134
175
}
135
176
else {
136
177
$ this ->handleError (90 , 'User has no tags for this artist ' );
@@ -154,6 +195,11 @@ public function getTags($methodVars) {
154
195
}
155
196
}
156
197
198
+ /**
199
+ * Remove a user's tag from an album. (Requires full auth)
200
+ * @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i>, <i>tag</i>
201
+ * @return boolean
202
+ */
157
203
public function removeTag ($ methodVars ) {
158
204
// Only allow full authed calls
159
205
if ( $ this ->fullAuth == TRUE ) {
@@ -193,6 +239,11 @@ public function removeTag($methodVars) {
193
239
}
194
240
}
195
241
242
+ /**
243
+ * Search for an album by name. Returns album matches sorted by relevance
244
+ * @param array $methodVars An array with the following required values: <i>album</i>
245
+ * @return array
246
+ */
196
247
public function search ($ methodVars ) {
197
248
// Check for required variables
198
249
if ( !empty ($ methodVars ['album ' ]) ) {
@@ -207,27 +258,28 @@ public function search($methodVars) {
207
258
if ( !empty ($ methodVars ['page ' ]) ) {
208
259
$ vars ['page ' ] = $ methodVars ['page ' ];
209
260
}
261
+ $ searchresults = array ();
210
262
211
263
if ( $ call = $ this ->apiGetCall ($ vars ) ) {
212
264
$ opensearch = $ call ->results ->children ('http://a9.com/-/spec/opensearch/1.1/ ' );
213
265
if ( $ opensearch ->totalResults > 0 ) {
214
- $ this -> searchResults ['totalResults ' ] = (string ) $ opensearch ->totalResults ;
215
- $ this -> searchResults ['startIndex ' ] = (string ) $ opensearch ->startIndex ;
216
- $ this -> searchResults ['itemsPerPage ' ] = (string ) $ opensearch ->itemsPerPage ;
266
+ $ searchresults ['totalResults ' ] = (string ) $ opensearch ->totalResults ;
267
+ $ searchresults ['startIndex ' ] = (string ) $ opensearch ->startIndex ;
268
+ $ searchresults ['itemsPerPage ' ] = (string ) $ opensearch ->itemsPerPage ;
217
269
$ i = 0 ;
218
270
foreach ( $ call ->results ->albummatches ->album as $ album ) {
219
- $ this -> searchResults ['results ' ][$ i ]['name ' ] = (string ) $ album ->name ;
220
- $ this -> searchResults ['results ' ][$ i ]['artist ' ] = (string ) $ album ->artist ;
221
- $ this -> searchResults ['results ' ][$ i ]['id ' ] = (string ) $ album ->id ;
222
- $ this -> searchResults ['results ' ][$ i ]['url ' ] = (string ) $ album ->url ;
223
- $ this -> searchResults ['results ' ][$ i ]['streamable ' ] = (string ) $ album ->streamable ;
224
- $ this -> searchResults ['results ' ][$ i ]['image ' ]['small ' ] = (string ) $ album ->image [0 ];
225
- $ this -> searchResults ['results ' ][$ i ]['image ' ]['medium ' ] = (string ) $ album ->image [1 ];
226
- $ this -> searchResults ['results ' ][$ i ]['image ' ]['large ' ] = (string ) $ album ->image [2 ];
271
+ $ searchresults ['results ' ][$ i ]['name ' ] = (string ) $ album ->name ;
272
+ $ searchresults ['results ' ][$ i ]['artist ' ] = (string ) $ album ->artist ;
273
+ $ searchresults ['results ' ][$ i ]['id ' ] = (string ) $ album ->id ;
274
+ $ searchresults ['results ' ][$ i ]['url ' ] = (string ) $ album ->url ;
275
+ $ searchresults ['results ' ][$ i ]['streamable ' ] = (string ) $ album ->streamable ;
276
+ $ searchresults ['results ' ][$ i ]['image ' ]['small ' ] = (string ) $ album ->image [0 ];
277
+ $ searchresults ['results ' ][$ i ]['image ' ]['medium ' ] = (string ) $ album ->image [1 ];
278
+ $ searchresults ['results ' ][$ i ]['image ' ]['large ' ] = (string ) $ album ->image [2 ];
227
279
$ i ++;
228
280
}
229
281
230
- return $ this -> searchResults ;
282
+ return $ searchresults ;
231
283
}
232
284
else {
233
285
// No tagsare found
0 commit comments