hrfee / mpris2client

rough mpris2 client library for go
MIT License
0 stars 2 forks source link

Error while getting player position from spotify #1

Open secu2 opened 3 years ago

secu2 commented 3 years ago

I'm a user of your great waybar module waybar-mpris I currently face an error while using the module with the --position flag with the official spotify client.

❯ waybar-mpris --position
panic: interface conversion: interface {} is uint64, not int64

goroutine 1 [running]:
github.com/hrfee/mpris2client.(*Player).StringPosition(0xc0001360b0, 0xc00009cea0, 0x55b1e5528511)
    github.com/hrfee/mpris2client@v0.0.0-20210115213010-244c4cd6a569/mpris2.go:218 +0x285
main.playerJSON(0xc0001360b0, 0x55b1e55b8c38, 0xc000010058)
    git.hrfee.pw/hrfee/waybar-mpris/main.go:54 +0x1086
main.(*players).JSON(...)
    git.hrfee.pw/hrfee/waybar-mpris/main.go:121
main.main()
    git.hrfee.pw/hrfee/waybar-mpris/main.go:322 +0x7e7

I did some verification and the dbus interface returns an uint64 from spotify client metadata mpris:length while your code expects an int64

Here is what my dbus interfaces returns from spotify :

❯ dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'
   variant       array [
         dict entry(
            mpris:trackid            variant                spotify:track:3jwLYTAiYI8kWQB8BfQ6iM         )
         dict entry(
            mpris:length            variant                uint64 321034000
         )
         dict entry(
            mpris:artUrl            variant                https://open.spotify.com/image/ab67616d00001e022fb9075aafbfd405dc088078         )
         dict entry(
            xesam:album            variant                Pumple Snout         )
         dict entry(
            xesam:albumArtist            variant                array [
                  Frequent               ]
         )
         dict entry(
            xesam:artist            variant                array [
                  Frequent               ]
         )
         dict entry(
            xesam:autoRating            variant                double 0.2
         )
         dict entry(
            xesam:discNumber            variant                int32 1
         )
         dict entry(
            xesam:title            variant                Pumple Snout         )
         dict entry(
            xesam:trackNumber            variant                int32 1
         )
         dict entry(
            xesam:url            variant                https://open.spotify.com/track/3jwLYTAiYI8kWQB8BfQ6iM         )
      ]

The error happens with the casting here : https://github.com/hrfee/mpris2client/blob/244c4cd6a569dcb648bd45e959d106331dcf4175/mpris2.go#L218

Some more type checking might be necessary, do you have an idea of how it's possible to handle this ?

hrfee commented 3 years ago

I've just added a switch case to this library (haven't updated waybar-mpris to use it yet though), and it reads fine now. However, spotify doesn't support the MediaPlayer2.Player.Position property, so there's no way of getting the position it seems. I'll fix it so it doesn't display the position at all.

hrfee commented 3 years ago

Added in 40f813d.