Last active
August 29, 2015 14:14
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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