/thirdparty/liblastfm2/src/types/FingerprintId.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 55 lines · 29 code · 7 blank · 19 comment · 2 complexity · 439a0092ea1d6de5f2a68fc50a8100f8 MD5 · raw file

  1. /*
  2. Copyright 2009 Last.fm Ltd.
  3. - Primarily authored by Max Howell, Jono Cole and Doug Mansell
  4. This file is part of liblastfm.
  5. liblastfm is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. liblastfm is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "FingerprintId.h"
  17. #include "../ws/ws.h"
  18. #include <QtNetwork>
  19. #include <QtXml>
  20. QNetworkReply*
  21. lastfm::FingerprintId::getSuggestions() const
  22. {
  23. if (isNull()) return 0;
  24. QUrl const url( "http://ws.audioscrobbler.com/fingerprint/" + QString(*this) + ".xml" );
  25. QNetworkRequest const request( url );
  26. return lastfm::nam()->get( request );
  27. }
  28. QMap<float, lastfm::Track> //static
  29. lastfm::FingerprintId::getSuggestions( QNetworkReply* reply )
  30. {
  31. QDomDocument xml;
  32. xml.setContent( reply->readAll() );
  33. QDomNodeList nodes = xml.documentElement().elementsByTagName( "track" );
  34. QMap<float, Track> tracks;
  35. for (int x = 0; x < nodes.count(); ++x)
  36. {
  37. QDomElement const e = nodes.at(x).toElement();
  38. MutableTrack t;
  39. t.setTitle( e.firstChildElement( "title" ).text() );
  40. t.setArtist( e.firstChildElement( "artist" ).text() );
  41. tracks.insert( e.attribute( "confidence", "0.0" ).toFloat(), t );
  42. }
  43. return tracks;
  44. }