ptgdp: Build a queue in mpd
This commit is contained in:
parent
92b5c86d71
commit
c97fb6563f
41
ptgdp
41
ptgdp
@ -49,8 +49,13 @@ checkforsong() {
|
||||
[ -z "$1" ] && return 1
|
||||
# Very rudimentary implementation
|
||||
# TODO: Make this a lot more thorough, maybe ensure MIME is good
|
||||
[ -f "$_musicdir/$1.*" ] && return 0
|
||||
[ -f "$_musicdir/$1" ]
|
||||
for file in "$_musicdir/$1"*; do
|
||||
if [ -f "$file" ]; then
|
||||
_return="$file"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
validatedeps() {
|
||||
# $@: Dependencies to validate
|
||||
@ -151,6 +156,7 @@ playlist() {
|
||||
normal dialog-error 3000
|
||||
error "Failed to communicate with MPD" 52
|
||||
fi
|
||||
local -a queue
|
||||
local -i dlexist=0
|
||||
local -i dlsuccess=0
|
||||
local -i dlfailure=0
|
||||
@ -177,8 +183,15 @@ playlist() {
|
||||
> /dev/null 2>&1 &
|
||||
if wait $!; then
|
||||
dlsuccess+=1
|
||||
local extension="${_tmpfile##*.}"
|
||||
mv "$_tmpfile"* "$filename.$extension"
|
||||
for file in "$_tmpfile"*; do
|
||||
[ -f "$file" ] && local extension="$file"
|
||||
break
|
||||
done
|
||||
extension="${extension##*/}"
|
||||
extension="${extension##*.}"
|
||||
filename="$filename.$extension"
|
||||
mv "$_tmpfile"* "$filename"
|
||||
queue+=("$filename")
|
||||
else
|
||||
dlfailure+=1
|
||||
notify "Could not download song" \
|
||||
@ -188,15 +201,9 @@ playlist() {
|
||||
continue
|
||||
fi
|
||||
else
|
||||
queue+=("$_return")
|
||||
dlexist+=1
|
||||
fi
|
||||
validatedeps mpc || continue
|
||||
[ -z "$_optdownloadonly" ] || continue
|
||||
mpc add "$filename"
|
||||
if [ -n "$_optautoplay" ]; then
|
||||
mpc play > /dev/null 2>&1
|
||||
unset _optautoplay
|
||||
fi
|
||||
else
|
||||
output="$(
|
||||
youtube-dl \
|
||||
@ -226,8 +233,18 @@ playlist() {
|
||||
elif [ -z "$_optdryrun" ]; then
|
||||
if [ -z "$_optdownloadonly" ]; then
|
||||
notify "Finished building queue" \
|
||||
"The playlist queue has been built in Audacious"
|
||||
"The playlist queue has been built in mpd"
|
||||
log "Finished building queue: $dlexist cached, $dlsuccess downloaded, $dlfailure failed"
|
||||
mpc update --wait > /dev/null 2>&1
|
||||
local xdgmusicdir="${XDG_MUSIC_DIR:-$HOME/Music}"
|
||||
for file in "${queue[@]}"; do
|
||||
file=${file##$xdgmusicdir/}
|
||||
mpc add "$file" > /dev/null 2>&1 || error "Could not add file: \"$file\""
|
||||
done
|
||||
if [ -n "$_optautoplay" ]; then
|
||||
mpc play > /dev/null 2>&1
|
||||
unset _optautoplay
|
||||
fi
|
||||
else
|
||||
notify "Finished precaching" \
|
||||
"Your songs have been cached and are ready for offline playback"
|
||||
|
Loading…
Reference in New Issue
Block a user