jptgdp: Add rofi menu, autoplay option
This commit is contained in:
parent
6d958494ff
commit
83058754bb
36
jptgdp
36
jptgdp
@ -41,6 +41,10 @@ validatedeps() {
|
|||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
sanitize() {
|
||||||
|
[ -z "$1" ] && return 1
|
||||||
|
_return="${1//[^ a-zA-Z0-9\[\]|()_-]/}"
|
||||||
|
}
|
||||||
|
|
||||||
# Traps
|
# Traps
|
||||||
trapexit() {
|
trapexit() {
|
||||||
@ -64,6 +68,7 @@ files are cached in your Music folder under "JPTGDP Songs" for offline use.
|
|||||||
|
|
||||||
-c Clears the cache (which can become quite large)
|
-c Clears the cache (which can become quite large)
|
||||||
-d Download only; don't queue anything up
|
-d Download only; don't queue anything up
|
||||||
|
-p Play the playlist after it is enqueued
|
||||||
-s Shuffle the playlist
|
-s Shuffle the playlist
|
||||||
|
|
||||||
-r <directory> Start up rofi, if installed, and present a listing of
|
-r <directory> Start up rofi, if installed, and present a listing of
|
||||||
@ -77,7 +82,23 @@ EOF
|
|||||||
}
|
}
|
||||||
rofimenu() {
|
rofimenu() {
|
||||||
validatedeps rofi || error "$_return is not currently installed" 1
|
validatedeps rofi || error "$_return is not currently installed" 1
|
||||||
error "Not yet implemented" 1
|
[ -d "$_optrofidir" ] || error "Could not open directory \"$_optrofidir\"" 2
|
||||||
|
files=$(find "$_optrofidir" -type f -name \*.gdp)
|
||||||
|
if [ -n "$files" ]; then
|
||||||
|
# Strip file suffixes for a cleaner menu
|
||||||
|
playlists=""
|
||||||
|
while read file; do
|
||||||
|
filebase="$(basename -- "$file")"
|
||||||
|
filebase="${filebase%.gdp}"
|
||||||
|
[ -n "$playlists" ] && playlists+=$'\n'
|
||||||
|
playlists+="$filebase"
|
||||||
|
done <<< "$files"
|
||||||
|
else
|
||||||
|
error "No playlists found" 61
|
||||||
|
fi
|
||||||
|
choice="$(rofi -dmenu -p "$_name" <<< "$playlists")"
|
||||||
|
[ -z "$choice" ] && error "User aborted at selection" 62
|
||||||
|
playlist "$_optrofidir"/"$choice".gdp
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
playlist() {
|
playlist() {
|
||||||
@ -87,7 +108,8 @@ playlist() {
|
|||||||
while read line; do
|
while read line; do
|
||||||
[ -z "$line" ] && continue
|
[ -z "$line" ] && continue
|
||||||
rm "$_tmpfile"* > /dev/null 2>&1
|
rm "$_tmpfile"* > /dev/null 2>&1
|
||||||
filename="$_musicdir/${line//[^ a-zA-Z0-9\[\]|()_-]/}"
|
sanitize "$line"
|
||||||
|
filename="$_musicdir/$_return"
|
||||||
if ! [ -f "$filename" ]; then
|
if ! [ -f "$filename" ]; then
|
||||||
log "Finding a song for \"$line\""
|
log "Finding a song for \"$line\""
|
||||||
youtube-dl \
|
youtube-dl \
|
||||||
@ -106,6 +128,10 @@ playlist() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
[ -z "$_optdownloadonly" ] && audacious -e "$filename"
|
[ -z "$_optdownloadonly" ] && audacious -e "$filename"
|
||||||
|
if [ -n "$_optautoplay" ]; then
|
||||||
|
audacious -p
|
||||||
|
unset _optautoplay
|
||||||
|
fi
|
||||||
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)
|
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)
|
||||||
if [ -z "$_optdownloadonly" ]; then
|
if [ -z "$_optdownloadonly" ]; then
|
||||||
log "Finished building queue"
|
log "Finished building queue"
|
||||||
@ -123,7 +149,7 @@ main() {
|
|||||||
trap trapexit EXIT
|
trap trapexit EXIT
|
||||||
|
|
||||||
# Actual program stuff
|
# Actual program stuff
|
||||||
while getopts ":cdf:r:sh" opt; do
|
while getopts ":cdf:pr:sh" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
c)
|
c)
|
||||||
clearcache
|
clearcache
|
||||||
@ -135,8 +161,12 @@ main() {
|
|||||||
f)
|
f)
|
||||||
_optfile="$OPTARG"
|
_optfile="$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
p)
|
||||||
|
_optautoplay=1
|
||||||
|
;;
|
||||||
r)
|
r)
|
||||||
_optrofi=1
|
_optrofi=1
|
||||||
|
_optrofidir="$OPTARG"
|
||||||
;;
|
;;
|
||||||
s)
|
s)
|
||||||
_optshuffle=1
|
_optshuffle=1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user