dotfiles/.config/zsh/functions/mkplaylist

25 lines
721 B
Plaintext
Raw Normal View History

2022-04-15 13:46:20 +02:00
#!/usr/bin/env zsh
# Create a playlist in the current folder, of the media files in the folder and
2022-04-15 13:51:01 +02:00
# all subfolders.
2022-04-15 13:46:20 +02:00
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