From 9b22bc853803a5ae1db07f66690ad7508f031da0 Mon Sep 17 00:00:00 2001 From: qblake Date: Thu, 16 Jan 2014 13:14:49 +0000 Subject: [PATCH 1/2] add json format for output --- src/fpclient/main.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/fpclient/main.cpp b/src/fpclient/main.cpp index ce301c3..71ca0f4 100644 --- a/src/fpclient/main.cpp +++ b/src/fpclient/main.cpp @@ -196,13 +196,14 @@ void getFileInfo( const string& fileName, map& urlParams, bool d // ----------------------------------------------------------------------------- -string fetchMetadata(int fpid, HTTPClient& client, bool justURL) +string fetchMetadata(int fpid, HTTPClient& client, bool justURL, bool jsonFormat) { - ostringstream oss; + ostringstream oss; oss << METADATA_SERVER_NAME << "?method=track.getfingerprintmetadata" << "&fingerprintid=" << fpid - << "&api_key=" << LASTFM_API_KEY; + << "&api_key=" << LASTFM_API_KEY + << "&format=json"; if ( justURL ) return oss.str(); @@ -230,22 +231,24 @@ int main(int argc, char* argv[]) string fileName = string(argv[0]); size_t lastSlash = fileName.find_last_of(SLASH); if ( lastSlash != string::npos ) - fileName = fileName.substr(lastSlash+1); + fileName = fileName.substr(lastSlash+1); cout << fileName << " (" << PUBLIC_CLIENT_NAME << ")\n" << "A minimal fingerprint client, public release.\n" - << "Copyright (C) 2007-2010 by Last.fm (MIR) - Build: " << __DATE__ << " (" << __TIME__ << ")\n\n" + << "Copyright (C) 2007-2014 by Last.fm (MIR) - Build: " << __DATE__ << " (" << __TIME__ << ")\n\n" << "Usage:\n" << fileName << " [options] yourMp3File.mp3\n" << "Available options:\n" << " -nometadata: will only return the id of the fingerprint\n" - << " -url: will output the url of the metadata\n"; + << " -url: will output the url of the metadata\n" + << " -json: will output in json format\n"; exit(0); } string mp3FileName; bool wantMetadata = true; bool justUrl = false; + bool jsonFormat = false; bool doTagLib = true; int forceDuration = 0; @@ -268,6 +271,8 @@ int main(int argc, char* argv[]) wantMetadata = false; else if ( arg == "-url" ) justUrl = true; + else if ( arg == "-json" ) + jsonFormat = true; else if ( arg == "-fplocation" && (i+1) < argc ) { ++i; @@ -412,7 +417,7 @@ int main(int argc, char* argv[]) string state; iss >> state; if ( state == "FOUND" ) - c = fetchMetadata(fpid, client, justUrl); + c = fetchMetadata(fpid, client, justUrl, jsonFormat); else if ( state == "NEW" ) { cout << "Was not found! Now added, thanks! :)" << endl; From 5871d709e1367d49b47037ae8f939efb11aa2fb8 Mon Sep 17 00:00:00 2001 From: qblake Date: Mon, 27 Jan 2014 12:37:15 +0000 Subject: [PATCH 2/2] fix adding jsonFormat --- src/fpclient/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fpclient/main.cpp b/src/fpclient/main.cpp index 71ca0f4..618e77d 100644 --- a/src/fpclient/main.cpp +++ b/src/fpclient/main.cpp @@ -202,8 +202,10 @@ string fetchMetadata(int fpid, HTTPClient& client, bool justURL, bool jsonFormat oss << METADATA_SERVER_NAME << "?method=track.getfingerprintmetadata" << "&fingerprintid=" << fpid - << "&api_key=" << LASTFM_API_KEY - << "&format=json"; + << "&api_key=" << LASTFM_API_KEY; + + if ( jsonFormat ) + oss << "&format=json"; if ( justURL ) return oss.str();