doti3/bar/src/spotify.php

37 lines
725 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;
}
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'),
]
);