40 lines
831 B
PHP
Executable file
40 lines
831 B
PHP
Executable file
#!/usr/bin/php
|
||
<?php
|
||
|
||
require __DIR__.'/base/block.php';
|
||
|
||
$status = trim(shell_exec('playerctl -p spotify status'));
|
||
|
||
if (!in_array($status, ['Playing'])) {
|
||
die;
|
||
}
|
||
|
||
function cleanUp($d, $max = 20)
|
||
{
|
||
$string = trim(str_replace(['"', "'"], ' ', $d));
|
||
|
||
if (mb_strlen($string) > $max) {
|
||
$string = substr($string, 0, $max).'…';
|
||
}
|
||
|
||
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);
|
||
|
||
if (getenv('BLOCK_BUTTON') === '1') {
|
||
shell_exec('i3-msg \'workspace "6. MEDIA"\'');
|
||
}
|
||
|
||
echo block(
|
||
'spotify',
|
||
[
|
||
'full_text' => $fullText,
|
||
'color' => color('music'),
|
||
]
|
||
);
|