Skip to content

Instantly share code, notes, and snippets.

@smj10j
Last active November 19, 2015 21:42
Show Gist options
  • Save smj10j/00084320ae337297d164 to your computer and use it in GitHub Desktop.
Save smj10j/00084320ae337297d164 to your computer and use it in GitHub Desktop.
Download YouTube Videos
#
# Made for use with IFTTT
# Wrapped in an Automator Folder Action Workflow
#
#
property bundlePath : the path to me as text
property binPath : bundlePath & "Contents:bin"
on run {input, parameters}
set theShellScript to "#!/bin/zsh
#set -e
#exec 2>&1
PATH=\"/usr/local/bin:" & (POSIX path of binPath) & ":$PATH\"
export FILE_PATH=" & (quoted form of (POSIX path of (input as text))) & "
FILE_NAME=$(basename \"$FILE_PATH\")
export FILE_NAME=${FILE_NAME%.*}
export OUTPUT_FILE_PATH=~/Dropbox/IFTTT/YouTube/\"$FILE_NAME\".mp3
export SHORT_VIDEO_URL=$(cat \"$FILE_PATH\")
osascript -e 'display notification \"'$FILE_NAME'\" with title \"Downloading YouTube video...\"'
export VIDEO_URL=$(curl -Ls -o /dev/null -w %{url_effective} \"$SHORT_VIDEO_URL\")
VIDEO_ID=${VIDEO_URL%&*}
export VIDEO_ID=${VIDEO_ID#*=}
export API_URL=\"http://youtubeinmp3.com/fetch/?format=json&video=$VIDEO_URL\"
DOWNLOAD_URL=$(curl -L \"$API_URL\" | jq .link)
export DOWNLOAD_URL=$(echo $DOWNLOAD_URL | tr -d '\"')
curl -L -o \"$OUTPUT_FILE_PATH\" \"$DOWNLOAD_URL\"
osascript -e 'display notification \"\" with title \"Compressing with ffmpeg...\"'
ffmpeg -n -i \"$OUTPUT_FILE_PATH\" -pix_fmt rgb24 -vsync 2 -b:a 192K -aq 2 \"$OUTPUT_FILE_PATH\".done.mp3
osascript -e 'display notification \"'$OUTPUT_FILE_PATH'\" with title \"Finished downloading video...\"'
env
"
do shell script theShellScript
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment