Last active
January 6, 2019 10:37
-
-
Save pbenke/8549f84bd9803d512b889f0c44e54dd6 to your computer and use it in GitHub Desktop.
Clementine and MellowPlayer currently playing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
echo "-- "; | |
echo "\nPetar from benke.co.uk"; | |
$listening = ''; | |
$players = array("MellowPlayer", "clementine"); | |
foreach($players as $player){ | |
exec("qdbus org.mpris.MediaPlayer2.$player /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus", $output, $result); | |
if(count($output)){ | |
$status = $output[0]; | |
if($status == "Playing"){ | |
exec("qdbus org.mpris.MediaPlayer2.$player /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata", $output, $result); | |
if(count($output)){ | |
foreach($output as $line){ | |
if(strpos($line, 'xesam:artist:') !== false){ | |
list($bogus, $artist) = explode(": ", $line, 2); | |
$artist = trim($artist); | |
} | |
if(strpos($line, 'xesam:title:') !== false){ | |
list($bogus, $title) = explode(": ", $line, 2); | |
$title = trim($title); | |
} | |
} | |
if(strlen($artist) && strlen($title)){ | |
$listening = "Listening \"$title\" by $artist"; | |
break; | |
} | |
} | |
} | |
} | |
} | |
if(strlen($listening)) echo "\n$listening"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment