Skip to content

Instantly share code, notes, and snippets.

@xim
Created October 25, 2010 16:10
Show Gist options
  • Save xim/645216 to your computer and use it in GitHub Desktop.
Save xim/645216 to your computer and use it in GitHub Desktop.
mplayer wrapper for making playlists
#!/bin/bash -f
SORT="sort -n"
filter="-type f"
DENIED_EXTS="txt m3u pls jpg jpeg gif nfo srt sub torrent zip rar cbz cbr"
if [[ "$1" =~ ^- && "$1" != "--help" ]] ;then
if [[ "$1" = "--cat" ]] ; then
SORT="cat"
else
SORT="sort $1"
fi
shift
fi
# Ensures correct handling of paths with spaces and makes playlist independent
# of $PWD... This is ugly, patches accepted :p
hit_dashdash=0
for arg in "$@" ; do
if [[ $hit_dashdash -eq 0 && "$arg" =~ ^- ]] ;then
if [[ "$arg" = "--" ]] ; then
hit_dashdash=1
elif [[ "$arg" =~ ^--?(\?|help)?$ ]] ;then
echo -e "Usage:
`basename $0` [sort argument | --cat] [--filter=FILTER] [mplayer_args | paths] [--] [paths]" >&2
exit 1
elif [[ "$arg" =~ ^--filter= ]] ;then
filter+=" -a ( ${arg#--filter=} )"
else
ARGS+=("$arg")
fi
else
PATHS+=("`readlink -f -- \"$arg\"`")
fi
done
if [[ ${#PATHS[@]} -eq 0 ]] ;then
PATHS+=("$PWD")
fi
blacklist=(`for ext in $DENIED_EXTS ; do echo -a '!' -name "*.$ext" ;done`)
echo mplayer "${ARGS[@]}" -playlist "<(" find "${PATHS[@]}" $filter "${blacklist[@]}" "|" $SORT ")"
exec mplayer "${ARGS[@]}" -playlist <( find "${PATHS[@]}" $filter "${blacklist[@]}" | $SORT )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment