Skip to content
This repository has been archived by the owner on Jul 14, 2019. It is now read-only.
/ Miam-Player Public archive

Commit

Permalink
Make AcoustId great again
Browse files Browse the repository at this point in the history
  • Loading branch information
MBach committed Feb 3, 2017
1 parent 1b50f3f commit 84d6911
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 34 deletions.
58 changes: 27 additions & 31 deletions src/acoustid/acoustid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,34 @@ AcoustId::~AcoustId()
});
}*/

void AcoustId::start()
void AcoustId::start(const QList<QUrl> &tracks)
{
/*if (!_selectedTracksModel->selectedTracks().isEmpty()) {
_stackedWidget->setVisible(true);
QString appName = QCoreApplication::instance()->applicationName();
QString appVersion = QCoreApplication::instance()->applicationVersion();
QString client = appName.append(appVersion);
for (int i = 0; i < _selectedTracksModel->selectedTracks().count(); i++) {
QString track = _selectedTracksModel->selectedTracks().at(i).toLocalFile();
if (_chromaprint->start(track)) {
QString fingerprint = _chromaprint->fingerprint();
if (!fingerprint.isEmpty()) {
QUrlQuery urlQuery;
urlQuery.addQueryItem("format", "json");
urlQuery.addQueryItem("client", AcoustId::_apiKey);
urlQuery.addQueryItem("duration", QString::number(_chromaprint->duration()));
urlQuery.addQueryItem("meta", "recordings+releasegroups+releases+tracks");
//qDebug() << fingerprint;
urlQuery.addQueryItem("fingerprint", fingerprint);
QNetworkRequest request(QUrl::fromEncoded(_wsAcoustID.toLatin1()));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
//request.setRawHeader("Content-Encoding", "gzip");
request.setRawHeader("User-Agent", client.toLatin1());
_requestPool->add(track, request, urlQuery, _chromaprint->duration());
}
QString appName = QCoreApplication::instance()->applicationName();
QString appVersion = QCoreApplication::instance()->applicationVersion();
QString client = appName.append(appVersion);

for (int i = 0; i < tracks.count(); i++) {
QString track = tracks.at(i).toLocalFile();
if (_chromaprint->start(track)) {

QString fingerprint = _chromaprint->fingerprint();
if (!fingerprint.isEmpty()) {

QUrlQuery urlQuery;
urlQuery.addQueryItem("format", "json");
urlQuery.addQueryItem("client", AcoustId::_apiKey);
urlQuery.addQueryItem("duration", QString::number(_chromaprint->duration()));
urlQuery.addQueryItem("meta", "recordings+releasegroups+releases+tracks");
//qDebug() << fingerprint;
urlQuery.addQueryItem("fingerprint", fingerprint);

QNetworkRequest request(QUrl::fromEncoded(_wsAcoustID.toLatin1()));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
//request.setRawHeader("Content-Encoding", "gzip");
request.setRawHeader("User-Agent", client.toLatin1());

_requestPool->add(track, request, urlQuery, _chromaprint->duration());
}
}
}*/
}
}
2 changes: 1 addition & 1 deletion src/acoustid/acoustid.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MIAMACOUSTID_LIBRARY AcoustId : public QObject

virtual ~AcoustId();

void start();
void start(const QList<QUrl> &tracks);

signals:
void releaseFound(const MusicBrainz::Release &);
Expand Down
4 changes: 4 additions & 0 deletions src/acoustid/qchromaprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ QString QChromaprint::fingerprint() const
int r = chromaprint_get_fingerprint(_ctx, &fp);
if (r == 1) {
QString s(fp);
qDebug() << Q_FUNC_INFO << "decoded fingerprint" << s;
return s;
} else {
return QString();
Expand Down Expand Up @@ -174,6 +175,9 @@ int QChromaprint::processFile(const QString &file)
ao->play(QByteArray::fromRawData(data.constData(), qMin(data.size(), ao->bufferSize())));
data.remove(0, qMin(data.size(), ao->bufferSize()));
}*/
/*if (!chromaprint_feed(_ctx, frame_data, first_part_size * frame.samplesPerChannel())) {
qDebug() << "ERROR: Could not process audio data";
}*/
}


Expand Down
1 change: 1 addition & 0 deletions src/acoustid/requestpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void RequestPool::add(const QString &track, const QNetworkRequest &request, cons
_timer->start(1000);
}
} else {
qDebug() << Q_FUNC_INFO << track << urlQuery.query() << trackDuration;
QNetworkReply* reply = _nam.post(request, urlQuery.query(QUrl::FullyEncoded).toUtf8());
reply->setProperty("duration", trackDuration);
reply->setProperty("track", track);
Expand Down
2 changes: 1 addition & 1 deletion src/acoustid/requestpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MIAMACOUSTID_LIBRARY RequestPool : public QObject
QMap<QString, QNetworkReply*> _map;

/**
* \brief The Triplet class is a nested class to manipulate queries easily.
* \brief The Quadruplet class is a nested class to manipulate queries easily.
*/
class Quadruplet
{
Expand Down
10 changes: 9 additions & 1 deletion src/tageditor/tageditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TagEditor::TagEditor(QWidget *parent)
combo->setProperty("column", _combos.key(combo));
}

connect(analyzePushButton, &QPushButton::clicked, _acoustId, &AcoustId::start);
connect(analyzePushButton, &QPushButton::clicked, this, &TagEditor::autoFetchTags);
connect(saveChangesButton, &QPushButton::clicked, this, &TagEditor::commitChanges);
connect(cancelButton, &QPushButton::clicked, this, &TagEditor::rollbackChanges);

Expand Down Expand Up @@ -323,6 +323,14 @@ void TagEditor::applyCoverToAll(bool isForAll, Cover *cover)
cancelButton->setEnabled(true);
}

void TagEditor::autoFetchTags()
{
if (!selectedTracks().isEmpty()) {
//_stackedWidget->setVisible(true);
_acoustId->start(selectedTracks());
}
}

/** Saves all fields in the media. */
void TagEditor::commitChanges()
{
Expand Down
2 changes: 2 additions & 0 deletions src/tageditor/tageditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public slots:
private slots:
void applyCoverToAll(bool isForAll, Cover *cover);

void autoFetchTags();

/** Saves all fields in the media. */
void commitChanges();

Expand Down

0 comments on commit 84d6911

Please sign in to comment.