#!/bin/sh
# Description: Add files or directories to the deadbeef queue
#
# Dependencies: deadbeef audio player
#
# Shell: sh
# Author: John McQuah

target="$1"
fullpath="$2/$target"

if [ -r "$target" ]; then
	[ -n "$(ps --no-header -C deadbeef-main)" ] || exit 0
	[ -f "$target" ] && deadbeef --queue -- "$fullpath" 2>/dev/null
	[ -d "$target" ] && find "$fullpath" \( -iname "*.mp3" \
		-o -iname "*.ogg" -o -iname "*.flac" \
		-o -iname "*.m4a" \) -print0 | sort -z \
		| xargs -0 deadbeef --queue -- 2>/dev/null
fi