doti3/bar/src/spotify.php

41 lines
874 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'));
$fullText = pspan($artist, '#ccc', '#222').pspan($title, '#ddd', '#000');
if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('i3-msg \'workspace "6. MEDIA"\'');
}
echo block(
'spotify',
[
'full_text' => $fullText,
'color' => color('music'),
'separator' => false,
'separator_block_width' => 0,
]
);