Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromium spotify track metadata mixed with previous track metadata #11

Open
redfast00 opened this issue Jun 8, 2023 · 3 comments
Open

Comments

@redfast00
Copy link

When a track finishes playing and goes to the next track, the metadata of the track printed to the console log and saved in the yaml file is incorrect, and often intermixed with the metadata from the previous song. This is with https://open.spotify.com in chromium. I suspect that that might be the issue: the nateive Spotify application probably sends events differently to DBUS than the web app. I'm unable to run the native application, so I can't say this for certain, but I have a strong suspicion.

When I monitor the D-Bus events with dbus-monitor, I see that there are multiple events to announce the metadata of the track playing, each one with one more field filled in compared to the previous one. In the trace below, the player was at the end of "Uncle Brian's Abattoir" by "Trampolene, Peter Doherty"; the next song it started playing is "Fight On" by "The Lathums".

(Kind of related; the behaviour of the application is a bit wonky when I go to the next song by pressing the 'next' button while a song is playing, but I don't really expect striputary to handle this and don't know if this is also caused by the multiple events per song change)

signal time=1686185204.736639 sender=org.freedesktop.DBus -> destination=:1.3088 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.3088"
signal time=1686185204.736652 sender=org.freedesktop.DBus -> destination=:1.3088 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
   string ":1.3088"
signal time=1686185208.233868 sender=:1.34 -> destination=(null destination) serial=482 path=/org/mpris/MediaPlayer2; interface=org.mpris.MediaPlayer2.Player; member=Seeked
   int64 133259341
signal time=1686185208.235008 sender=:1.34 -> destination=(null destination) serial=483 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanPlay"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1686185208.235198 sender=:1.34 -> destination=(null destination) serial=484 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanPause"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1686185208.235622 sender=:1.34 -> destination=(null destination) serial=485 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanGoPrevious"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1686185208.235914 sender=:1.34 -> destination=(null destination) serial=486 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanGoNext"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1686185208.236145 sender=:1.34 -> destination=(null destination) serial=487 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 133259341
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/mpris/MediaPlayer2/TrackList/NoTrack"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string "Uncle Brian's Abattoir"
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string "Trampolene, Peter Doherty"
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string "Uncle Brian's Abattoir"
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.236492 sender=:1.34 -> destination=(null destination) serial=488 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "PlaybackStatus"
         variant             string "Stopped"
      )
   ]
   array [
   ]
signal time=1686185208.236600 sender=:1.34 -> destination=(null destination) serial=489 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 133259341
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/mpris/MediaPlayer2/TrackList/NoTrack"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string "Uncle Brian's Abattoir"
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string "Trampolene, Peter Doherty"
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string ""
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.237262 sender=:1.34 -> destination=(null destination) serial=490 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 133259341
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/mpris/MediaPlayer2/TrackList/NoTrack"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string "Uncle Brian's Abattoir"
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string ""
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string ""
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.237691 sender=:1.34 -> destination=(null destination) serial=491 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 133259341
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/mpris/MediaPlayer2/TrackList/NoTrack"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string ""
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string ""
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string ""
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.238173 sender=:1.34 -> destination=(null destination) serial=492 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 0
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/mpris/MediaPlayer2/TrackList/NoTrack"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string ""
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string ""
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string ""
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.238507 sender=:1.34 -> destination=(null destination) serial=493 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanSeek"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1686185208.357447 sender=:1.34 -> destination=(null destination) serial=494 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 0
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/chromium/MediaPlayer2/TrackList/Track400BD8FD95B2F2D9ABABBDD0917E4D95"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string ""
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string ""
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string ""
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.357597 sender=:1.34 -> destination=(null destination) serial=495 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "PlaybackStatus"
         variant             string "Playing"
      )
   ]
   array [
   ]
signal time=1686185208.357768 sender=:1.34 -> destination=(null destination) serial=496 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 0
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/chromium/MediaPlayer2/TrackList/Track400BD8FD95B2F2D9ABABBDD0917E4D95"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string ""
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string ""
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string "Fight On"
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.357840 sender=:1.34 -> destination=(null destination) serial=497 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 0
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/chromium/MediaPlayer2/TrackList/Track400BD8FD95B2F2D9ABABBDD0917E4D95"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string ""
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string "The Lathums"
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string "Fight On"
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.357928 sender=:1.34 -> destination=(null destination) serial=498 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 0
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/chromium/MediaPlayer2/TrackList/Track400BD8FD95B2F2D9ABABBDD0917E4D95"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string "How Beautiful Life Can Be"
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string "The Lathums"
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string "Fight On"
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.358136 sender=:1.34 -> destination=(null destination) serial=499 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanPlay"
         variant             boolean true
      )
   ]
   array [
   ]
signal time=1686185208.358165 sender=:1.34 -> destination=(null destination) serial=500 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanPause"
         variant             boolean true
      )
   ]
   array [
   ]
signal time=1686185208.358185 sender=:1.34 -> destination=(null destination) serial=501 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanGoPrevious"
         variant             boolean true
      )
   ]
   array [
   ]
signal time=1686185208.358240 sender=:1.34 -> destination=(null destination) serial=502 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanGoNext"
         variant             boolean true
      )
   ]
   array [
   ]
