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