Skip to content

Instantly share code, notes, and snippets.

@albertyw
Last active July 16, 2021 05:28
Show Gist options
  • Select an option

  • Save albertyw/0eb7564341334e85e7d9ebf816a66c0a to your computer and use it in GitHub Desktop.

Select an option

Save albertyw/0eb7564341334e85e7d9ebf816a66c0a to your computer and use it in GitHub Desktop.
Download and convert youtube playlists to MP3
#!/bin/bash
# This script converts an mp4 into an mp3
# It works by running ffmpeg in a docker container
set -euo pipefail
IFS=$'\n'
convert () {
input="$1"
output="$input.mp3"
docker run -v "$(pwd):$(pwd)" -w "$(pwd)" jrottenberg/ffmpeg:3.4-scratch \
-stats \
-i "./$input" -vn \
-acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 \
"./$output"
}
if [ -z "${1-}" ]; then
for f in $(find . -type f -name "*.mp4"); do
convert "$f"
done
else
convert "$1"
fi
#!/bin/bash
# Download a youtube playlist
set -euo pipefail
IFS=$'\n\t'
url="$1"
wget https://yt-dl.org/downloads/2021.06.06/youtube-dl-2021.06.06.tar.gz
tar xvf youtube-dl*
screen python3 youtube-dl/youtube-dl "$url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment