Skip to content

Instantly share code, notes, and snippets.

@txgk
Created January 28, 2024 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txgk/cebff2e7a02b39f20aa7ce54ebdef614 to your computer and use it in GitHub Desktop.
Save txgk/cebff2e7a02b39f20aa7ce54ebdef614 to your computer and use it in GitHub Desktop.
#!/bin/sh
main_dir="$HOME/.cache/audio_taster"
success_file='downloaded-successfully'
duration='3000'
loop_it='0'
PLAY_CURRENT_DIRECTORY() {
killall mpv 2>/dev/null
for file in *; do
[ "$file" = '*' ] && break
[ "$file" = "$success_file" ] && continue
msg="$(echo "Playing $file" | sed -e 's/ \[.*\]//' -e 's/\..*$//')"
notify-send -t "$duration" "$msg" >/dev/null 2>/dev/null
if [ "$loop_it" = '1' ]; then
mpv --no-terminal --loop-playlist -- "$file" >/dev/null 2>/dev/null
else
mpv --no-terminal -- "$file" >/dev/null 2>/dev/null
fi
done
}
if [ "$1" = '-l' ]; then
loop_it='1'
shift
fi
if [ -n "$1" ]; then
download_dir="$main_dir/$(echo "$1" | base32)"
mkdir -p "$download_dir" || exit 1
cd "$download_dir" || exit 1
if [ -e "$success_file" ]; then
PLAY_CURRENT_DIRECTORY
else
if yt-dlp --quiet --format bestaudio "$1" >/dev/null 2>/dev/null; then
touch "$success_file"
PLAY_CURRENT_DIRECTORY
else
notify-send -t "$duration" "Download failed!" >/dev/null 2>/dev/null
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment