| 1 | /* |
| 2 | Copyright 2009 Last.fm Ltd. |
| 3 | - Primarily authored by Max Howell, Jono Cole and Doug Mansell |
| 4 | |
| 5 | This file is part of liblastfm. |
| 6 | |
| 7 | liblastfm is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | liblastfm is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with liblastfm. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | #include <lastfm/Fingerprint> |
| 21 | #include <lastfm/FingerprintId> |
| 22 | #include <QtCore> |
| 23 | #include <QtNetwork> |
| 24 | |
| 25 | using namespace lastfm; |
| 26 | |
| 27 | |
| 28 | static void finish( QNetworkReply* reply ) |
| 29 | { |
| 30 | QEventLoop loop; |
| 31 | loop.connect( reply, SIGNAL(finished()), SLOT(quit()) ); |
| 32 | loop.exec(); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | int main( int argc, char** argv ) |
| 37 | { |
| 38 | QCoreApplication app( argc, argv ); |
| 39 | |
| 40 | // these fields are required |
| 41 | MutableTrack t; |
| 42 | t.setArtist( "Air" ); |
| 43 | t.setTitle( "Redhead Girl" ); |
| 44 | t.setAlbum( "Pocket Symphony" ); |
| 45 | t.setUrl( QUrl::fromLocalFile( "/Users/mxcl/Music/iTunes/iTunes Music/Air/Pocket Symphony/1-11 Redhead Girl.mp3") ); |
| 46 | |
| 47 | try |
| 48 | { |
| 49 | Fingerprint fp( t ); |
| 50 | |
| 51 | // we cache FingerprintIds in an sqlite3 db, as the generate() function |
| 52 | // is expensive |
| 53 | if (fp.id().isNull()) |
| 54 | { |
| 55 | // this generates the full fingerprint hash, which is about 20kB |
| 56 | fp.generate(); |
| 57 | |
| 58 | // this asks Last.fm for a FingerprintId |
| 59 | // the finish function is a Qt hack to allow syncronous HTTP |
| 60 | finish( fp.submit() ); |
| 61 | |
| 62 | // the decode step sets the FingerprintId |
| 63 | // the FingerprintId is required to obtain suggestions |
| 64 | // id will now be valid, or this function throws |
| 65 | fp.decode( reply ); |
| 66 | } |
| 67 | |
| 68 | finish( fp.id().getSuggestions() ); |
| 69 | |
| 70 | qDebug() << FingerprintId::getSuggestions( reply ); |
| 71 | } |
| 72 | catch (Fingerprint::Error e) |
| 73 | { |
| 74 | qWarning() << e; //TODO enum debug thing |
| 75 | } |
| 76 | } |