/thirdparty/liblastfm2/src/fingerprint/EXAMPLE.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 76 lines · 36 code · 12 blank · 28 comment · 1 complexity · e436d4331da577569d50c8d1524e83d4 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 <lastfm/Fingerprint>
  17. #include <lastfm/FingerprintId>
  18. #include <QtCore>
  19. #include <QtNetwork>
  20. using namespace lastfm;
  21. static void finish( QNetworkReply* reply )
  22. {
  23. QEventLoop loop;
  24. loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
  25. loop.exec();
  26. }
  27. int main( int argc, char** argv )
  28. {
  29. QCoreApplication app( argc, argv );
  30. // these fields are required
  31. MutableTrack t;
  32. t.setArtist( "Air" );
  33. t.setTitle( "Redhead Girl" );
  34. t.setAlbum( "Pocket Symphony" );
  35. t.setUrl( QUrl::fromLocalFile( "/Users/mxcl/Music/iTunes/iTunes Music/Air/Pocket Symphony/1-11 Redhead Girl.mp3") );
  36. try
  37. {
  38. Fingerprint fp( t );
  39. // we cache FingerprintIds in an sqlite3 db, as the generate() function
  40. // is expensive
  41. if (fp.id().isNull())
  42. {
  43. // this generates the full fingerprint hash, which is about 20kB
  44. fp.generate();
  45. // this asks Last.fm for a FingerprintId
  46. // the finish function is a Qt hack to allow syncronous HTTP
  47. finish( fp.submit() );
  48. // the decode step sets the FingerprintId
  49. // the FingerprintId is required to obtain suggestions
  50. // id will now be valid, or this function throws
  51. fp.decode( reply );
  52. }
  53. finish( fp.id().getSuggestions() );
  54. qDebug() << FingerprintId::getSuggestions( reply );
  55. }
  56. catch (Fingerprint::Error e)
  57. {
  58. qWarning() << e; //TODO enum debug thing
  59. }
  60. }