Add title, artist and album to MPRIS network packets
Summary: This diff adds the title, artist and album to the MPRIS network packets. That's useful when you need more detail than just "artist - title", for example in the future media control notification. It also fixes weird song descriptions for empty artist strings (e.g. Spotify uses an empty (but present) artist when playing ads) Reviewers: #kde_connect, apol Reviewed By: #kde_connect, apol Subscribers: nicolasfella, apol Differential Revision: https://phabricator.kde.org/D8957
This commit is contained in:
parent
7e7aa6df3f
commit
71d8eb07c3
2 changed files with 25 additions and 25 deletions
|
@ -129,22 +129,9 @@ void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, con
|
|||
QDBusArgument bullshit = qvariant_cast<QDBusArgument>(properties[QStringLiteral("Metadata")]);
|
||||
QVariantMap nowPlayingMap;
|
||||
bullshit >> nowPlayingMap;
|
||||
if (nowPlayingMap.contains(QStringLiteral("xesam:title"))) {
|
||||
QString nowPlaying = nowPlayingMap[QStringLiteral("xesam:title")].toString();
|
||||
if (nowPlayingMap.contains(QStringLiteral("xesam:artist"))) {
|
||||
nowPlaying = nowPlayingMap[QStringLiteral("xesam:artist")].toString() + " - " + nowPlaying;
|
||||
}
|
||||
np.set(QStringLiteral("nowPlaying"),nowPlaying);
|
||||
somethingToSend = true;
|
||||
}
|
||||
if (nowPlayingMap.contains(QStringLiteral("mpris:length"))) {
|
||||
if (nowPlayingMap.contains(QStringLiteral("mpris:length"))) {
|
||||
long long length = nowPlayingMap[QStringLiteral("mpris:length")].toLongLong();
|
||||
np.set(QStringLiteral("length"),length/1000); //milis to nanos
|
||||
}
|
||||
somethingToSend = true;
|
||||
}
|
||||
|
||||
mprisPlayerMetadataToNetworkPackage(np, nowPlayingMap);
|
||||
somethingToSend = true;
|
||||
}
|
||||
if (properties.contains(QStringLiteral("PlaybackStatus"))) {
|
||||
bool playing = (properties[QStringLiteral("PlaybackStatus")].toString() == QLatin1String("Playing"));
|
||||
|
@ -242,18 +229,9 @@ bool MprisControlPlugin::receivePackage (const NetworkPackage& np)
|
|||
NetworkPackage answer(PACKAGE_TYPE_MPRIS);
|
||||
bool somethingToSend = false;
|
||||
if (np.get<bool>(QStringLiteral("requestNowPlaying"))) {
|
||||
|
||||
QVariantMap nowPlayingMap = mprisInterface.metadata();
|
||||
QString nowPlaying = nowPlayingMap[QStringLiteral("xesam:title")].toString();
|
||||
if (nowPlayingMap.contains(QStringLiteral("xesam:artist"))) {
|
||||
nowPlaying = nowPlayingMap[QStringLiteral("xesam:artist")].toString() + " - " + nowPlaying;
|
||||
}
|
||||
answer.set(QStringLiteral("nowPlaying"),nowPlaying);
|
||||
mprisPlayerMetadataToNetworkPackage(answer, nowPlayingMap);
|
||||
|
||||
if (nowPlayingMap.contains(QStringLiteral("mpris:length"))) {
|
||||
qlonglong length = nowPlayingMap[QStringLiteral("mpris:length")].toLongLong();
|
||||
answer.set(QStringLiteral("length"),length/1000);
|
||||
}
|
||||
qlonglong pos = mprisInterface.position();
|
||||
answer.set(QStringLiteral("pos"), pos/1000);
|
||||
|
||||
|
@ -288,4 +266,25 @@ void MprisControlPlugin::sendPlayerList()
|
|||
sendPackage(np);
|
||||
}
|
||||
|
||||
void MprisControlPlugin::mprisPlayerMetadataToNetworkPackage(NetworkPackage& np, const QVariantMap& nowPlayingMap) const {
|
||||
QString title = nowPlayingMap[QStringLiteral("xesam:title")].toString();
|
||||
QString artist = nowPlayingMap[QStringLiteral("xesam:artist")].toString();
|
||||
QString album = nowPlayingMap[QStringLiteral("xesam:album")].toString();
|
||||
QString nowPlaying = title;
|
||||
if (!artist.isEmpty()) {
|
||||
nowPlaying = artist + " - " + title;
|
||||
}
|
||||
np.set(QStringLiteral("title"), title);
|
||||
np.set(QStringLiteral("artist"), artist);
|
||||
np.set(QStringLiteral("album"), album);
|
||||
np.set(QStringLiteral("nowPlaying"), nowPlaying);
|
||||
|
||||
bool hasLength = false;
|
||||
long long length = nowPlayingMap[QStringLiteral("mpris:length")].toLongLong(&hasLength) / 1000; //nanoseconds to milliseconds
|
||||
if (!hasLength) {
|
||||
length = -1;
|
||||
}
|
||||
np.set(QStringLiteral("length"), length);
|
||||
}
|
||||
|
||||
#include "mpriscontrolplugin.moc"
|
||||
|
|
|
@ -52,6 +52,7 @@ private:
|
|||
void addPlayer(const QString& ifaceName);
|
||||
void removePlayer(const QString& ifaceName);
|
||||
void sendPlayerList();
|
||||
void mprisPlayerMetadataToNetworkPackage(NetworkPackage& np, const QVariantMap& nowPlayingMap) const;
|
||||
|
||||
QHash<QString, QString> playerList;
|
||||
int prevVolume;
|
||||
|
|
Loading…
Reference in a new issue