altdesktop / playerctl

🎧 mpris media player command-line controller for vlc, mpv, RhythmBox, web browsers, cmus, mpd, spotify and others.
GNU Lesser General Public License v3.0
2.42k stars 79 forks source link

Follow mode behaves unreliably if the player is closed (Plexamp) #288

Open bvergnaud opened 1 year ago

bvergnaud commented 1 year ago

Hello,

I use Plexamp to play music. I'm using playerctl in a waybar custom module to show what song is playing. And rather than poll every second, I'd rather use the --follow flag which seems perfectly suited.

So I crafted this little command which works almost as expected:

playerctl --player Plexamp --follow metadata --format '{"text": "{{markup_escape(artist)}} - {{markup_escape(title)}}", "tooltip": "{{markup_escape(playerName)}} : {{markup_escape(artist)}} - {{markup_escape(title)}}", "alt": "{{markup_escape(status)}}", "class": "{{markup_escape(status)}}"}'

I say almost because if I close Plexamp, playerctl seems to not know what to do about it. It prints a blank line, stays open, and won't resume following any new Plexamp I open or any other player.

Here's an example:

➜ playerctl --player Plexamp --follow metadata --format '{"text": "{{markup_escape(artist)}} - {{markup_escape(title)}}", "tooltip": "{{markup_escape(playerName)}} : {{markup_escape(artist)}} - {{markup_escape(title)}}", "alt": "{{markup_escape(status)}}", "class": "{{markup_escape(status)}}"}'
{"text": "Sonata Arctica - Replica", "tooltip": "Plexamp : Sonata Arctica - Replica", "alt": "Playing", "class": "Playing"}
{"text": "Tremonti - Betray Me", "tooltip": "Plexamp : Tremonti - Betray Me", "alt": "Playing", "class": "Playing"}

It just hangs there until I kill it / ^C.

Here's a more detailed example with debug mode enabled:

➜ G_MESSAGES_DEBUG=playerctl playerctl --player Plexamp --follow metadata --format '{"text": "{{markup_escape(artist)}} - {{markup_escape(title)}}", "tooltip": "{{markup_escape(playerName)}} : {{markup_escape(artist)}} - {{markup_escape(title)}}", "alt": "{{markup_escape(status)}}", "class": "{{markup_escape(status)}}"}'
(playerctl:204259): playerctl-DEBUG: 01:18:22.514: Getting list of player names from D-Bus
(playerctl:204259): playerctl-DEBUG: 01:18:22.514: Playerctld is running. Getting names from there.
(playerctl:204259): playerctl-DEBUG: 01:18:22.515: Getting list of player names from D-Bus
(playerctl:204259): playerctl-DEBUG: 01:18:22.517: initializing player: Plexamp
(playerctl:204259): playerctl-DEBUG: 01:18:22.517: player appeared: Plexamp
{"text": "Kenji Kawai - Warlords Sprint", "tooltip": "Plexamp : Kenji Kawai - Warlords Sprint", "alt": "Playing", "class": "Playing"}
(playerctl:204259): playerctl-DEBUG: 01:18:25.789: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6420'>, 'xesam:title': <'Annihilation By The Hands Of God'>,'xesam:album': <'The All-Star Sessions'>, 'xesam:artist': <['Roadrunner United']>, 'mpris:length': <int64 333587000>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/2/43eca92ee96466a8ea7834d7ef747c184e3a3b1'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:25.789: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:25.789: Plexamp: track id updated to /org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6420
(playerctl:204259): playerctl-DEBUG: 01:18:25.789: Plexamp: metadata changed
{"text": "Roadrunner United - Annihilation By The Hands Of God", "tooltip": "Plexamp : Roadrunner United - Annihilation By The Hands Of God", "alt": "Playing", "class": "Playing"}
(playerctl:204259): playerctl-DEBUG: 01:18:25.790: Playback status not set on track change; getting status from interface instead
(playerctl:204259): playerctl-DEBUG: 01:18:25.792: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:25.981: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/1589'>, 'xesam:title': <'The Slopes Of The Blessure'>, 'xesam:album': <'The Witcher 3: Wild Hunt - Blood And Wine'>, 'xesam:artist': <['Piotr Musiał']>, 'mpris:length': <int64 242000000>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/b/f121aba49994def0f8fdc07fd1ea91e96f12a21'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:25.981: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:25.981: Plexamp: track id updated to /org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/1589
(playerctl:204259): playerctl-DEBUG: 01:18:25.981: Plexamp: metadata changed
{"text": "Piotr Musiał - The Slopes Of The Blessure", "tooltip": "Plexamp : Piotr Musiał - The Slopes Of The Blessure", "alt": "Playing", "class": "Playing"}
(playerctl:204259): playerctl-DEBUG: 01:18:25.981: Playback status not set on track change; getting status from interface instead
(playerctl:204259): playerctl-DEBUG: 01:18:25.982: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:26.203: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297'>, 'xesam:title': <'Reflect The Storm'>, 'xesam:album':<'Come Clarity'>, 'xesam:artist': <['In Flames']>, 'mpris:length': <int64 256480000>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/6/96231377610204b2c2f02c8c8acc14c536cd93b'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:26.203: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:26.203: Plexamp: track id updated to /org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297
(playerctl:204259): playerctl-DEBUG: 01:18:26.203: Plexamp: metadata changed
{"text": "In Flames - Reflect The Storm", "tooltip": "Plexamp : In Flames - Reflect The Storm", "alt": "Playing", "class": "Playing"}
(playerctl:204259): playerctl-DEBUG: 01:18:26.203: Playback status not set on track change; getting status from interface instead
(playerctl:204259): playerctl-DEBUG: 01:18:26.205: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:29.406: removing managed player: Plexamp

