#!/bin/bash

if [ $# -eq 0 ]; then
  echo "usage $0 host"
  exit 1
fi

# Define the path and any password options for MPD
MY_MPC="/usr/bin/mpc -h $1"

# Check if the server is up and running
ping -c 2 -W 1 $1 2>&1>/dev/null
if [ $? -eq 0 ]; then

  # Define acceptable genres of random tracks to add
  MY_GENRES="Dance Electronica Folk Funk Indie Jazz Pop
             Reggae Rock Soul Soundtrack"

  # Define Anything to strip out
  MY_STRIP="Wiggles Fuck Shit"

  # Remove the track list file if it exists
  rm -f /tmp/random_mpd_tracks.txt

  for genre in ${MY_GENRES}
  do
    $MY_MPC search genre ${genre} >> /tmp/random_mpd_tracks.txt
  done

  for strip in ${MY_STRIP}
  do
    grep -v -i ${strip} /tmp/random_mpd_tracks.txt > /tmp/random_mpd_tracks_out.txt
    mv /tmp/random_mpd_tracks_out.txt /tmp/random_mpd_tracks.txt
  done
fi