1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 12:02:48 +01:00

* Use Chromaprinter instead of OFA fingerprinter.

* Send fingerprint to Acoustid instead of MusicDNS.
* Retrieve MBID instead of PUID and send to Musicbrainz.
This commit is contained in:
John Maguire 2012-01-06 16:31:29 +00:00
parent 423295b01e
commit db83c411c2
6 changed files with 52 additions and 40 deletions

View File

@ -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);

View File

@ -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<QString, QString> Param;
QList<Param> 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);

View File

@ -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.

View File

@ -16,15 +16,18 @@
*/
#include "musicdnsclient.h"
#include "core/network.h"
#include <QCoreApplication>
#include <QNetworkReply>
#include <QXmlStreamReader>
#include <QtDebug>
const char* MusicDnsClient::kClientId = "c44f70e49000dd7c0d1388bff2bf4152";
const char* MusicDnsClient::kUrl = "http://ofa.musicdns.org/ofa/1/track";
#include <qjson/parser.h>
#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<QString, QString> Param;
QList<Param> 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;
}
}
}
}

View File

@ -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();

View File

@ -15,10 +15,11 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "fingerprinter.h"
#include "tagfetcher.h"
#include "chromaprinter.h"
#include "musicbrainzclient.h"
#include "musicdnsclient.h"
#include "tagfetcher.h"
#include "core/timeconstants.h"
#include <QFuture>
@ -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) {