Last active
January 2, 2016 09:09
-
-
Save andyeff/8281537 to your computer and use it in GitHub Desktop.
Dashtube (bash)
This file contains 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 | |
id=$(youtube-dl --no-playlist --get-id -- $1 | tr -d '\r') | |
if [[ $? -ne 0 ]]; then | |
exit $? | |
fi | |
desc=$(youtube-dl --no-playlist --get-title -- $1 | tr -cd '[:alnum:][:space:]' | tr -d '\r') | |
echo "id is ${id}" | |
echo "input is ${1}" | |
echo "title is ${desc}" | |
# Try for 1440p, | |
# Then 60fps 1080p / 720p, | |
# Then 1080p / 720p, | |
# Then 480p | |
# http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs | |
youtube-dl --no-playlist -f 264/299/298/137/136/135 -o "dl_${id}_v.mp4" -- $1 | |
if [[ $? -ne 0 ]]; then | |
exit $? | |
fi | |
youtube-dl --no-playlist -f 141/140/139 -o "dl_${id}_a.m4a" -- $1 | |
if [[ $? -ne 0 ]]; then | |
exit $? | |
fi | |
ffmpeg -i "dl_${id}_v.mp4" -i "dl_${id}_a.m4a" -vcodec copy -acodec copy "dl_${id}_muxed.mp4" 2>/dev/null | |
echo "..." | |
mv "dl_${id}_muxed.mp4" "${desc}.mp4" | |
if [[ -d ~/Downloads ]]; then | |
mv "${desc}.mp4" ~/Downloads | |
elif [[ -d ~/download ]]; then | |
mv "${desc}.mp4" ~/download | |
fi | |
if [[ $? -ne 0 ]]; then | |
exit $? | |
else | |
rm "dl_${id}_v.mp4" | |
rm "dl_${id}_a.m4a" | |
echo "All Done - ${desc}.mp4" | |
echo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment