From db83c411c27a91ddaabb283c3fd44dbb0c9b4530 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Fri, 6 Jan 2012 16:31:29 +0000 Subject: [PATCH] * Use Chromaprinter instead of OFA fingerprinter. * Send fingerprint to Acoustid instead of MusicDNS. * Retrieve MBID instead of PUID and send to Musicbrainz. --- src/musicbrainz/chromaprinter.cpp | 2 - src/musicbrainz/musicbrainzclient.cpp | 6 +-- src/musicbrainz/musicbrainzclient.h | 8 ++-- src/musicbrainz/musicdnsclient.cpp | 63 ++++++++++++++++----------- src/musicbrainz/musicdnsclient.h | 6 +-- src/musicbrainz/tagfetcher.cpp | 7 +-- 6 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/musicbrainz/chromaprinter.cpp b/src/musicbrainz/chromaprinter.cpp index aadfce9b1..b040295f4 100644 --- a/src/musicbrainz/chromaprinter.cpp +++ b/src/musicbrainz/chromaprinter.cpp @@ -142,8 +142,6 @@ QString Chromaprinter::CreateFingerprint() { qLog(Debug) << "Decode time:" << decode_time << "Codegen time:" << codegen_time; - qLog(Debug) << "Chromaprint:" << fingerprint; - // Cleanup gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), NULL, NULL); g_source_remove(bus_callback_id); diff --git a/src/musicbrainz/musicbrainzclient.cpp b/src/musicbrainz/musicbrainzclient.cpp index d8a847b67..e4bf58276 100644 --- a/src/musicbrainz/musicbrainzclient.cpp +++ b/src/musicbrainz/musicbrainzclient.cpp @@ -35,14 +35,14 @@ MusicBrainzClient::MusicBrainzClient(QObject* parent) { } -void MusicBrainzClient::Start(int id, const QString& puid) { +void MusicBrainzClient::Start(int id, const QString& mbid) { typedef QPair Param; QList parameters; parameters << Param("type", "xml") - << Param("puid", puid); + << Param("inc", "artist+releases"); - QUrl url(kTrackUrl); + QUrl url(kTrackUrl + mbid); url.setQueryItems(parameters); QNetworkRequest req(url); diff --git a/src/musicbrainz/musicbrainzclient.h b/src/musicbrainz/musicbrainzclient.h index 25bda0c7e..21c59bfa4 100644 --- a/src/musicbrainz/musicbrainzclient.h +++ b/src/musicbrainz/musicbrainzclient.h @@ -30,8 +30,8 @@ class QNetworkReply; class MusicBrainzClient : public QObject { Q_OBJECT - // Gets metadata for a particular PUID. - // A PUID is created from a fingerprint using MusicDnsClient. + // Gets metadata for a particular MBID. + // An MBID is created from a fingerprint using MusicDnsClient. // You can create one MusicBrainzClient and make multiple requests using it. // IDs are provided by the caller when a request is started and included in // the Finished signal - they have no meaning to MusicBrainzClient. @@ -52,8 +52,8 @@ public: // Starts a request and returns immediately. Finished() will be emitted // later with the same ID. - void Start(int id, const QString& puid); - void StartDiscIdRequest(const QString& puid); + void Start(int id, const QString& mbid); + void StartDiscIdRequest(const QString& discid); // Cancels the request with the given ID. Finished() will never be emitted // for that ID. Does nothing if there is no request with the given ID. diff --git a/src/musicbrainz/musicdnsclient.cpp b/src/musicbrainz/musicdnsclient.cpp index bd777d86e..c09b773d1 100644 --- a/src/musicbrainz/musicdnsclient.cpp +++ b/src/musicbrainz/musicdnsclient.cpp @@ -16,15 +16,18 @@ */ #include "musicdnsclient.h" -#include "core/network.h" #include #include -#include -#include -const char* MusicDnsClient::kClientId = "c44f70e49000dd7c0d1388bff2bf4152"; -const char* MusicDnsClient::kUrl = "http://ofa.musicdns.org/ofa/1/track"; +#include + +#include "core/logging.h" +#include "core/network.h" +#include "core/timeconstants.h" + +const char* MusicDnsClient::kClientId = "qsZGpeLx"; +const char* MusicDnsClient::kUrl = "http://api.acoustid.org/v2/lookup"; const int MusicDnsClient::kDefaultTimeout = 5000; // msec MusicDnsClient::MusicDnsClient(QObject* parent) @@ -42,20 +45,11 @@ void MusicDnsClient::Start(int id, const QString& fingerprint, int duration_msec typedef QPair Param; QList parameters; - parameters << Param("alb", "unknown") - << Param("art", "unknown") - << Param("brt", "0") - << Param("cid", kClientId) - << Param("cvr", QString("%1 %2").arg(QCoreApplication::applicationName(), - QCoreApplication::applicationVersion())) - << Param("dur", QString::number(duration_msec)) - << Param("fmt", "unknown") - << Param("fpt", fingerprint) - << Param("gnr", "unknown") - << Param("rmd", "1") - << Param("tnm", "0") - << Param("ttl", "unknown") - << Param("yrr", "0"); + parameters << Param("format", "json") + << Param("client", kClientId) + << Param("duration", QString::number(duration_msec / kMsecPerSec)) + << Param("meta", "recordingids") + << Param("fingerprint", fingerprint); QUrl url(kUrl); url.setQueryItems(parameters); @@ -95,12 +89,31 @@ void MusicDnsClient::RequestFinished() { return; } - QXmlStreamReader reader(reply); - while (!reader.atEnd()) { - if (reader.readNext() == QXmlStreamReader::StartElement && reader.name() == "puid") { - QString puid = reader.attributes().value("id").toString(); - emit Finished(id, puid); - return; + QJson::Parser parser; + bool ok = false; + QVariantMap result = parser.parse(reply, &ok).toMap(); + if (!ok) { + emit Finished(id, QString()); + return; + } + + QString status = result["status"].toString(); + if (status != "ok") { + emit Finished(id, QString()); + return; + } + QVariantList results = result["results"].toList(); + foreach (const QVariant& v, results) { + QVariantMap r = v.toMap(); + if (r.contains("recordings")) { + QVariantList recordings = r["recordings"].toList(); + foreach (const QVariant& recording, recordings) { + QVariantMap o = recording.toMap(); + if (o.contains("id")) { + emit Finished(id, o["id"].toString()); + return; + } + } } } diff --git a/src/musicbrainz/musicdnsclient.h b/src/musicbrainz/musicdnsclient.h index 0e79280b6..0d92db9c9 100644 --- a/src/musicbrainz/musicdnsclient.h +++ b/src/musicbrainz/musicdnsclient.h @@ -29,9 +29,9 @@ class QNetworkReply; class MusicDnsClient : public QObject { Q_OBJECT - // Gets a PUID from an OFA fingerprint. + // Gets a MBID from a Chromaprint fingerprint. // A fingerprint identifies one particular encoding of a song and is created - // by Fingerprinter. A PUID identifies the actual song and can be passed to + // by Fingerprinter. An MBID identifies the actual song and can be passed to // Musicbrainz to get metadata. // You can create one MusicDnsClient and make multiple requests using it. // IDs are provided by the caller when a request is started and included in @@ -56,7 +56,7 @@ public: void CancelAll(); signals: - void Finished(int id, const QString& puid); + void Finished(int id, const QString& mbid); private slots: void RequestFinished(); diff --git a/src/musicbrainz/tagfetcher.cpp b/src/musicbrainz/tagfetcher.cpp index 30f7740fb..a87d2b398 100644 --- a/src/musicbrainz/tagfetcher.cpp +++ b/src/musicbrainz/tagfetcher.cpp @@ -15,10 +15,11 @@ along with Clementine. If not, see . */ -#include "fingerprinter.h" +#include "tagfetcher.h" + +#include "chromaprinter.h" #include "musicbrainzclient.h" #include "musicdnsclient.h" -#include "tagfetcher.h" #include "core/timeconstants.h" #include @@ -37,7 +38,7 @@ TagFetcher::TagFetcher(QObject* parent) } QString TagFetcher::GetFingerprint(const Song& song) { - return Fingerprinter(song.url().toLocalFile()).CreateFingerprint(); + return Chromaprinter(song.url().toLocalFile()).CreateFingerprint(); } void TagFetcher::StartFetch(const SongList& songs) {