diff --git a/plugins/mpriscontrol/mpriscontrolplugin.h b/plugins/mpriscontrol/mpriscontrolplugin.h --- a/plugins/mpriscontrol/mpriscontrolplugin.h +++ b/plugins/mpriscontrol/mpriscontrolplugin.h @@ -52,6 +52,7 @@ void addPlayer(const QString& ifaceName); void removePlayer(const QString& ifaceName); void sendPlayerList(); + void mprisPlayerMetadataToNetworkPackage(NetworkPackage& np, const QVariantMap& nowPlayingMap) const; QHash playerList; int prevVolume; diff --git a/plugins/mpriscontrol/mpriscontrolplugin.cpp b/plugins/mpriscontrol/mpriscontrolplugin.cpp --- a/plugins/mpriscontrol/mpriscontrolplugin.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin.cpp @@ -129,22 +129,9 @@ QDBusArgument bullshit = qvariant_cast(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 @@ NetworkPackage answer(PACKAGE_TYPE_MPRIS); bool somethingToSend = false; if (np.get(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 @@ 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"