Skip to content

Instantly share code, notes, and snippets.

@0scvr
Created September 9, 2023 18:27
Show Gist options
  • Save 0scvr/67ed81503c270e24cd9634b009361c7c to your computer and use it in GitHub Desktop.
Save 0scvr/67ed81503c270e24cd9634b009361c7c to your computer and use it in GitHub Desktop.
Shell script to download a list of songs from Youtube Music. Requires "gytmdl" to function.
#!/bin/zsh
FAILCTR=0
# Check if a file argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <url_list_file>"
exit 1
fi
url_list_file="$1"
# Check if the file exists
if [ ! -f "$url_list_file" ]; then
echo "Error: File '$url_list_file' not found."
exit 1
fi
# Assign file descriptor 3 to read input from input file
exec 3< $url_list_file
# Read URLs from the file line by line and run gytmdl for each
while IFS= read -u 3 -r url; do
echo "Downloading: $url"
gytmdl "$url"
gytmdl_exit_status=$?
if [ $gytmdl_exit_status -ne 0 ]; then
echo "Error downloading: $url"
# Increment the error counter
FAILCTR=$((counter + 1))
fi
# Sleep for 10s to avoid rate-limiting
sleep 10
done
echo "Total failed executions: $FAILCTR"
echo "All downloads completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment