Skip to content

Instantly share code, notes, and snippets.

@Nezteb
Last active July 23, 2021 15:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Nezteb/1b76470294ad7bdd9ca0 to your computer and use it in GitHub Desktop.
Save Nezteb/1b76470294ad7bdd9ca0 to your computer and use it in GitHub Desktop.
Downloads specified youtube videos as songs given text file.
#!/bin/bash
# Download_Songs.sh
# By Noah Betzen (Nezteb)
#
# Requires youtube-dl: https://rg3.github.io/youtube-dl/
# You can install youtube-dl via most package managers:
# brew install youtube-dl
# apt-get install youtube-dl
#
# Creates relative directory called "downloads" with downloaded songs in it
#
# Sample file: (two video URLs on own lines, songs.txt)
# https://www.youtube.com/watch?v=abcdefghijk
# https://www.youtube.com/watch?v=lmnopqrstuv
#
# Once downloaded, song URL is removed from file
[ "$#" -eq 1 ] || { echo >&2 "Requires single text file (with youtube links on each line) name as argument."; exit 1; }
command -v youtube-dl >/dev/null 2>&1 || { echo >&2 "Install youtube-dl first."; exit 1; }
if [ ! -d "downloads" ]; then
mkdir downloads
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
youtube-dl -x --audio-format mp3 $line -o './downloads/%(title)s.%(ext)s'
grep -v "$line" $1 > temp
mv temp $1
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment