My intention is to notify-send a message if an unrated song is about to come to end. I am using Rhythmbox with the MPRIS plugin and I found following scripts :
#Get position
gdbus call \
--session \
--dest org.mpris.MediaPlayer2.rhythmbox \
--object-path /org/mpris/MediaPlayer2 \
--method org.freedesktop.DBus.Properties.Get \
org.mpris.MediaPlayer2.Player Position
#Get metadata such as song length and user song rating
gdbus call \
--session \
--dest org.mpris.MediaPlayer2.rhythmbox \
--object-path /org/mpris/MediaPlayer2 \
--method org.freedesktop.DBus.Properties.Get \
org.mpris.MediaPlayer2.Player Metadata
Output : (<int64 77000000>,)
(in microseconds) for the first one, and for the second one : (<{'mpris:trackid': <'/org/mpris/MediaPlayer2/Track/4782'>, 'xesam:url': <'file:///path-to-the-mp4-file'>, 'xesam:title': <'Song title'>, 'xesam:artist': <['Artist name']>, 'xesam:album': <'Album name'>, 'xesam:genre': <['Genre name']>, 'xesam:audioBitrate': <214016>, 'xesam:contentCreated': <'2017-01-01T00:00:00Z'>, 'xesam:lastUsed': <'2017-09-12T13:41:52Z'>, 'mpris:length': <int64 189000000>, 'xesam:trackNumber': <15>, 'xesam:useCount': <6>, 'xesam:userRating': <0.80000000000000004>, 'mpris:artUrl': <'file:///path-to-an-image-i-guess'>}>,)
('mpris:length' is what matters)
But I don't know how to use the results, espetially how to parse them to check there are less than 10 seconds left (I need the remaining time as int value and don't know how to achieve it in a script...).
There over, I am not sure how to implement that. I was thinking about a .sh file, which I would run from a terminal and which would check every few seconds what the playing state is.
Can you give some pieces of advice and/or the begining of a script (which has at least an infinite loop or a recursion -what is the best?- and the remaining time refreshed in a variable) ?
Thank you very much in advance !
I post here what I finally made, so that if it interests somebody, he could use it. Thank you to @steeldriver.