Skip to content

Instantly share code, notes, and snippets.

@tacofumi
Last active August 29, 2015 14:14
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 tacofumi/42b67d23ac44dda24e91 to your computer and use it in GitHub Desktop.
Save tacofumi/42b67d23ac44dda24e91 to your computer and use it in GitHub Desktop.
Using youtube-dl to download audio and convert it to m4a with ffmpeg. (the file downloaded as it is won't play on iTunes for some reason. So I decided to convert it with ffmpeg with -acodec copy)
#!/bin/bash
# Setting default quality to 256kb
quality=141
# See if url is provided
url=$1
if [ -z $url ]; then
echo "Need a URL"
exit
fi
# See if 256kb is available. If not, setting quality to 128kb.
is256kb=$(youtube-dl -F $url | grep 141)
if [ -z is256kb ]; then
echo "256kb not available. Downloading lower quality..."
quality=140
fi
# Getting and setting the title
original=$(youtube-dl --get-filename -f $quality $url)
title=${original:0:${#original}-16}".m4a"
echo "Processing $title"
# Download the audio file
youtube-dl -f $quality $url > /dev/null
# Converting the audio file to playable file with ffmpeg and then move it to Music folder
ffmpeg -v 0 -i "$original" -acodec copy "$title"
mv "$title" ~/Music
rm "$original"
echo "$title created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment