Wikia

Music Player Daemon Community Wiki

Hack:mpdgrep

525pages on
this wiki
Talk0
  • Description: Simple Complicated script to search MPD's library for a keyword and play the next hit.
  • Homepage: http://github.com/magcius/mpdsetup
  • 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

See Hack:query.py

Old Version Edit

#!/bin/bash

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

# Create a temp file for our operations.
TMP=$(mktemp)

# 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"
fi

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

# 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.

Around Wikia's network

Random Wiki