Music Player Daemon Community Wiki


525pages on
this wiki
Add New Page
Talk0 Share
  • Description: Simple Complicated script to search MPD's library for a keyword and play the next hit.
  • Homepage:
  • Maintainer(s): JP St. Pierre < jstpierre AT mecheye DOT net >

MPD recently broke this script. I made a new one in Python with support for a lot more features.

New Version Edit


Old Version Edit


# mpdgrep - grep our playlist.
# JP St. Pierre
# October 3, 2008

# Create a temp file for our operations.

# Grep the playlist with our argument to get a a list of all playlist IDs, with line numbers..
mpc --format "%artist% - %album% - %title%" playlist | grep -i "$*" | grep -no '^[> ][0-9]\+' > $TMP

# Get the line number of the currently playing song.
playing_line=$(grep ">" $TMP | grep -o '^[0-9]\+')

# Get the total number of lines.
total=$(wc -l $TMP)

# If we're not playing a song in the search pattern, play the first one.
if [ -z "$playing_line" ]; then
  let "playing_line=0"

# If we're at the bottom of the list, play the first one again.
if [ "$playing_line" -eq "$total" ]; then
  let "playing_line=0"

# Do some arithmetic to get the number of lines below the currently playing song.
let "wanted=$total-$playing_line"

# Play our song.
mpc play $(tail -$wanted $TMP | head -1 | grep -o '[0-9]\+')

# Remove the temp file.
rm $TMP

I have this aliased to "play", so I can type "play Viva la Vida" at the console and have my music playing a mere 2 seconds later.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki