doti3/bar/src/spotify.php
2017-06-19 16:36:59 +02:00

37 lines
725 B
PHP
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)
{
$string = trim(str_replace(['"', "'"], ' ', $d));
if (mb_strlen($string) > 15) {
$string = substr($string, 0, 15).'…';
}
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);
echo block(
'spotify',
[
'full_text' => $fullText,
'color' => color('music'),
]
);