#!/bin/sh

# Remove stale playlist files
[ -f /tmp/*.pls ] && rm /tmp/*.pls

DIR="$1"
APPEND=${2:-0}
[ -d "$DIR" ] && DIR=${DIR%\/} || DIR=${DIR%/[^/]*}
NAME=${DIR##*/}

for i in `cat /etc/file_ext`; do
  if [ -z "$EXTS" ]; then
    EXTS="$i"
  else
    EXTS="$EXTS\|$i"
  fi
done

find "$DIR" | grep -v /GEEXBOX/ | grep -i "\.\($EXTS\)\$" | sort > /tmp/"$NAME".pls
if [ -s /tmp/"$NAME".pls ]; then
  echo -e "menu hide\nloadlist \"/tmp/$NAME.pls\" $APPEND" > /var/mp_control
else
  exit 1
fi