(playerctl:204259): playerctl-DEBUG: 01:18:29.406: player name vanished: Plexamp
(playerctl:204259): playerctl-DEBUG: 01:18:36.221: player name appeared: Plexamp
(playerctl:204259): playerctl-DEBUG: 01:18:36.230: initializing player: Plexamp
(playerctl:204259): playerctl-DEBUG: 01:18:36.230: player appeared: Plexamp
(playerctl:204259): playerctl-DEBUG: 01:18:37.045: {'PlaybackStatus': <'Playing'>}
(playerctl:204259): playerctl-DEBUG: 01:18:37.045: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:37.045: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:37.046: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297'>, 'xesam:title': <'Reflect The Storm'>, 'xesam:album':<'Come Clarity'>, 'xesam:artist': <['In Flames']>, 'mpris:length': <int64 0>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:37.046: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:37.046: Plexamp: track id updated to /org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297
(playerctl:204259): playerctl-DEBUG: 01:18:37.046: Plexamp: metadata changed
(playerctl:204259): playerctl-DEBUG: 01:18:37.046: Playback status not set on track change; getting status from interface instead
(playerctl:204259): playerctl-DEBUG: 01:18:37.047: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:37.188: {'PlaybackStatus': <'Stopped'>}
(playerctl:204259): playerctl-DEBUG: 01:18:37.188: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:37.188: Plexamp: playback status set to Stopped
(playerctl:204259): playerctl-DEBUG: 01:18:37.354: {'PlaybackStatus': <'Playing'>}
(playerctl:204259): playerctl-DEBUG: 01:18:37.354: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:37.354: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:37.355: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297'>, 'xesam:title': <'Reflect The Storm'>, 'xesam:album':<'Come Clarity'>, 'xesam:artist': <['In Flames']>, 'mpris:length': <int64 0>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/a/f062c65f1f62d8abacb8422ccd4b9345d3f928f'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:37.355: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:37.355: Plexamp: metadata changed
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: {'PlaybackStatus': <'Paused'>}
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: Plexamp: playback status set to Paused
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: {'CanSeek': <false>}
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: {'CanPause': <false>}
(playerctl:204259): playerctl-DEBUG: 01:18:41.174: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:41.175: {'Volume': <0.75>}
(playerctl:204259): playerctl-DEBUG: 01:18:41.175: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:41.175: Plexamp: volume set to 0.750000
(playerctl:204259): playerctl-DEBUG: 01:18:41.175: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297'>, 'xesam:title': <'Reflect The Storm'>, 'xesam:album':<'Come Clarity'>, 'xesam:artist': <['In Flames']>, 'mpris:length': <int64 256480000>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/6/96231377610204b2c2f02c8c8acc14c536cd93b'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:41.175: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:41.175: Plexamp: metadata changed
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: {'PlaybackStatus': <'Playing'>}
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: {'CanSeek': <true>}
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: {'CanPause': <true>}
(playerctl:204259): playerctl-DEBUG: 01:18:42.066: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:53.061: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/32217'>, 'xesam:title': <'Thrown Further'>, 'xesam:album': <'Marching in Time'>, 'xesam:artist': <['Tremonti']>, 'mpris:length': <int64 287887000>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/b/d0394ffa440acd45f51b6488f1901dafd8e185c'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:53.061: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:53.061: Plexamp: track id updated to /org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/32217
(playerctl:204259): playerctl-DEBUG: 01:18:53.061: Plexamp: metadata changed
(playerctl:204259): playerctl-DEBUG: 01:18:53.061: Playback status not set on track change; getting status from interface instead
(playerctl:204259): playerctl-DEBUG: 01:18:53.063: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:54.732: {'PlaybackStatus': <'Paused'>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.732: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.732: Plexamp: playback status set to Paused
(playerctl:204259): playerctl-DEBUG: 01:18:54.733: {'CanSeek': <false>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.733: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.733: {'CanPause': <false>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.733: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.734: {'Metadata': <{'mpris:trackid': <objectpath '/org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297'>, 'xesam:title': <'Reflect The Storm'>, 'xesam:album':<'Come Clarity'>, 'xesam:artist': <['In Flames']>, 'mpris:length': <int64 256480000>, 'mpris:artUrl': <'file:///home/bvergnaud/.cache/Plexamp/Images/6/96231377610204b2c2f02c8c8acc14c536cd93b'>}>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.734: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.734: Plexamp: track id updated to /org/node/mediaplayer/Plexamp/track/9388277a028388f46d24b2fbe31078b932240831/library/metadata/6297
(playerctl:204259): playerctl-DEBUG: 01:18:54.734: Plexamp: metadata changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.734: Playback status not set on track change; getting status from interface instead
(playerctl:204259): playerctl-DEBUG: 01:18:54.735: Plexamp: playback status set to Paused
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: {'PlaybackStatus': <'Playing'>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: Plexamp: playback status set to Playing
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: {'CanSeek': <true>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: Plexamp: properties changed
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: {'CanPause': <true>}
(playerctl:204259): playerctl-DEBUG: 01:18:54.912: Plexamp: properties changed

So it does catch the new instance, and new status / metadata changes. However it just does not output them to stdout. Before the blank line, you can see the output after each Plexamp: metadata changed line. After the blank line, no output. I did the same test with spotify, which works better, there's a few half-empty lines when the player restarts, but switching to a new track works as expected.

In my case it's a problem because even though waybar gives me a restart-interval option to restart the module after some time, since playerctl never exits, there's nothing to restart, the thread is still considered active.

I'm happy to provide more details if it can help.

skiletro commented 1 year ago

Can confirm I'm having the same issue with spotify (+ pretty much any other single player I tested). Was wondering if there are any updates on this issue?