doti3/bar/src/spotify.php

40 lines
831 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'));
$label = sprintf('%s %s', $title, $artist);
$fullText = sprintf('%s %s', $title, $artist);
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'),
]
);