i3blocks: use ruby for strawberry current song
When using shellscript for dbus properties, I parsed the output manually. It was not really good and special characters were not displayed correctly.
This commit is contained in:
parent
e3f59f7cad
commit
a5a42bffb8
32
i3blocks/multi/blocks/strawberry-current.rb
Executable file
32
i3blocks/multi/blocks/strawberry-current.rb
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require "dbus"
|
||||||
|
|
||||||
|
def seconds_to_ms(sec)
|
||||||
|
sec /= 1000000
|
||||||
|
"%02d:%02d" % [sec / 60, sec % 60]
|
||||||
|
end
|
||||||
|
|
||||||
|
service = DBus.session_bus["org.mpris.MediaPlayer2.strawberry"]
|
||||||
|
unless service.exists?
|
||||||
|
puts 'Strawberry not running'
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
object = service["/org/mpris/MediaPlayer2"]
|
||||||
|
interface = object["org.mpris.MediaPlayer2.Player"]
|
||||||
|
|
||||||
|
metadata = interface["Metadata"]
|
||||||
|
|
||||||
|
if metadata.empty?
|
||||||
|
puts 'No song in playlist'
|
||||||
|
exit 2
|
||||||
|
end
|
||||||
|
|
||||||
|
position = interface["Position"]
|
||||||
|
playback_status = interface["PlaybackStatus"]
|
||||||
|
|
||||||
|
|
||||||
|
printf "(#{playback_status}) " if playback_status != 'Playing'
|
||||||
|
puts "#{metadata['xesam:albumArtist'].join(', ')} - #{metadata['xesam:album']} - #{metadata['xesam:title']} " \
|
||||||
|
"(#{metadata['xesam:trackNumber']}) [#{seconds_to_ms(position)} / #{seconds_to_ms(metadata['mpris:length'])}]"
|
||||||
@ -3,7 +3,7 @@ separator_block_width=10
|
|||||||
markup=none
|
markup=none
|
||||||
|
|
||||||
[mpc]
|
[mpc]
|
||||||
command=./blocks/strawberry.sh
|
command=./blocks/strawberry-current.rb
|
||||||
interval=5
|
interval=5
|
||||||
signal=12
|
signal=12
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user