ptgdp: Add dry run, overhaul erroring syntax
This commit is contained in:
parent
107937bb41
commit
d699c8195f
38
ptgdp
38
ptgdp
@ -28,9 +28,11 @@ log() {
|
||||
}
|
||||
error() {
|
||||
[ -z "$1" ] && return 1 # Message body
|
||||
[ -z "$2" ] && return 2 # Exit code
|
||||
log "$1"
|
||||
exit "${2:-1}"
|
||||
# 2: Exit code
|
||||
printf "%s: \\e[31m%s\\e[0m\\n" \
|
||||
"$_name" \
|
||||
"$1"
|
||||
[ -n "$2" ] && exit "${2:-1}"
|
||||
}
|
||||
notify() {
|
||||
[ -z "$_optrofi" ] && return 0
|
||||
@ -85,6 +87,9 @@ files are cached in your Music folder under "JPTGDP Songs" for offline use.
|
||||
-c Clears the cache (which can become quite large)
|
||||
-d Download only; don't queue anything up
|
||||
Conflicts with -p
|
||||
-D Dry run; parse out all songs, downloaded or not, and
|
||||
print out the resolved names. Useful for testing, as
|
||||
YouTube searches can sometimes be finicky.
|
||||
-p Play the playlist after it is enqueued.
|
||||
Conflicts with -d
|
||||
-s Shuffle the playlist
|
||||
@ -146,6 +151,7 @@ playlist() {
|
||||
rm "$_tmpfile"* > /dev/null 2>&1
|
||||
sanitize "$line"
|
||||
filename="$_musicdir/$_return"
|
||||
if [ -z "$_optdryrun" ]; then
|
||||
if ! [ -f "$filename" ]; then
|
||||
log "Finding a song for \"$line\""
|
||||
youtube-dl \
|
||||
@ -165,7 +171,7 @@ playlist() {
|
||||
notify "Could not download song" \
|
||||
"youtube-dl did not download a song for \"$line\", either because it is out of date or because it could not find a video to rip from" \
|
||||
normal dialog-error 3000
|
||||
log "Could not download song \"$line\""
|
||||
error "Could not download song \"$line\""
|
||||
continue
|
||||
fi
|
||||
else
|
||||
@ -176,6 +182,25 @@ playlist() {
|
||||
audacious -p
|
||||
unset _optautoplay
|
||||
fi
|
||||
else
|
||||
output="$(
|
||||
youtube-dl \
|
||||
--get-title \
|
||||
--geo-bypass \
|
||||
--playlist-items 1 \
|
||||
ytsearch:"$line" 2>&1
|
||||
)"
|
||||
exitcode="$?"
|
||||
if [ $exitcode -gt 0 ]; then
|
||||
error "Could not find song \"$line\""
|
||||
continue
|
||||
fi
|
||||
if ! [ "$output" = "${output#*WARNING}" ]; then
|
||||
log "$line parsed, but title could not be extracted"
|
||||
else
|
||||
log "$line - \"$output\""
|
||||
fi
|
||||
fi
|
||||
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)
|
||||
if [ "$dlexist" = "0" ] && [ "$dlsuccess" = "0" ]; then
|
||||
notify "Failed to enqueue playlist" \
|
||||
@ -203,7 +228,7 @@ main() {
|
||||
trap trapexit EXIT
|
||||
|
||||
# Actual program stuff
|
||||
while getopts ":cdf:pr:sh" opt; do
|
||||
while getopts ":cdDf:pr:sh" opt; do
|
||||
case $opt in
|
||||
c)
|
||||
clearcache
|
||||
@ -212,6 +237,9 @@ main() {
|
||||
d)
|
||||
_optdownloadonly=1
|
||||
;;
|
||||
D)
|
||||
_optdryrun=1
|
||||
;;
|
||||
f)
|
||||
_optfile="$OPTARG"
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user