Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed Oct 25, 2024
1 parent f2ba600 commit e591fa0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
36 changes: 24 additions & 12 deletions src/integrations/metadatapushmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>

#include "mixer/basetrackplayer.h"
#include "mixer/playermanager.h"
Expand Down Expand Up @@ -43,32 +44,42 @@ bool MetadataPushManager::isEnabled() {

void MetadataPushManager::slotPlayStateChanged(double v) {
Q_UNUSED(v);
auto playingTracks = getPlayingTracks();
auto body = buildJson(playingTracks);
auto host = qgetenv("METADATA_PUSH_HOST");
auto request = QNetworkRequest(QUrl(QStringLiteral("http://%1/now-playing/update").arg(host)));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
m_pNetworkAccessManager->post(request, body);
if (isEnabled()) {
auto playingTracks = getPlayingTracks();
auto body = buildJson(playingTracks);
auto host = qgetenv("METADATA_PUSH_HOST");
auto request = QNetworkRequest(QUrl(QStringLiteral("%1/now-playing/update").arg(host)));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
auto pReply = m_pNetworkAccessManager->post(request, body);

Check warning on line 53 in src/integrations/metadatapushmanager.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto pReply' can be declared as 'auto *pReply' [readability-qualified-auto]
connect(pReply,
&QNetworkReply::finished,
this,
[pReply] {
pReply->deleteLater();
});
}
}

QList<TrackPointer> MetadataPushManager::getPlayingTracks() {
QList<TrackPointer> tracks;
QList<QPair<bool, TrackPointer>> MetadataPushManager::getPlayingTracks() {
QList<QPair<bool, TrackPointer>> tracks;
for (unsigned int i = 0; i < m_pPlayerManager->numberOfDecks(); ++i) {
QString group = PlayerManager::groupForDeck(i);
BaseTrackPlayer* pPlayer = m_pPlayerManager->getPlayer(group);
TrackPointer pTrack = pPlayer->getLoadedTrack();
if (pTrack) {
tracks.append(pTrack);
tracks.append(QPair<bool, TrackPointer>(m_decks[i]->toBool(), pTrack));
}
}
return tracks;
}

QByteArray MetadataPushManager::buildJson(QList<TrackPointer> playingTracks) {
QByteArray MetadataPushManager::buildJson(QList<QPair<bool, TrackPointer>> playingTracks) {
QJsonArray tracks;

for (auto trackPointer : playingTracks) {
for (auto info : playingTracks) {
auto trackPointer = info.second;
QJsonObject track{
{"is_playing", info.first},
{"title", trackPointer->getTitle()},
{"artist", trackPointer->getArtist()},
{"album", trackPointer->getAlbum()},
Expand All @@ -77,7 +88,8 @@ QByteArray MetadataPushManager::buildJson(QList<TrackPointer> playingTracks) {
{"comment", trackPointer->getComment()},
{"year", trackPointer->getYear()},
{"location", trackPointer->getLocation()},
{"url", trackPointer->getURL()}};
{"url", trackPointer->getURL()},
{"bpm", trackPointer->getBpm()}};
tracks.append(track);
}

Expand Down
5 changes: 3 additions & 2 deletions src/integrations/metadatapushmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QList>
#include <QObject>
#include <QPair>
#include <memory>

#include "control/controlproxy.h"
Expand Down Expand Up @@ -31,8 +32,8 @@ class MetadataPushManager : public QObject {
void slotPlayStateChanged(double v);

private:
QList<TrackPointer> getPlayingTracks();
QByteArray buildJson(QList<TrackPointer> playingTracks);
QList<QPair<bool, TrackPointer>> getPlayingTracks();
QByteArray buildJson(QList<QPair<bool, TrackPointer>> playingTracks);

private:
UserSettingsPointer m_pConfig;
Expand Down

0 comments on commit e591fa0

Please sign in to comment.