Youtube-dl is an awesome tool that lets you download videos from the most popular video platforms. When we combine it with Mac’s Automator we can set a keyboard shortcut to download the video we currently have open in our browser tab.
Requirements:
- homebrew – a nice packet manager
- youtube-dl – to download videos
- ffmpeg – to transcode files
- recommended: nodejs, osx-notifier*
*used for nice notifications in user interface
In Terminal, run:
brew install youtube-dl ffmpeg node; npm install -g osx-notifier
Next, open the Automator app on Mac and create a new service. Then from the Actions library choose Utilities and Run Applescript.
Change Service receives dropdown to no input and paste the script below into the Run AppleScript area.
on run {input, parameters}
tell application "Safari" to set currentTab to current tab of window 1
tell application "Safari" to set currentURL to URL of currentTab
tell application "Safari" to set currentTitle to name of currentTab
tell application "Finder" to set homeFolder to path to home folder
do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js --type info --title \"Video Download\" --subtitle \"New video download started\" --message " & quoted form of currentTitle
do shell script "/usr/local/bin/youtube-dl -o \"" & POSIX path of homeFolder & "Desktop/%(title)s.%(ext)s\" --ffmpeg-location /usr/local/bin/ffmpeg --recode-video mp4 " & currentURL
do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js --type pass --title \"Video Download\" --subtitle \"Video download successful\" --message " & quoted form of currentTitle
return input
end run
Once you’re done you can save the service, I chose Download video using youtube-dl as the name.
Next we need to bind the service to a keyboard shortcut. This is very handy as we’ll just need to hit the keyboard shortcut in the browser with a YouTube video open to kickstart the download service.
Open up System Preferences then Keyboard.
Within the keyboard preferences pane click the Shortcuts tab. Then select Services from the left pane and make sure the service you created earlier is checked in the right pane. All that’s left is to select a preferred keyboard shortcut, which is entirely up to your preference. I chose [ctrl] + [alt] + [cmd] + [D].
Hope you found that useful. Automator really is a nifty tool and I look forward to experimenting with it in other ways in the future.
Other Video Sites
You can also use youtube-dl for downloading videos from other sites like Vimeo and Wistia.
For Wistia, you need to use this URL and replace the ending with the code of the file you want:
https://fast.wistia.net/embed/iframe/o1kvat5mfb
Ali says
Nigeria
reetu says
Good luck
John says
I am building an Automator service instead and having an issue where the files aren’t muxed after being downloaded. When running the same commands in terminal the files are muxed. The error I receive is:
WARNING: You have requested multiple formats but ffmpeg or avconv are not installed. The formats won’t be merged.
AppleScript is not seeing those binaries from being installed.
on run {input, parameters}
try
tell application “System Events”
set pid to do shell script “cd /tmp/; /usr/local/bin/youtube-dl –newline ” & input & ” > /tmp/vidstatus 2>&1 & echo $!”
delay 1
repeat while ((do shell script “kill -0 ” & pid) is “”) — check if pid is still responding
display dialog “Status: ” & (do shell script “tail -n 1 /tmp/vidstatus”) — display last line of output
end repeat
end tell
delay 5
on error
display notification “YouTube Download Failed” — show error message
end try
end run
john says
Honestly, I had problems following I find it a little too technical for a not so tech savvy like me. I am hoping to read more of downloaders that I can use for free like Acethinker Online Video Downloader. I know there might be other tools like it. I wish to see more. Thank you for this info anyway.