|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Nalina Hariharan |
|
14 * |
|
15 * Description: |
|
16 * The Plugin that does music search related functionalities from last.fm site |
|
17 * |
|
18 */ |
|
19 |
|
20 // Include files |
|
21 #include <QtPlugin> |
|
22 #include <QDebug> |
|
23 #include <QCryptographicHash> |
|
24 #include <QTextStream> |
|
25 #include <QFile> |
|
26 #include <QMap> |
|
27 #include <QListIterator> |
|
28 #include <QSettings> |
|
29 #include <smfpluginutil.h> |
|
30 #include <qlocale.h> |
|
31 #include <smfprovider.h> |
|
32 |
|
33 #include "lastfmmusicsearchplugin.h" |
|
34 |
|
35 static int gPageNum = 0; |
|
36 static int gItemsPerPage = 0; |
|
37 static quint8 forTracksOfAlbum = 0; |
|
38 QString albumId; |
|
39 |
|
40 int gOperationId; |
|
41 |
|
42 |
|
43 /** |
|
44 * Destructor |
|
45 */ |
|
46 LastFmMusicSearchPlugin::~LastFmMusicSearchPlugin( ) |
|
47 { |
|
48 if(m_provider) |
|
49 delete m_provider; |
|
50 } |
|
51 |
|
52 /** |
|
53 * Method to interpret the key sets obtained from credential manager |
|
54 * @param aApiKey [out] The api key |
|
55 * @param aApiSecret [out] The api secret |
|
56 * @param aSessionKey [out] The session key |
|
57 * @param aToken [out] The session token |
|
58 */ |
|
59 void LastFmMusicSearchPlugin::fetchKeys( QString &aApiKey, |
|
60 QString &aApiSecret, |
|
61 QString &aToken ) |
|
62 { |
|
63 qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken; |
|
64 qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t(); |
|
65 |
|
66 SmfAuthParams keys; |
|
67 SmfPluginUtil util; |
|
68 util.getAuthKeys(keys, m_provider->m_smfRegToken, |
|
69 m_provider->m_validity, m_provider->m_pluginId); |
|
70 |
|
71 QByteArray keyName; |
|
72 keyName.append("ApiKey"); |
|
73 aApiKey.append(keys.value(keyName)); |
|
74 |
|
75 keyName.clear(); |
|
76 keyName.append("ApiSecret"); |
|
77 aApiSecret.append(keys.value(keyName)); |
|
78 |
|
79 keyName.clear(); |
|
80 keyName.append("Token"); |
|
81 aToken.append(keys.value(keyName)); |
|
82 |
|
83 qDebug()<<"Api Key = "<<aApiKey; |
|
84 qDebug()<<"Api Secret = "<<aApiSecret; |
|
85 qDebug()<<"Token = "<<aToken; |
|
86 } |
|
87 |
|
88 /** |
|
89 * Method called by plugins to generate a signature string from a base string |
|
90 * @param aBaseString The base string |
|
91 * @return The md5 hash of the base string |
|
92 */ |
|
93 QString LastFmMusicSearchPlugin::generateSignature(const QString aBaseString) |
|
94 { |
|
95 // Create md5 hash of the signature string |
|
96 QByteArray byteArray; |
|
97 byteArray.insert(0, aBaseString.toAscii()); |
|
98 |
|
99 QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex(); |
|
100 QString returnString (md5Hash); |
|
101 return returnString; |
|
102 } |
|
103 |
|
104 /** |
|
105 * Method to get the current country name as per ISO 3166-1 standard. |
|
106 * @return Current country name |
|
107 */ |
|
108 QString LastFmMusicSearchPlugin::currentCountryName() const |
|
109 { |
|
110 // ToDo :- complete remaining country code and names |
|
111 QLocale locale; |
|
112 QLocale::Country country = locale.country(); |
|
113 |
|
114 switch(country) |
|
115 { |
|
116 case 0: |
|
117 return QString(); |
|
118 case 1: |
|
119 return QString("AFGHANISTAN"); |
|
120 // ToDo :- fill for other countries |
|
121 case 100: |
|
122 return QString("INDIA"); |
|
123 case 224: // UK |
|
124 return QString("UNITED KINGDOM"); |
|
125 default: |
|
126 return QString(); |
|
127 } |
|
128 } |
|
129 |
|
130 /** |
|
131 * Method to get recommended tracks |
|
132 * @param aRequest [out] The request data to be sent to network |
|
133 * @param aTrack The track for which similar recommendations |
|
134 * need to be fetched. |
|
135 * @param aPageNum The page to be extracted |
|
136 * @param aItemsPerPage Number of items per page |
|
137 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
138 */ |
|
139 SmfPluginError LastFmMusicSearchPlugin::recommendations( SmfPluginRequestData &aRequest, |
|
140 const SmfTrackInfo &aTrack, |
|
141 const int aPageNum, |
|
142 const int aItemsPerPage ) |
|
143 { |
|
144 Q_UNUSED(aRequest) |
|
145 Q_UNUSED(aTrack) |
|
146 Q_UNUSED(aPageNum) |
|
147 Q_UNUSED(aItemsPerPage) |
|
148 qDebug()<<"Inside LastFmMusicSearchPlugin::recommendations()"; |
|
149 SmfPluginError error = SmfPluginErrInvalidRequest; |
|
150 return error; |
|
151 |
|
152 #if 0 // recommended artist not present in music.search interface |
|
153 qDebug()<<"Inside LastFmMusicSearchPlugin::recommendations()"; |
|
154 |
|
155 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
156 |
|
157 // invalid arguments |
|
158 if( aPageNum < 0 || aItemsPerPage < 0 ) |
|
159 { |
|
160 qDebug()<<"Invalid arguments"; |
|
161 return error; |
|
162 } |
|
163 |
|
164 qDebug()<<"Valid arguments"; |
|
165 |
|
166 // Get the key sets from SMF Plugin Utility class. |
|
167 QString apiKey; |
|
168 QString apiSecret; |
|
169 QString token; |
|
170 fetchKeys(apiKey, apiSecret, token); |
|
171 |
|
172 // Create the API signature string |
|
173 QString baseString; |
|
174 baseString.append("api_key"+apiKey); |
|
175 baseString.append("methoduser.getRecommendedArtists"); |
|
176 baseString.append("sk"+token); |
|
177 baseString.append(apiSecret); |
|
178 |
|
179 // Create the url |
|
180 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
181 url.addQueryItem("api_key", apiKey); |
|
182 url.addQueryItem("format", "json"); |
|
183 url.addQueryItem("method", "user.getRecommendedArtists"); |
|
184 url.addQueryItem("sk", token); |
|
185 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
186 |
|
187 // Create the request, set the url |
|
188 aRequest.iNetworkRequest.setUrl(url); |
|
189 aRequest.iRequestType = SmfMusicGetRecommendations; |
|
190 aRequest.iPostData = NULL; |
|
191 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
192 error = SmfPluginErrNone; |
|
193 |
|
194 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
195 return error; |
|
196 #endif |
|
197 } |
|
198 |
|
199 /** |
|
200 * Method to search for tracks similar to a given track |
|
201 * @param aRequest [out] The request data to be sent to network |
|
202 * @param aTrack The track for which similar tracks |
|
203 * need to be fetched. |
|
204 * @param aPageNum The page to be extracted |
|
205 * @param aItemsPerPage Number of items per page |
|
206 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
207 */ |
|
208 SmfPluginError LastFmMusicSearchPlugin::tracksSimilar( SmfPluginRequestData &aRequest, |
|
209 const SmfTrackInfo &aTrack, |
|
210 const int aPageNum, |
|
211 const int aItemsPerPage ) |
|
212 { |
|
213 // Note : |
|
214 // only mbid won't work |
|
215 // only artist won't work |
|
216 // only track wont work |
|
217 // a combination of artist mbid and track name won't work |
|
218 // Give a combination of artist name and track name for a valid response |
|
219 qDebug()<<"Inside LastFmMusicSearchPlugin::tracksSimilar()"; |
|
220 qDebug()<<"Page num = "<<aPageNum; |
|
221 qDebug()<<"item per Page = "<<aItemsPerPage; |
|
222 |
|
223 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
224 |
|
225 // invalid arguments |
|
226 if( aPageNum < 0 || aItemsPerPage < 0 || (0 == aTrack.artists().names().count()) || |
|
227 aTrack.title().isEmpty() ) |
|
228 { |
|
229 qDebug()<<"Invalid arguments"; |
|
230 return error; |
|
231 } |
|
232 |
|
233 qDebug()<<"Valid arguments"; |
|
234 |
|
235 gPageNum = aPageNum; |
|
236 gItemsPerPage = aItemsPerPage; |
|
237 |
|
238 // Get the key sets from SMF Plugin Utility class. |
|
239 QString apiKey; |
|
240 QString apiSecret; |
|
241 QString token; |
|
242 fetchKeys(apiKey, apiSecret, token); |
|
243 |
|
244 // Create the API signature string |
|
245 QString baseString; |
|
246 baseString.append("api_key"+apiKey); |
|
247 baseString.append("artist"+aTrack.artists().names().at(0)); // artist name |
|
248 baseString.append("methodtrack.getSimilar"); |
|
249 baseString.append("track"+aTrack.title()); // track name |
|
250 baseString.append(apiSecret); |
|
251 |
|
252 // Create the url |
|
253 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
254 url.addQueryItem("api_key", apiKey); |
|
255 url.addQueryItem("artist", aTrack.artists().names().at(0)); |
|
256 url.addQueryItem("format", "json"); |
|
257 url.addQueryItem("method", "track.getSimilar"); |
|
258 url.addQueryItem("track", aTrack.title()); |
|
259 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
260 |
|
261 // Create the request, set the url |
|
262 aRequest.iNetworkRequest.setUrl(url); |
|
263 aRequest.iRequestType = SmfMusicGetTracksSimilar; |
|
264 aRequest.iPostData = NULL; |
|
265 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
266 error = SmfPluginErrNone; |
|
267 |
|
268 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
269 return error; |
|
270 } |
|
271 |
|
272 /** |
|
273 * Method to search for tracks of a given album |
|
274 * @param aRequest [out] The request data to be sent to network |
|
275 * @param aAlbum The album whose tracks need to be fetched. |
|
276 * @param aPageNum The page to be extracted |
|
277 * @param aItemsPerPage Number of items per page |
|
278 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
279 */ |
|
280 SmfPluginError LastFmMusicSearchPlugin::tracksOfAlbum( SmfPluginRequestData &aRequest, |
|
281 const SmfAlbum &aAlbum, |
|
282 const int aPageNum, |
|
283 const int aItemsPerPage ) |
|
284 { |
|
285 qDebug()<<"Inside LastFmMusicSearchPlugin::tracksOfAlbum()"; |
|
286 qDebug()<<"Page num = "<<aPageNum; |
|
287 qDebug()<<"item per Page = "<<aItemsPerPage; |
|
288 |
|
289 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
290 |
|
291 // invalid arguments |
|
292 if( aPageNum < 0 || aItemsPerPage < 0 || aAlbum.name().isEmpty() |
|
293 || aAlbum.artists().names().at(0).isEmpty() ) |
|
294 { |
|
295 qDebug()<<"Invalid arguments"; |
|
296 return error; |
|
297 } |
|
298 |
|
299 qDebug()<<"Valid arguments"; |
|
300 |
|
301 gPageNum = aPageNum; |
|
302 gItemsPerPage = aItemsPerPage; |
|
303 |
|
304 if(0 == forTracksOfAlbum) |
|
305 return getAlbumId(aRequest, aAlbum); |
|
306 else //if(1 == forTracksOfAlbum) |
|
307 return getTracksOfAlbum(aRequest, aAlbum); |
|
308 } |
|
309 |
|
310 /** |
|
311 * Method to get the last.fm specific ID of the given album |
|
312 * @param aRequest [out] The request data to be sent to network |
|
313 * @param aAlbum The album whose tracks need to be fetched. |
|
314 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
315 */ |
|
316 SmfPluginError LastFmMusicSearchPlugin::getAlbumId( SmfPluginRequestData &aRequest, |
|
317 const SmfAlbum &aAlbum ) |
|
318 { |
|
319 qDebug()<<"Inside LastFmMusicSearchPlugin::getAlbumId()"; |
|
320 |
|
321 SmfPluginError error = SmfPluginErrNone; |
|
322 |
|
323 // Get the key sets from SMF Plugin Utility class. |
|
324 QString apiKey; |
|
325 QString apiSecret; |
|
326 QString token; |
|
327 fetchKeys(apiKey, apiSecret, token); |
|
328 |
|
329 // Create the API signature string |
|
330 QString baseString; |
|
331 baseString.append("album"+aAlbum.name()); // album name |
|
332 baseString.append("api_key"+apiKey); |
|
333 baseString.append("artist"+aAlbum.artists().names().at(0)); // artist name |
|
334 baseString.append("methodalbum.getInfo"); |
|
335 baseString.append(apiSecret); |
|
336 |
|
337 // Create the url |
|
338 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
339 url.addQueryItem("album", aAlbum.name()); |
|
340 url.addQueryItem("api_key", apiKey); |
|
341 url.addQueryItem("artist", aAlbum.artists().names().at(0)); |
|
342 url.addQueryItem("format", "json"); |
|
343 url.addQueryItem("method", "album.getInfo"); |
|
344 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
345 |
|
346 // Create the request, set the url |
|
347 aRequest.iNetworkRequest.setUrl(url); |
|
348 aRequest.iRequestType = SmfMusicGetTracksOfAlbum; |
|
349 aRequest.iPostData = NULL; |
|
350 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
351 error = SmfPluginErrNone; |
|
352 |
|
353 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
354 return error; |
|
355 } |
|
356 |
|
357 /** |
|
358 * Method to search for tracks of a given album using its ID in last.fm |
|
359 * @param aRequest [out] The request data to be sent to network |
|
360 * @param aAlbum The album whose tracks need to be fetched. |
|
361 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
362 */ |
|
363 SmfPluginError LastFmMusicSearchPlugin::getTracksOfAlbum( SmfPluginRequestData &aRequest, |
|
364 const SmfAlbum &aAlbum) |
|
365 { |
|
366 qDebug()<<"Inside LastFmMusicSearchPlugin::getTracksOfAlbum()"; |
|
367 Q_UNUSED(aAlbum) |
|
368 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
369 |
|
370 // Get the key sets from SMF Plugin Utility class. |
|
371 QString apiKey; |
|
372 QString apiSecret; |
|
373 QString token; |
|
374 fetchKeys(apiKey, apiSecret, token); |
|
375 |
|
376 QString playlistUrl("lastfm://playlist/album/"); |
|
377 playlistUrl.append(albumId); |
|
378 |
|
379 // Create the API signature string |
|
380 QString baseString; |
|
381 baseString.append("api_key"+apiKey); |
|
382 baseString.append("methodplaylist.fetch"); |
|
383 baseString.append("playlistURL"+playlistUrl); |
|
384 baseString.append(apiSecret); |
|
385 |
|
386 // Create the url |
|
387 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
388 url.addQueryItem("api_key", apiKey); |
|
389 url.addQueryItem("format", "json"); |
|
390 url.addQueryItem("method", "playlist.fetch"); |
|
391 url.addQueryItem("playlistURL", playlistUrl); |
|
392 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
393 |
|
394 // Create the request, set the url |
|
395 aRequest.iNetworkRequest.setUrl(url); |
|
396 aRequest.iRequestType = SmfMusicGetTracksOfAlbum; |
|
397 aRequest.iPostData = NULL; |
|
398 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
399 error = SmfPluginErrNone; |
|
400 |
|
401 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
402 return error; |
|
403 } |
|
404 |
|
405 /** |
|
406 * Method to search for tracks of the given artist(s) |
|
407 * @param aRequest [out] The request data to be sent to network |
|
408 * @param aArtist The artist(s) whose tracks need to be fetched. |
|
409 * @param aPageNum The page to be extracted |
|
410 * @param aItemsPerPage Number of items per page |
|
411 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
412 */ |
|
413 SmfPluginError LastFmMusicSearchPlugin::tracksOfArtist( SmfPluginRequestData &aRequest, |
|
414 const SmfArtists &aArtist, |
|
415 const int aPageNum, |
|
416 const int aItemsPerPage ) |
|
417 { |
|
418 qDebug()<<"Inside LastFmMusicSearchPlugin::tracksOfArtist()"; |
|
419 qDebug()<<"Page num = "<<aPageNum; |
|
420 qDebug()<<"item per Page = "<<aItemsPerPage; |
|
421 |
|
422 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
423 |
|
424 // invalid arguments |
|
425 if( aPageNum < 0 || aItemsPerPage < 0 || aArtist.names().at(0).isEmpty() ) |
|
426 { |
|
427 qDebug()<<"Invalid arguments"; |
|
428 return error; |
|
429 } |
|
430 |
|
431 qDebug()<<"Valid arguments"; |
|
432 |
|
433 gPageNum = aPageNum; |
|
434 gItemsPerPage = aItemsPerPage; |
|
435 |
|
436 // Get the key sets from SMF Plugin Utility class. |
|
437 QString apiKey; |
|
438 QString apiSecret; |
|
439 QString token; |
|
440 fetchKeys(apiKey, apiSecret, token); |
|
441 |
|
442 // Create the API signature string |
|
443 QString baseString; |
|
444 baseString.append("api_key"+apiKey); |
|
445 baseString.append("artist"+aArtist.names().at(0)); // artist name |
|
446 baseString.append("methodartist.getTopTracks"); |
|
447 baseString.append(apiSecret); |
|
448 |
|
449 // Create the url |
|
450 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
451 url.addQueryItem("api_key", apiKey); |
|
452 url.addQueryItem("artist", aArtist.names().at(0)); |
|
453 url.addQueryItem("format", "json"); |
|
454 url.addQueryItem("method", "artist.getTopTracks"); |
|
455 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
456 |
|
457 // Create the request, set the url |
|
458 aRequest.iNetworkRequest.setUrl(url); |
|
459 aRequest.iRequestType = SmfMusicGetTracksOfArtist; |
|
460 aRequest.iPostData = NULL; |
|
461 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
462 error = SmfPluginErrNone; |
|
463 |
|
464 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
465 return error; |
|
466 } |
|
467 |
|
468 /** |
|
469 * Method to get tracks having a similar finger print |
|
470 * @param aRequest [out] The request data to be sent to network |
|
471 * @param aSignature The finger print to be searched for need to be |
|
472 * fetched. |
|
473 * @param aPageNum The page to be extracted |
|
474 * @param aItemsPerPage Number of items per page |
|
475 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
476 */ |
|
477 SmfPluginError LastFmMusicSearchPlugin::trackInfo( SmfPluginRequestData &aRequest, |
|
478 const SmfMusicFingerPrint &aSignature, |
|
479 const int aPageNum, |
|
480 const int aItemsPerPage ) |
|
481 { |
|
482 qDebug()<<"Inside LastFmMusicSearchPlugin::trackInfo()"; |
|
483 |
|
484 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
485 |
|
486 // invalid arguments |
|
487 if( aPageNum < 0 || aItemsPerPage < 0 || aSignature.id().isEmpty() ) |
|
488 { |
|
489 qDebug()<<"Invalid arguments"; |
|
490 return error; |
|
491 } |
|
492 |
|
493 qDebug()<<"Valid arguments"; |
|
494 |
|
495 gPageNum = aPageNum; |
|
496 gItemsPerPage = aItemsPerPage; |
|
497 |
|
498 // Get the key sets from SMF Plugin Utility class. |
|
499 QString apiKey; |
|
500 QString apiSecret; |
|
501 QString token; |
|
502 fetchKeys(apiKey, apiSecret, token); |
|
503 |
|
504 // Create the API signature string |
|
505 QString baseString; |
|
506 baseString.append("api_key"+apiKey); |
|
507 baseString.append("fingerprintid"+aSignature.id()); |
|
508 baseString.append("methodtrack.getFingerprintMetadata"); |
|
509 baseString.append(apiSecret); |
|
510 |
|
511 // Create the url |
|
512 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
513 url.addQueryItem("api_key", apiKey); |
|
514 url.addQueryItem("fingerprintid", aSignature.id()); |
|
515 url.addQueryItem("format", "json"); |
|
516 url.addQueryItem("method", "track.getFingerprintMetadata"); |
|
517 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
518 |
|
519 // Create the request, set the url |
|
520 aRequest.iNetworkRequest.setUrl(url); |
|
521 aRequest.iRequestType = SmfMusicGetTrackInfo; |
|
522 aRequest.iPostData = NULL; |
|
523 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
524 error = SmfPluginErrNone; |
|
525 |
|
526 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
527 return error; |
|
528 } |
|
529 |
|
530 /** |
|
531 * Method to search information about where to buy this song from |
|
532 * @param aRequest [out] The request data to be sent to network |
|
533 * @param aTrack The track for which stores need to be searched |
|
534 * @param aPageNum The page to be extracted |
|
535 * @param aItemsPerPage Number of items per page |
|
536 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
537 */ |
|
538 SmfPluginError LastFmMusicSearchPlugin::stores( SmfPluginRequestData &aRequest, |
|
539 const SmfTrackInfo &aTrack, |
|
540 const int aPageNum, |
|
541 const int aItemsPerPage ) |
|
542 { |
|
543 qDebug()<<"Inside LastFmMusicSearchPlugin::stores()"; |
|
544 |
|
545 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
546 |
|
547 // invalid arguments |
|
548 if( aPageNum < 0 || aItemsPerPage < 0 || (0 == aTrack.artists().names().count()) || |
|
549 aTrack.album().name().isEmpty() ) |
|
550 { |
|
551 qDebug()<<"Invalid arguments"; |
|
552 return error; |
|
553 } |
|
554 |
|
555 qDebug()<<"Valid arguments"; |
|
556 |
|
557 gPageNum = aPageNum; |
|
558 gItemsPerPage = aItemsPerPage; |
|
559 |
|
560 // Get the key sets from SMF Plugin Utility class. |
|
561 QString apiKey; |
|
562 QString apiSecret; |
|
563 QString token; |
|
564 fetchKeys(apiKey, apiSecret, token); |
|
565 |
|
566 QString countryName = currentCountryName(); |
|
567 |
|
568 // Create the API signature string |
|
569 QString baseString; |
|
570 baseString.append("album"+aTrack.album().name()); |
|
571 baseString.append("api_key"+apiKey); |
|
572 baseString.append("artist"+aTrack.artists().names().at(0)); |
|
573 baseString.append("country"+countryName); |
|
574 baseString.append("methodalbum.getBuylinks"); |
|
575 baseString.append(apiSecret); |
|
576 |
|
577 // Create the url |
|
578 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
579 url.addQueryItem("album", aTrack.album().name()); |
|
580 url.addQueryItem("api_key", apiKey); |
|
581 url.addQueryItem("artist", aTrack.artists().names().at(0)); |
|
582 url.addQueryItem("country", countryName); |
|
583 url.addQueryItem("format", "json"); |
|
584 url.addQueryItem("method", "album.getBuylinks"); |
|
585 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
586 |
|
587 // Create the request, set the url |
|
588 aRequest.iNetworkRequest.setUrl(url); |
|
589 aRequest.iRequestType = SmfMusicGetStores; |
|
590 aRequest.iPostData = NULL; |
|
591 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
592 error = SmfPluginErrNone; |
|
593 |
|
594 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
595 return error; |
|
596 } |
|
597 |
|
598 /** |
|
599 * Customised method for SmfMusicSearchPlugin interface |
|
600 * @param aRequest [out] The request data to be sent to network |
|
601 * @param aOperation The operation type (should be known between |
|
602 * the client interface and the plugin) |
|
603 * @param aData The data required to form the request (The type |
|
604 * of data should be known between client and the plugin) |
|
605 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
606 */ |
|
607 SmfPluginError LastFmMusicSearchPlugin::customRequest( SmfPluginRequestData &aRequest, |
|
608 const int &aOperation, QByteArray *aData ) |
|
609 { |
|
610 qDebug()<<"Inside LastFmMusicSearchPlugin::customRequest()"; |
|
611 |
|
612 SmfPluginError error = SmfPluginErrInvalidArguments; |
|
613 |
|
614 // invalid arguments |
|
615 if( NULL == aData ) |
|
616 { |
|
617 qDebug()<<"Invalid arguments"; |
|
618 return error; |
|
619 } |
|
620 |
|
621 qDebug()<<"Valid arguments"; |
|
622 |
|
623 // Get the key sets from SMF Plugin Utility class. |
|
624 QString apiKey; |
|
625 QString apiSecret; |
|
626 QString token; |
|
627 fetchKeys(apiKey, apiSecret, token); |
|
628 |
|
629 |
|
630 if(107 == aOperation) |
|
631 { |
|
632 gOperationId = aOperation; |
|
633 int limit; |
|
634 int pageNum; |
|
635 SmfAlbum album; |
|
636 |
|
637 QDataStream read(aData, QIODevice::ReadOnly); |
|
638 read>>limit; |
|
639 read>>pageNum; |
|
640 read>>album; |
|
641 |
|
642 gItemsPerPage = limit; |
|
643 gPageNum = pageNum; |
|
644 |
|
645 // Create the API signature string |
|
646 QString baseString; |
|
647 baseString.append("album"+album.name()); |
|
648 baseString.append("api_key"+apiKey); |
|
649 baseString.append("limit"+QString::number(limit)); |
|
650 baseString.append("methodalbum.search"); |
|
651 baseString.append("page"+QString::number(pageNum)); |
|
652 baseString.append(apiSecret); |
|
653 |
|
654 // Create the url |
|
655 QUrl url("http://ws.audioscrobbler.com/2.0/?"); |
|
656 url.addQueryItem("album", album.name()); |
|
657 url.addQueryItem("api_key", apiKey); |
|
658 url.addQueryItem("limit", QString::number(limit)); |
|
659 url.addQueryItem("page", QString::number(pageNum)); |
|
660 url.addQueryItem("format", "json"); |
|
661 url.addQueryItem("method", "album.search"); |
|
662 url.addQueryItem("api_sig", generateSignature(baseString)); |
|
663 |
|
664 // Create the request, set the url |
|
665 aRequest.iNetworkRequest.setUrl(url); |
|
666 aRequest.iRequestType = SmfMusicSearchCustomRequest; |
|
667 aRequest.iPostData = NULL; |
|
668 aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
669 error = SmfPluginErrNone; |
|
670 |
|
671 qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
672 } |
|
673 return error; |
|
674 } |
|
675 |
|
676 /** |
|
677 * The first method to be called in the plugin that implements this interface. |
|
678 * If this method is not called, plugin may not behave as expected. |
|
679 */ |
|
680 void LastFmMusicSearchPlugin::initialize( ) |
|
681 { |
|
682 // Create an instance of LastFmMusicSearchProviderBase |
|
683 m_provider = new LastFmMusicSearchProviderBase; |
|
684 m_provider->initialize(); |
|
685 } |
|
686 |
|
687 /** |
|
688 * Method to get the provider information |
|
689 * @return Instance of SmfProviderBase |
|
690 */ |
|
691 SmfProviderBase* LastFmMusicSearchPlugin::getProviderInfo( ) |
|
692 { |
|
693 return m_provider; |
|
694 } |
|
695 |
|
696 /** |
|
697 * Method to get the result for a network request. |
|
698 * @param aOperation The type of operation to be requested |
|
699 * @param aTransportResult The result of transport operation |
|
700 * @param aResponse The QByteArray instance containing the network response. |
|
701 * The plugins should delete this instance once they have read the |
|
702 * data from it. |
|
703 * @param aResult [out] An output parameter to the plugin manager.If the |
|
704 * return value is SmfSendRequestAgain, QVariant will be of type |
|
705 * SmfPluginRequestData. |
|
706 * For SmfMusicSearchPlugin: If last operation was recommendations(), |
|
707 * tracksSimilar() or tracksOfAlbum() or tracksOfArtist() or trackInfo(), |
|
708 * aResult will be of type QList<SmfTrackInfo>. |
|
709 * If last operation was stores(), aResult will be of type QList<SmfProvider>. |
|
710 * @param aRetType [out] SmfPluginRetType |
|
711 * @param aPageResult [out] The SmfResultPage structure variable |
|
712 */ |
|
713 SmfPluginError LastFmMusicSearchPlugin::responseAvailable( |
|
714 const SmfRequestTypeID aOperation, |
|
715 const SmfTransportResult &aTransportResult, |
|
716 QByteArray *aResponse, |
|
717 QVariant* aResult, |
|
718 SmfPluginRetType &aRetType, |
|
719 SmfResultPage &aPageResult ) |
|
720 { |
|
721 Q_UNUSED(aPageResult) |
|
722 qDebug()<<"Inside LastFmMusicSearchPlugin::responseAvailable()"; |
|
723 |
|
724 SmfPluginError error = SmfPluginErrNetworkError; |
|
725 |
|
726 if( !aResponse || (0 == aResponse->size()) ) |
|
727 { |
|
728 qDebug()<<"Response is NULL or empty"; |
|
729 aRetType = SmfRequestError; |
|
730 return error; |
|
731 } |
|
732 |
|
733 QByteArray response(*aResponse); |
|
734 delete aResponse; |
|
735 |
|
736 QFile respFile("c://data//SmfMusicSearchPluginResponse.txt"); |
|
737 if(!respFile.open(QIODevice::WriteOnly)) |
|
738 qDebug()<<"File to write the response could not be opened"; |
|
739 else |
|
740 { |
|
741 respFile.write(response); |
|
742 respFile.close(); |
|
743 qDebug()<<"Writing FB response to a file named 'SmfMusicSearchPluginResponse.txt'"; |
|
744 } |
|
745 qDebug()<<"FB response size = "<<response.size(); |
|
746 |
|
747 if(SmfTransportOpNoError == aTransportResult) |
|
748 { |
|
749 qDebug()<<"No transport error"; |
|
750 |
|
751 if((SmfMusicGetTracksSimilar == aOperation) || (SmfMusicGetTracksOfArtist == aOperation)) |
|
752 { |
|
753 qDebug()<<"Response for music search get similar tracks/artist's tracks"; |
|
754 |
|
755 QList<SmfTrackInfo> list; |
|
756 QString errStr; |
|
757 errStr.clear(); |
|
758 |
|
759 bool ok; |
|
760 SmfPluginUtil util; |
|
761 QVariantMap result = util.parse(response, &ok).toMap(); |
|
762 if (!ok) |
|
763 { |
|
764 qDebug()<<"An error occurred during json parsing"; |
|
765 aRetType = SmfRequestError; |
|
766 return SmfPluginErrParsingFailed; |
|
767 } |
|
768 |
|
769 if(response.contains(QByteArray("error"))) |
|
770 { |
|
771 errStr.append(result["message"].toString()); |
|
772 } |
|
773 else |
|
774 { |
|
775 QVariantMap map1; |
|
776 if(SmfMusicGetTracksSimilar == aOperation) |
|
777 map1 = result["similartracks"].toMap(); |
|
778 else //if(SmfMusicGetTracksOfArtist == aOperation) // tracks of artists |
|
779 map1 = result["toptracks"].toMap(); |
|
780 QList<QVariant> list1 = map1["track"].toList(); |
|
781 QListIterator<QVariant> iter(list1); |
|
782 while(iter.hasNext()) |
|
783 { |
|
784 SmfTrackInfo track; |
|
785 |
|
786 QVariantMap map2 = iter.next().toMap(); |
|
787 qDebug()<<"track title = "<<map2["name"].toString(); |
|
788 if(SmfMusicGetTracksSimilar == aOperation) |
|
789 qDebug()<<"duration in milli sec = "<<map2["duration"].toString(); |
|
790 |
|
791 // Set the track title |
|
792 track.setTitle(map2["name"].toString()); |
|
793 |
|
794 // Set the tracks duration in seconds |
|
795 if(SmfMusicGetTracksSimilar == aOperation) |
|
796 { |
|
797 int timeValInSec = map2["duration"].toInt(); |
|
798 timeValInSec /= 1000; |
|
799 QString str = QString::number(timeValInSec); |
|
800 str.prepend("0."); |
|
801 QTime time = QTime::fromString(str, "m.z"); |
|
802 qDebug()<<" Time value = "<<time; |
|
803 track.setDuration(time); |
|
804 } |
|
805 |
|
806 // Set the track's Id - last.fm's mbid |
|
807 track.setId(map2["mbid"].toString()); |
|
808 |
|
809 // Set the tracks artist details |
|
810 QVariantMap map3 = map2["artist"].toMap(); |
|
811 SmfArtists artists; |
|
812 |
|
813 // Set the artist's name |
|
814 QStringList namesList; |
|
815 namesList.append(map3["name"].toString()); |
|
816 artists.setNames(namesList); |
|
817 |
|
818 // Set the artist's url |
|
819 QUrl url(map3["url"].toString()); |
|
820 artists.setUrl(url); |
|
821 |
|
822 // Set the artist's id |
|
823 artists.setId(map3["mbid"].toString()); |
|
824 |
|
825 // Set the artist's image url |
|
826 QList<QVariant> list2 = map3["image"].toList(); |
|
827 QListIterator<QVariant> iter2(list2); |
|
828 while(iter2.hasNext()) |
|
829 { |
|
830 QVariantMap map4 = iter.next().toMap(); |
|
831 |
|
832 // Set the artist's image url |
|
833 QUrl url(map4["#text"].toString()); |
|
834 //artists.setImageUrlurl); |
|
835 break; |
|
836 } |
|
837 |
|
838 track.setArtists(artists); |
|
839 |
|
840 list.append(track); |
|
841 if(gItemsPerPage == list.count()) |
|
842 break; |
|
843 } |
|
844 } |
|
845 |
|
846 if(errStr.size()) |
|
847 { |
|
848 qDebug()<<"Response error found = "<<errStr; |
|
849 error = SmfPluginErrInvalidRequest; |
|
850 aRetType = SmfRequestError; |
|
851 aResult->setValue(errStr); |
|
852 } |
|
853 else |
|
854 { |
|
855 qDebug()<<"list count = "<<list.count(); |
|
856 aResult->setValue(list); |
|
857 aRetType = SmfRequestComplete; |
|
858 error = SmfPluginErrNone; |
|
859 } |
|
860 } |
|
861 else if (SmfMusicGetTracksOfAlbum == aOperation) |
|
862 { |
|
863 qDebug()<<"Response for music search tracks of album"; |
|
864 |
|
865 if(0 == forTracksOfAlbum) // for fetching album ID |
|
866 { |
|
867 qDebug()<<"FOR GETTING ALBUMID"; |
|
868 QString errStr; |
|
869 errStr.clear(); |
|
870 |
|
871 bool ok; |
|
872 SmfPluginUtil util; |
|
873 QVariantMap result = util.parse(response, &ok).toMap(); |
|
874 if (!ok) |
|
875 { |
|
876 qDebug()<<"An error occurred during json parsing"; |
|
877 aRetType = SmfRequestError; |
|
878 return SmfPluginErrParsingFailed; |
|
879 } |
|
880 |
|
881 qDebug()<<"Json parsing complete"; |
|
882 |
|
883 if(response.contains(QByteArray("error"))) |
|
884 { |
|
885 errStr.append(result["message"].toString()); |
|
886 } |
|
887 else |
|
888 { |
|
889 QVariantMap map1 = result["album"].toMap(); |
|
890 albumId.clear(); |
|
891 albumId.append(map1["id"].toString()); |
|
892 forTracksOfAlbum = 1; |
|
893 } |
|
894 |
|
895 if(errStr.size()) |
|
896 { |
|
897 qDebug()<<"Response error found = "<<errStr; |
|
898 error = SmfPluginErrInvalidRequest; |
|
899 aRetType = SmfRequestError; |
|
900 aResult->setValue(errStr); |
|
901 } |
|
902 else |
|
903 { |
|
904 qDebug()<<"album id = "<<albumId; |
|
905 aRetType = SmfSendRequestAgain; |
|
906 error = SmfPluginErrNone; |
|
907 } |
|
908 } |
|
909 else // for fetching tracks of the album |
|
910 { |
|
911 qDebug()<<"FOR GETTING TRACKS OF ALBUM"; |
|
912 QList<SmfTrackInfo> list; |
|
913 QString errStr; |
|
914 errStr.clear(); |
|
915 |
|
916 bool ok; |
|
917 SmfPluginUtil util; |
|
918 QVariantMap result = util.parse(response, &ok).toMap(); |
|
919 if (!ok) |
|
920 { |
|
921 qDebug()<<"An error occurred during json parsing"; |
|
922 aRetType = SmfRequestError; |
|
923 return SmfPluginErrParsingFailed; |
|
924 } |
|
925 |
|
926 if(response.contains(QByteArray("error"))) |
|
927 { |
|
928 errStr.append(result["message"].toString()); |
|
929 } |
|
930 else |
|
931 { |
|
932 QVariantMap map1 = result["playlist"].toMap(); |
|
933 QVariantMap map2 = map1["trackList"].toMap(); |
|
934 QList<QVariant> list1 = map2["track"].toList(); |
|
935 QListIterator<QVariant> iter(list1); |
|
936 while(iter.hasNext()) |
|
937 { |
|
938 SmfTrackInfo track; |
|
939 |
|
940 QVariantMap map3 = iter.next().toMap(); |
|
941 qDebug()<<"track title = "<<map3["title"].toString(); |
|
942 |
|
943 // Set the track's Id - last.fm's identifier |
|
944 track.setId(map3["identifier"].toString()); |
|
945 |
|
946 // Set the track title |
|
947 track.setTitle(map3["title"].toString()); |
|
948 |
|
949 // Set the tracks album |
|
950 SmfAlbum album; |
|
951 album.setName(map3["album"].toString()); |
|
952 track.setAlbum(album); |
|
953 |
|
954 // Set the tracks artist details |
|
955 SmfArtists artists; |
|
956 QStringList namesList; |
|
957 namesList.append(map3["creator"].toString()); |
|
958 artists.setNames(namesList); |
|
959 |
|
960 QUrl url(map3["info"].toString()); |
|
961 artists.setUrl(url); |
|
962 |
|
963 //QUrl imageUrl(map3["image"].toString()); |
|
964 //artists.setImageUrl(imageUrl); |
|
965 |
|
966 track.setArtists(artists); |
|
967 |
|
968 // Set the tracks duration in seconds |
|
969 int timeValInSec = map3["duration"].toInt(); |
|
970 timeValInSec /= 1000; |
|
971 QTime time = QTime::fromString(QString::number(timeValInSec), "z"); |
|
972 track.setDuration(time); |
|
973 |
|
974 list.append(track); |
|
975 |
|
976 if(gItemsPerPage == list.count()) |
|
977 break; |
|
978 } |
|
979 } |
|
980 |
|
981 if(errStr.size()) |
|
982 { |
|
983 qDebug()<<"Response error found = "<<errStr; |
|
984 error = SmfPluginErrInvalidRequest; |
|
985 aRetType = SmfRequestError; |
|
986 aResult->setValue(errStr); |
|
987 } |
|
988 else |
|
989 { |
|
990 qDebug()<<"list count = "<<list.count(); |
|
991 aResult->setValue(list); |
|
992 aRetType = SmfRequestComplete; |
|
993 error = SmfPluginErrNone; |
|
994 } |
|
995 } |
|
996 } |
|
997 else if(SmfMusicGetStores == aOperation) |
|
998 { |
|
999 qDebug()<<"Response for music search get stores"; |
|
1000 |
|
1001 QList<SmfProvider> list; |
|
1002 QString errStr; |
|
1003 errStr.clear(); |
|
1004 |
|
1005 bool ok; |
|
1006 SmfPluginUtil util; |
|
1007 QVariantMap result = util.parse(response, &ok).toMap(); |
|
1008 if (!ok) |
|
1009 { |
|
1010 qDebug()<<"An error occurred during json parsing"; |
|
1011 aRetType = SmfRequestError; |
|
1012 return SmfPluginErrParsingFailed; |
|
1013 } |
|
1014 |
|
1015 qDebug()<<"Json parsing complete"; |
|
1016 |
|
1017 if(response.contains(QByteArray("error"))) |
|
1018 { |
|
1019 errStr.append(result["message"].toString()); |
|
1020 } |
|
1021 else |
|
1022 { |
|
1023 QVariantMap map1 = result["affiliations"].toMap(); |
|
1024 QVariantMap map2 = map1["physicals"].toMap(); |
|
1025 QList<QVariant> list1 = map2["affiliation"].toList(); |
|
1026 QListIterator<QVariant> iter(list1); |
|
1027 while(iter.hasNext()) |
|
1028 { |
|
1029 SmfProvider provider; |
|
1030 |
|
1031 QVariantMap map3 = iter.next().toMap(); |
|
1032 qDebug()<<"provider name = "<<map3["supplierName"].toString(); |
|
1033 qDebug()<<"provider URL = "<<map3["buyLink"].toString(); |
|
1034 |
|
1035 // Set the provider name |
|
1036 QString str(map3["supplierName"].toString()); |
|
1037 provider.setServiceName(str); |
|
1038 |
|
1039 // Set the provider url |
|
1040 QUrl url(map3["buyLink"].toString()); |
|
1041 provider.setServiceUrl(url); |
|
1042 |
|
1043 // Set the provider icon |
|
1044 //QUrl url(map3["supplierIcon"].toString()); |
|
1045 //provider.setServiceIcon(url); |
|
1046 |
|
1047 list.append(provider); |
|
1048 if(gItemsPerPage == list.count()) |
|
1049 break; |
|
1050 } |
|
1051 } |
|
1052 |
|
1053 if(errStr.size()) |
|
1054 { |
|
1055 qDebug()<<"Response error found = "<<errStr; |
|
1056 error = SmfPluginErrInvalidRequest; |
|
1057 aRetType = SmfRequestError; |
|
1058 aResult->setValue(errStr); |
|
1059 } |
|
1060 else |
|
1061 { |
|
1062 qDebug()<<"list count = "<<list.count(); |
|
1063 aResult->setValue(list); |
|
1064 aRetType = SmfRequestComplete; |
|
1065 error = SmfPluginErrNone; |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 else if (SmfMusicGetTrackInfo == aOperation) |
|
1070 { |
|
1071 qDebug()<<"Response for music search get fingerprint tracks"; |
|
1072 |
|
1073 QList<SmfTrackInfo> list; |
|
1074 QString errStr; |
|
1075 errStr.clear(); |
|
1076 |
|
1077 bool ok; |
|
1078 SmfPluginUtil util; |
|
1079 QVariantMap result = util.parse(response, &ok).toMap(); |
|
1080 if (!ok) |
|
1081 { |
|
1082 qDebug()<<"An error occurred during json parsing"; |
|
1083 aRetType = SmfRequestError; |
|
1084 return SmfPluginErrParsingFailed; |
|
1085 } |
|
1086 |
|
1087 qDebug()<<"Json parsing complete"; |
|
1088 |
|
1089 if(response.contains(QByteArray("error"))) |
|
1090 { |
|
1091 errStr.append(result["message"].toString()); |
|
1092 } |
|
1093 else |
|
1094 { |
|
1095 QVariantMap map1 = result["tracks"].toMap(); |
|
1096 QList<QVariant> list1 = map1["track"].toList(); |
|
1097 QListIterator<QVariant> iter(list1); |
|
1098 while(iter.hasNext()) |
|
1099 { |
|
1100 SmfTrackInfo track; |
|
1101 |
|
1102 QVariantMap map3 = iter.next().toMap(); |
|
1103 |
|
1104 // Set the track's Id - last.fm's identifier |
|
1105 track.setId(map3["mbid"].toString()); |
|
1106 |
|
1107 // Set the track title |
|
1108 track.setTitle(map3["name"].toString()); |
|
1109 |
|
1110 // Set the tracks artist details |
|
1111 QVariantMap map4 = map3["artist"].toMap(); |
|
1112 SmfArtists artists; |
|
1113 QStringList namesList; |
|
1114 namesList.append(map4["name"].toString()); |
|
1115 artists.setNames(namesList); |
|
1116 |
|
1117 QUrl url(map4["url"].toString()); |
|
1118 artists.setUrl(url); |
|
1119 |
|
1120 artists.setId(map4["mbid"].toString()); |
|
1121 |
|
1122 QList<QVariant> list2 = map4["image"].toList(); |
|
1123 QListIterator<QVariant> iter2(list2); |
|
1124 while(iter2.hasNext()) |
|
1125 { |
|
1126 QVariantMap map5 = iter2.next().toMap(); |
|
1127 QUrl imageUrl(map5["#text"].toString()); |
|
1128 //artists.setImageUrl(imageUrl); |
|
1129 break; |
|
1130 } |
|
1131 |
|
1132 track.setArtists(artists); |
|
1133 |
|
1134 list.append(track); |
|
1135 |
|
1136 if(gItemsPerPage == list.count()) |
|
1137 break; |
|
1138 } |
|
1139 } |
|
1140 |
|
1141 if(errStr.size()) |
|
1142 { |
|
1143 qDebug()<<"Response error found = "<<errStr; |
|
1144 error = SmfPluginErrInvalidRequest; |
|
1145 aRetType = SmfRequestError; |
|
1146 aResult->setValue(errStr); |
|
1147 } |
|
1148 else |
|
1149 { |
|
1150 qDebug()<<"list count = "<<list.count(); |
|
1151 aResult->setValue(list); |
|
1152 aRetType = SmfRequestComplete; |
|
1153 error = SmfPluginErrNone; |
|
1154 } |
|
1155 } |
|
1156 |
|
1157 else if (SmfMusicSearchCustomRequest == aOperation) |
|
1158 { |
|
1159 qDebug()<<"Response for music search custom request = album.search"; |
|
1160 |
|
1161 QList<SmfAlbum> list; |
|
1162 QString errStr; |
|
1163 errStr.clear(); |
|
1164 |
|
1165 bool ok; |
|
1166 SmfPluginUtil util; |
|
1167 QVariantMap result = util.parse(response, &ok).toMap(); |
|
1168 if (!ok) |
|
1169 { |
|
1170 qDebug()<<"An error occurred during json parsing"; |
|
1171 aRetType = SmfRequestError; |
|
1172 return SmfPluginErrParsingFailed; |
|
1173 } |
|
1174 |
|
1175 qDebug()<<"Json parsing complete"; |
|
1176 |
|
1177 if(response.contains(QByteArray("error"))) |
|
1178 { |
|
1179 errStr.append(result["message"].toString()); |
|
1180 } |
|
1181 else |
|
1182 { |
|
1183 QVariantMap map1 = result["results"].toMap(); |
|
1184 QVariantMap map2 = map1["albummatches"].toMap(); |
|
1185 QList<QVariant> list1 = map2["album"].toList(); |
|
1186 QListIterator<QVariant> iter(list1); |
|
1187 while(iter.hasNext()) |
|
1188 { |
|
1189 SmfAlbum album; |
|
1190 |
|
1191 QVariantMap map3 = iter.next().toMap(); |
|
1192 |
|
1193 album.setName(map3["name"].toString()); |
|
1194 |
|
1195 SmfArtists artists; |
|
1196 QStringList names; |
|
1197 names.append(map3["artist"].toString()); |
|
1198 artists.setNames(names); |
|
1199 |
|
1200 QList<QVariant> list2 = map3["image"].toList(); |
|
1201 QListIterator<QVariant> iter2(list2); |
|
1202 while(iter2.hasNext()) |
|
1203 { |
|
1204 QVariantMap map5 = iter2.next().toMap(); |
|
1205 QUrl imageUrl(map5["#text"].toString()); |
|
1206 //artists.setImageUrl(imageUrl); |
|
1207 break; |
|
1208 } |
|
1209 |
|
1210 album.setArtists(artists); |
|
1211 |
|
1212 album.setId(map3["id"].toString()); |
|
1213 |
|
1214 //QUrl url(map3["url"].toString()) |
|
1215 //album.setUrl(url); |
|
1216 |
|
1217 list.append(album); |
|
1218 |
|
1219 if(gItemsPerPage == list.count()) |
|
1220 break; |
|
1221 } |
|
1222 } |
|
1223 |
|
1224 if(errStr.size()) |
|
1225 { |
|
1226 qDebug()<<"Response error found = "<<errStr; |
|
1227 error = SmfPluginErrInvalidRequest; |
|
1228 aRetType = SmfRequestError; |
|
1229 aResult->setValue(errStr); |
|
1230 } |
|
1231 else |
|
1232 { |
|
1233 QByteArray customResponseData; |
|
1234 QByteArray entireData; |
|
1235 QDataStream writeResponse(&customResponseData, QIODevice::WriteOnly); |
|
1236 qDebug()<<"list count = "<<list.count(); |
|
1237 writeResponse<<list; |
|
1238 |
|
1239 QDataStream writeFull(&entireData, QIODevice::WriteOnly); |
|
1240 qDebug()<<"operation id = "<<gOperationId; |
|
1241 writeFull<<gOperationId; |
|
1242 qDebug()<<"custom Data size = "<<customResponseData.size(); |
|
1243 writeFull<<customResponseData; |
|
1244 |
|
1245 aResult->setValue(entireData); |
|
1246 aRetType = SmfRequestComplete; |
|
1247 error = SmfPluginErrNone; |
|
1248 } |
|
1249 } |
|
1250 |
|
1251 else |
|
1252 { |
|
1253 qDebug()<<"Service unsupported!!! ="<<aOperation; |
|
1254 aRetType = SmfRequestError; |
|
1255 error = SmfPluginErrServiceNotSupported; |
|
1256 } |
|
1257 } |
|
1258 |
|
1259 else if(SmfTransportOpOperationCanceledError == aTransportResult) |
|
1260 { |
|
1261 qDebug()<<"Operation Cancelled !!!"; |
|
1262 error = SmfPluginErrCancelComplete; |
|
1263 aRetType = SmfRequestComplete; |
|
1264 } |
|
1265 |
|
1266 else |
|
1267 { |
|
1268 qDebug()<<"Transport Error !!!"; |
|
1269 error = SmfPluginErrNetworkError; |
|
1270 aRetType = SmfRequestError; |
|
1271 } |
|
1272 |
|
1273 return error; |
|
1274 } |
|
1275 |
|
1276 |
|
1277 |
|
1278 /** |
|
1279 * Destructor |
|
1280 */ |
|
1281 LastFmMusicSearchProviderBase::~LastFmMusicSearchProviderBase( ) |
|
1282 { |
|
1283 } |
|
1284 |
|
1285 |
|
1286 /** |
|
1287 * Method to get the Localisable name of the service. |
|
1288 * @return The Localisable name of the service. |
|
1289 */ |
|
1290 QString LastFmMusicSearchProviderBase::serviceName( ) const |
|
1291 { |
|
1292 return m_serviceName; |
|
1293 } |
|
1294 |
|
1295 |
|
1296 /** |
|
1297 * Method to get the Logo of the service |
|
1298 * @return The Logo of the service |
|
1299 */ |
|
1300 QImage LastFmMusicSearchProviderBase::serviceIcon( ) const |
|
1301 { |
|
1302 return m_serviceIcon; |
|
1303 } |
|
1304 |
|
1305 |
|
1306 /** |
|
1307 * Method to get the Readable service description |
|
1308 * @return The Readable service description |
|
1309 */ |
|
1310 QString LastFmMusicSearchProviderBase::description( ) const |
|
1311 { |
|
1312 return m_description; |
|
1313 } |
|
1314 |
|
1315 |
|
1316 /** |
|
1317 * Method to get the Website of the service |
|
1318 * @return The Website of the service |
|
1319 */ |
|
1320 QUrl LastFmMusicSearchProviderBase::serviceUrl( ) const |
|
1321 { |
|
1322 return m_serviceUrl; |
|
1323 } |
|
1324 |
|
1325 |
|
1326 /** |
|
1327 * Method to get the URL of the Application providing this service |
|
1328 * @return The URL of the Application providing this service |
|
1329 */ |
|
1330 QUrl LastFmMusicSearchProviderBase::applicationUrl( ) const |
|
1331 { |
|
1332 return m_applicationUrl; |
|
1333 } |
|
1334 |
|
1335 |
|
1336 /** |
|
1337 * Method to get the Icon of the application |
|
1338 * @return The Icon of the application |
|
1339 */ |
|
1340 QImage LastFmMusicSearchProviderBase::applicationIcon( ) const |
|
1341 { |
|
1342 return m_applicationIcon; |
|
1343 } |
|
1344 |
|
1345 /** |
|
1346 * Method to get the list of interfaces that this provider support |
|
1347 * @return List of supported Interafces |
|
1348 */ |
|
1349 QList<QString> LastFmMusicSearchProviderBase::supportedInterfaces( ) const |
|
1350 { |
|
1351 return m_supportedInterfaces; |
|
1352 } |
|
1353 |
|
1354 /** |
|
1355 * Method to get the list of languages supported by this service provider |
|
1356 * @return a QStringList of languages supported by this service |
|
1357 * provider in 2 letter ISO 639-1 format. |
|
1358 */ |
|
1359 QStringList LastFmMusicSearchProviderBase::supportedLanguages( ) const |
|
1360 { |
|
1361 return m_supportedLangs; |
|
1362 } |
|
1363 |
|
1364 /** |
|
1365 * Method to get the Plugin specific ID |
|
1366 * @return The Plugin specific ID |
|
1367 */ |
|
1368 QString LastFmMusicSearchProviderBase::pluginId( ) const |
|
1369 { |
|
1370 return m_pluginId; |
|
1371 } |
|
1372 |
|
1373 |
|
1374 /** |
|
1375 * Method to get the ID of the authentication application |
|
1376 * for this service |
|
1377 * @param aProgram The authentication application name |
|
1378 * @param aArguments List of arguments required for authentication app |
|
1379 * @param aMode Strting mode for authentication application |
|
1380 * @return The ID of the authentication application |
|
1381 */ |
|
1382 QString LastFmMusicSearchProviderBase::authenticationApp( QString &aProgram, |
|
1383 QStringList & aArguments, |
|
1384 QIODevice::OpenModeFlag aMode ) const |
|
1385 { |
|
1386 Q_UNUSED(aProgram) |
|
1387 Q_UNUSED(aArguments) |
|
1388 Q_UNUSED(aMode) |
|
1389 return m_authAppId; |
|
1390 } |
|
1391 |
|
1392 |
|
1393 /** |
|
1394 * Method to get the unique registration ID provided by the |
|
1395 * Smf for authorised plugins |
|
1396 * @return The unique registration ID/token provided by the Smf for |
|
1397 * authorised plugins |
|
1398 */ |
|
1399 QString LastFmMusicSearchProviderBase::smfRegistrationId( ) const |
|
1400 { |
|
1401 return m_smfRegToken; |
|
1402 } |
|
1403 |
|
1404 |
|
1405 /** |
|
1406 * Method that initializes this class. This method should be called |
|
1407 * from the initialize() method of the FBContactFetcherPlugin class |
|
1408 */ |
|
1409 void LastFmMusicSearchProviderBase::initialize() |
|
1410 { |
|
1411 m_serviceName = "last.fm"; |
|
1412 m_description = "Last.fm music search plugin description"; |
|
1413 m_serviceUrl = QUrl(QString("http://www.last.fm")); |
|
1414 m_pluginId = "lastfmmusicsearchplugin.qtplugin"; |
|
1415 m_authAppId = "0x12345678"; |
|
1416 m_supportedInterfaces.append("org.symbian.smf.plugin.music.search/v0.2"); |
|
1417 QSettings iSettings; |
|
1418 m_smfRegToken = iSettings.value("LastFmRegToken").toString(); |
|
1419 m_validity = iSettings.value("LastFmExpiryTime").toDateTime(); |
|
1420 } |
|
1421 |
|
1422 |
|
1423 /* |
|
1424 * Export Macro |
|
1425 * plugin name : lastfmmusicsearchplugin |
|
1426 * plugin class : LastFmMusicSearchPlugin |
|
1427 */ |
|
1428 Q_EXPORT_PLUGIN2( lastfmmusicsearchplugin, LastFmMusicSearchPlugin ) |