Skip to content

Instantly share code, notes, and snippets.

@phracker
Created May 1, 2014 09:55
Show Gist options
  • Save phracker/11448247 to your computer and use it in GitHub Desktop.
Save phracker/11448247 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# m3ugen.sh: M3U video playlist generator
# Recursively searches a directory for video files
# and adds them to the specified m3u file.
#
# Requires `realpath` (sometimes `grealpath`) from coreutils.
# by phracker <https://github.com/phracker>
#
# m3ugen.sh -d <searchdir> -f <m3ufile>
usage() { echo "Usage: $0 [-d <searchdir>] [-f <m3ufile>]" 1>&2; exit 1; }
if [ -e /usr/local/bin/grealpath ]; then
REALPATH="grealpath"
elif [ -e /usr/local/bin/realpath ] || [ -e /usr/bin/realpath ]; then
REALPATH="realpath"
else
usage
fi
while getopts ":d:f:" o; do
case "${o}" in
d)
SEARCHDIR=$($REALPATH ${OPTARG})
;;
f)
FILEOUT=${OPTARG}
;;
*)
usage
;;
esac
done
if [ -z "$SEARCHDIR" ] || [ -z "$FILEOUT" ]; then
usage
fi
find $SEARCHDIR -type f \( -iname "*.mpg" -o -iname "*.mp4" -o -iname "*.flv" -o -iname "*.avi" -o -iname "*.wmv" -o -iname "*.mov" -o -iname "*.mkv" -o -iname "*.3gp" -o -iname "*.aaf" -o -iname "*.asf" -o -iname "*.m4v" -o -iname "*.mpeg" -o -iname "*.mpe" -o -iname "*.rm" -o -iname "*.swf" \) -size +1M > $FILEOUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment