doti3/bar/src/spotify.php

41 lines
874 B
PHP
Raw Normal View History

2017-06-19 16:36:59 +02:00
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$status = trim(shell_exec('playerctl -p spotify status'));
if (!in_array($status, ['Playing'])) {
die;
}
2017-12-05 16:42:33 +01:00
function cleanUp($d, $max = 20)
2017-06-19 16:36:59 +02:00
{
$string = trim(str_replace(['"', "'"], ' ', $d));
2017-12-04 19:41:16 +01:00
if (mb_strlen($string) > $max) {
$string = substr($string, 0, $max).'…';
2017-06-19 16:36:59 +02:00
}
return $string;
}
$title = cleanUp(shell_exec('playerctl -p spotify metadata xesam:title'));
$artist = cleanUp(shell_exec('playerctl -p spotify metadata xesam:artist'));
2019-01-28 11:13:11 +01:00
$fullText = pspan($artist, '#ccc', '#222').pspan($title, '#ddd', '#000');
2017-06-19 16:36:59 +02:00
2017-12-04 19:41:16 +01:00
if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('i3-msg \'workspace "6. MEDIA"\'');
}
2017-06-19 16:36:59 +02:00
echo block(
'spotify',
[
'full_text' => $fullText,
'color' => color('music'),
2019-01-28 11:13:11 +01:00
'separator' => false,
'separator_block_width' => 0,
2017-06-19 16:36:59 +02:00
]
);