Skip to content

Instantly share code, notes, and snippets.

@spvkgn
Last active September 28, 2023 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spvkgn/d297314d7808fb14945fbc54bab0bf04 to your computer and use it in GitHub Desktop.
Save spvkgn/d297314d7808fb14945fbc54bab0bf04 to your computer and use it in GitHub Desktop.
#!/bin/bash
export MPD_HOST=$HOME/.config/mpd/socket
#MIME_CMD="file -bL --mime-type"
MIME_CMD="mimetype -biL"
[ -z "$1" ] || tmpfile=$(mktemp)
add_file() {
$MIME_CMD "$file" | grep -q 'audio' && \
echo "file://$(readlink -f "$file")" >> "$tmpfile"
}
for arg in "$@" ; do
if [ -f "$arg" ] ; then # file
file=$arg
add_file "$file"
elif [ -d "$arg" ] ; then # files in directory
find "$arg" ! -regex ".*\.\(m3u8?\|part\)$" -print | sort -f | while read -r file ; do
add_file "$file"
done
fi
done
[ -s "$tmpfile" ] && mpc add < "$tmpfile"
rm -f "$tmpfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment