Rhythmbox - Get current track path

172 views Asked by At

Is there a way to programmatically get the full path of the currently played track in rhythmbox (or even any music player on linux)? It could be a linux command or in python.

I need this to sort my new music albums with shortcuts (i.e., delete or archive the currently played file until the new music folder is empty). I was doing it with amarok but with the new version my plugins do not work anymore and there is no documentation yet.

2

There are 2 answers

0
dr0i On

Install mp3info and use this script:

#!/bin/sh

apps="vlc totem rhythmbox banshee mplayer gnome-mplayer"

for app in $apps
do
  pat="([^\w-]$app)"
  if ps ux | grep -P $pat | grep -vq grep; then
    echo
    echo "$app detected"
    echo -------------------------
    file=`lsof -F n -c "$app" | grep -i "^.*\.mp3$" | sed 's/^n//g'`
    if [ ! -z "$file" ]; then
      echo -n "Now playing: "
      if mp3info "$file" 2>&1 | grep -q "does not have an ID3"; then
        echo $file
        echo MP3 info missing \(ID3v2 not supported\)    
      else
        echo
        mp3info "$file"
      fi
    else
      echo Playing no MP3 files
    fi
  fi
done

Credits to Vaphell (https://ubuntuforums.org/showthread.php?t=1562395&s=4ea6cfb6ce5e37681f20a82af578825f&p=9785684#post9785684).

0
Zach On

It can be done with mplayer:

path=`lsof -c mplayer | grep -E '\.m4a|\.mp3|\.flac|\.mp4|\.wav|\.wma|\.aac' | sed "s+.*\(/home/$USER.*\)+\1+g"`

Details:

  • lsof -c mplayer: list all the files currently used by mplayer;
  • grep -E '\.m4a|\.mp3|\.flac|\.mp4|\.wav|\.wma|\.aac': only keep the lines with audio files (there may be a more elegant way to do that...);
  • sed "s+.*\(/home/$USER.*\)+\1+g": remove the line prefix (to adapt if your music files are not in /home/$USER).