Add title, artist and album to MPRIS network packets
ClosedPublic

Authored by mtijink on Nov 22 2017, 7:47 PM.

Details

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)

Diff Detail

Repository
R224 KDE Connect
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mtijink created this revision.Nov 22 2017, 7:47 PM
apol requested changes to this revision.Nov 22 2017, 11:43 PM
apol added a subscriber: apol.
apol added inline comments.
plugins/mpriscontrol/mpriscontrolplugin.cpp
140

You can use {} instead of QStringLiteral("").

232–233

Can you put the string in a separate variable? it will be easier to read.

240

What does this status send that we don't have now?

This revision now requires changes to proceed.Nov 22 2017, 11:43 PM
mtijink updated this revision to Diff 22800.Nov 23 2017, 9:25 AM

Factor out some statements into variables

To improve readability.

mtijink added inline comments.Nov 23 2017, 9:29 AM
plugins/mpriscontrol/mpriscontrolplugin.cpp
140

That doesn't work: I get the following compile error, probably because the argument is templated and not a QString.

error: no matching function for call to ‘NetworkPackage::set(QString, <brace-enclosed initializer list>)’
240

Sorry, that shouldn't have been included. I was experimenting with it earlier, but figured that I didn't really need it.

Mpris allows three states: "Stopped", "Paused" and "Playing", although a lot of players never report "Stopped". Using the current code you cannot distinguish between "Stopped" and "Paused". Since I don't need it, I removed it in the diff.

Are the changes okay this way?

nicolasfella added inline comments.
plugins/mpriscontrol/mpriscontrolplugin.cpp
133

I would rather extract all metadata like:

if (nowPlayingMap.contains(QStringLiteral("xesam:foo"))) {
    QString foo = nowPlayingMap[QStringLiteral("xesam:foo")].toString();
}
....

And compose the nowPlaying at the end. This way all the ifs have the same structure and the artist isn't checked twice.

135

Please check whether it's really necessary to set it to an empty string or it's the default case. I'm not sure about that right now :)

mtijink updated this revision to Diff 24214.Dec 21 2017, 12:18 PM

Incorporated suggested improvements. The code really is a lot cleaner this way! I think I also fixed a (latent) bug with inconsistent sending of the length of the playing track.

mtijink marked 7 inline comments as done.Dec 21 2017, 12:21 PM
mtijink added inline comments.
plugins/mpriscontrol/mpriscontrolplugin.cpp
135

It's necessary, since the code is written to send only changes in the network packets. If we don't send an empty artist etc. the Android part will think it's unchanged. With the current code it implicitely sends empty values, which is better.

mtijink updated this revision to Diff 24215.Dec 21 2017, 12:28 PM
mtijink marked an inline comment as done.

Oops, missed a single line in the refactoring.

Looks much better! Those two blocks of code appear the same to me, have you tried factoring them out into a method?

Not yet, but that shouldn't be too difficult.

Do you want only the part relating to nowPlayingMap? That's functionality-wise identical.
I could also remove nearly the whole MprisControlPlugin::propertiesChanged method, but then the code will make additional DBus calls to fetch all information even if only some properties change.

Do you want only the part relating to nowPlayingMap? That's functionality-wise identical.

Let's start with this. We can see if the other one makes sense later

mtijink updated this revision to Diff 24421.Dec 28 2017, 2:37 PM

Refactored common functionality into a single function

nicolasfella added inline comments.Dec 28 2017, 2:45 PM
plugins/mpriscontrol/mpriscontrolplugin.cpp
269

i would prefer something like

insertPlayingInformation(NetworkPackage& target, const QVariantMap& source)

to make it more clear which one is the source/target. Or make the method name more clear

mtijink updated this revision to Diff 24427.Dec 28 2017, 3:28 PM

Change common functionality method name, as suggested.

Looks good to me :) @apol what do you think?

apol accepted this revision.Dec 29 2017, 4:48 PM
This revision is now accepted and ready to land.Dec 29 2017, 4:48 PM
This revision was automatically updated to reflect the committed changes.