signal time=1686185208.358261 sender=:1.34 -> destination=(null destination) serial=503 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Metadata"
         variant             array [
               dict entry(
                  string "mpris:length"
                  variant                      int64 168753106
               )
               dict entry(
                  string "mpris:trackid"
                  variant                      object path "/org/chromium/MediaPlayer2/TrackList/Track400BD8FD95B2F2D9ABABBDD0917E4D95"
               )
               dict entry(
                  string "xesam:album"
                  variant                      string "How Beautiful Life Can Be"
               )
               dict entry(
                  string "xesam:artist"
                  variant                      array [
                        string "The Lathums"
                     ]
               )
               dict entry(
                  string "xesam:title"
                  variant                      string "Fight On"
               )
            ]
      )
   ]
   array [
   ]
signal time=1686185208.358332 sender=:1.34 -> destination=(null destination) serial=504 path=/org/mpris/MediaPlayer2; interface=org.mpris.MediaPlayer2.Player; member=Seeked
   int64 1241
signal time=1686185208.358336 sender=:1.34 -> destination=(null destination) serial=505 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "CanSeek"
         variant             boolean true
      )
   ]
   array [
   ]
method call time=1686185208.529701 sender=:1.3086 -> destination=org.freedesktop.DBus serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal', path='/org/freedesktop/DBus/Local',interface='org.freedesktop.DBus.Local', member='Disconnected'"
method return time=1686185208.529719 sender=org.freedesktop.DBus -> destination=:1.3086 serial=6 reply_serial=5
signal time=1686185208.529826 sender=org.freedesktop.DBus -> destination=:1.3086 serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
   string ":1.3086"
signal time=1686185208.529838 sender=org.freedesktop.DBus -> destination=(null destination) serial=6204 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged
   string ":1.3086"
   string ":1.3086"
   string ""
method call time=1686185208.609547 sender=:1.3089 -> destination=org.freedesktop.DBus serial=1 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=Hello
method return time=1686185208.609559 sender=org.freedesktop.DBus -> destination=:1.3089 serial=1 reply_serial=1
   string ":1.3089"
signal time=1686185208.609567 sender=org.freedesktop.DBus -> destination=(null destination) serial=6205 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged
   string ":1.3089"
   string ""
   string ":1.3089"
signal time=1686185208.609576 sender=org.freedesktop.DBus -> destination=:1.3089 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.3089"
method call time=1686185208.609661 sender=:1.3089 -> destination=org.freedesktop.DBus serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal', path='/org/freedesktop/DBus/Local',interface='org.freedesktop.DBus.Local', member='Disconnected'"
method return time=1686185208.609667 sender=org.freedesktop.DBus -> destination=:1.3089 serial=3 reply_serial=2
method call time=1686185208.609830 sender=:1.3089 -> destination=org.freedesktop.DBus serial=3 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameHasOwner
   string "org.gnome.SessionManager"
method return time=1686185208.609841 sender=org.freedesktop.DBus -> destination=:1.3089 serial=4 reply_serial=3
   boolean false
method call time=1686185208.609988 sender=:1.3089 -> destination=org.freedesktop.DBus serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameHasOwner
   string "org.freedesktop.PowerManagement"
method return time=1686185208.609996 sender=org.freedesktop.DBus -> destination=:1.3089 serial=5 reply_serial=4
   boolean false
signal time=1686185208.625368 sender=:1.34 -> destination=(null destination) serial=506 path=/org/mpris/MediaPlayer2; interface=org.mpris.MediaPlayer2.Player; member=Seeked
   int64 17726

@Tehforsch
Copy link
Owner

Thanks for the details. I recently updated my spotify native app to a new version and realized that the pattern of dbus messages had changed between versions, however the difference wasn't quite as drastic as it seems to be between native and web/chromium.
In order for this type of problem to be solved properly, I will need to find a more robust way to handle dbus messages. Since testing this kind of stuff manually is very annoying, I'll try to set up a framework for testing in which I save a number of recorded buffers alongside the (entire) dbus information for different platforms and then test that striputary gets the metadata correct on all platforms. More importantly, it should make it easier to maintain this in the future.
This should also help me in finally addressing #3 properly, which will hopefuly improve usability. However, all of this will take some time and I am not sure when I'll get to start working on it. In the meantime, if you have any suggestions on how to "quickly" patch the dbus code so that it can deal with your case, I'd be happy to help.

(Kind of related; the behaviour of the application is a bit wonky when I go to the next song by pressing the 'next' button while a song is playing, but I don't really expect striputary to handle this and don't know if this is also caused by the multiple events per song change)

Yes, striputary can't handle this at all currently, but I think it should be possible in principle. What I don't know is what the expected behavior should be. I guess it would be best to disregard the the current song entirely (which was interrupted halfway through?) and to remember the timestamp of the next step?

@redfast00
Copy link
Author

I think a possible solution might be to:

  • detect song changes by looking at groups of events in a timeframe (for example, group all events of maximum 5 seconds)
  • Using the last metadata in such an event group as the one containing the actual metadata for the next song

I think the expected behaviour would indeed be to disregard the song if it's skipped

In any case, I'm really happy that you keep this project alive :)

@Tehforsch
Copy link
Owner

I think a possible solution might be to:
...

This sounds like a reasonable fix. I'll try to implement this in the coming weeks and will let you know. I'll have to try to replicate the behavior you see first, so I hope chromium behaves the same on my machine.

In any case, I'm really happy that you keep this project alive :)

Of course, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants