dotfiles/.config/zsh/functions/mkplaylist
2022-06-29 19:55:55 +02:00

25 lines
725 B
Bash
Executable File

#!/usr/bin/env zsh
# Create a playlist in the current folder, of the media files in the folder and
# all subfolders.
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_help=()
zparseopts -D -K -- h=o_help
if [[ ${#o_help} -ne 0 ]]; then
print -l "usage: ${0} [-h] [NAME]" \
"Without NAME, the current directory is used."
return 0
fi
if [[ -v 1 ]]; then
local name=${1}
else
local name=${PWD##*/}
fi
find . -type f -name '*.mkv' -or -name '*.mp4' -or -name '*.avi' \
-or -name '*.flac' -or -name '*.ogg' -or -name '*.opus' -or -name '*.mp3' \
-or -name '*.m4a' -or -name '*.wma' -or -name '*.aac' \
| grep -Pv '[^[](ED|OP|PV) ?\d' | sort > ${name}.m3u8