Skip to content

Instantly share code, notes, and snippets.

@pbenke
Last active January 6, 2019 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbenke/8549f84bd9803d512b889f0c44e54dd6 to your computer and use it in GitHub Desktop.
Save pbenke/8549f84bd9803d512b889f0c44e54dd6 to your computer and use it in GitHub Desktop.
Clementine and MellowPlayer currently playing
#!/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