Video Downloader
Tired of sketchy websites and crazy ads just to download a video? One shortcut saves any link on your Mac as an MP4 or MP3, in the best quality.
Download any video on your Mac with one shortcut
Press ⌃⌥⌘4 on a video and it saves as an MP4 in the quality you pick. Press ⌃⌥⌘3 and you get the audio as an MP3. No sketchy download sites, no ads, no pop-ups. Free, with Hammerspoon and yt-dlp.
Time: About 15 minutes.
What you'll get
- ⌃⌥⌘4 on any video page: pick 1080p, max quality (4K when there is one) or a smaller 720p, and the MP4 lands in your Downloads folder
- ⌃⌥⌘3: the audio only, as a 320 kbps MP3
- No download websites. No ads, no fake "Download" buttons, no pop-ups.
- It works on YouTube, Instagram, TikTok, X and the hundreds of other sites yt-dlp supports
- MP4s that play in QuickTime and Photos and drop straight into your editor
- Your clipboard is put back the way it was afterwards
- Free, and everything runs on your own Mac
How it works
- You press the shortcut on a video page.
- Hammerspoon, a free Mac automation app, copies the link from your browser's address bar. Outside a browser, it uses a link you've copied.
- It hands the link to yt-dlp, the free, open-source downloader behind a lot of those download sites, and ffmpeg puts the video and sound together.
- An arrow in the menu bar shows it's working, and an alert tells you when the file is saved.
What you'll need before we start
- A Mac, Apple Silicon or Intel
- Hammerspoon, free
- Homebrew, free, to install yt-dlp and ffmpeg
Time: About 15 minutes.
Set it up with Claude
Want a guide by your side? Copy this into Claude and answer its questions.
I'm setting up the Video Downloader from cezarhere.com/video-downloader:
a Hammerspoon script for my Mac that downloads the video in my browser with
yt-dlp when I press Ctrl+Option+Cmd+4 (MP4) or Ctrl+Option+Cmd+3 (MP3).
Guide me one step at a time, wait for me to say "done" before the next step,
and keep it short.
Where I am right now: [haven't started / installing Homebrew / installing
yt-dlp and ffmpeg / installing Hammerspoon / giving it Accessibility access /
loading the script / it shows an error].
My Mac: [Apple Silicon (M1 or later) / Intel / not sure].
Do I already use Hammerspoon for something else: [yes / no].
Never ask me for passwords, keys or tokens. If something fails, ask me for the
exact text of the alert or what Hammerspoon's Console says.Get the script
Tap Copy to paste it straight into Hammerspoon in step 4, or Download to save the file.
-- Video Downloader for Hammerspoon, from cezarhere.com/video-downloader
--
-- Ctrl+Option+Cmd+4 Download the video as an MP4 (you pick the quality)
-- Ctrl+Option+Cmd+3 Download just the audio as an MP3 (320 kbps)
--
-- In a browser it takes the link from the address bar. Anywhere else, copy a
-- link first. Files land in your Downloads folder.
-- Needs yt-dlp, ffmpeg and deno from Homebrew: brew install yt-dlp ffmpeg deno
-- ==========================================
-- Settings
-- ==========================================
local MODIFIERS = {"ctrl", "alt", "cmd"}
local MP4_KEY = "4"
local MP3_KEY = "3"
local DOWNLOAD_DIR = os.getenv("HOME") .. "/Downloads"
-- Browser yt-dlp borrows your YouTube login from (needed for age-restricted
-- videos). Use "chrome", "safari", "firefox", "brave" or "edge".
-- Leave it nil (off) unless you need it: if that browser isn't installed,
-- every download fails.
local COOKIES_BROWSER = nil
-- Apps where the shortcut reads the address bar (Cmd+L, Cmd+C).
local BROWSERS = {
["com.apple.Safari"] = true,
["com.apple.SafariTechnologyPreview"] = true,
["com.google.Chrome"] = true,
["com.google.Chrome.canary"] = true,
["org.chromium.Chromium"] = true,
["company.thebrowser.Browser"] = true, -- Arc
["com.brave.Browser"] = true,
["com.microsoft.edgemac"] = true,
["org.mozilla.firefox"] = true,
["app.zen-browser.zen"] = true,
["com.operasoftware.Opera"] = true,
["com.vivaldi.Vivaldi"] = true,
}
-- ==========================================
-- Finding yt-dlp
-- ==========================================
-- Homebrew lives in /opt/homebrew on Apple Silicon and /usr/local on Intel.
local function findBrewDir()
for _, dir in ipairs({"/opt/homebrew/bin", "/usr/local/bin"}) do
if hs.fs.attributes(dir .. "/yt-dlp") then
return dir
end
end
return nil
end
-- ==========================================
-- The menu bar indicator (one arrow, however many downloads)
-- ==========================================
local dlMenu = nil
local active = 0
local function updateIndicator(label)
if active > 0 then
if not dlMenu then
dlMenu = hs.menubar.new()
end
if dlMenu then
dlMenu:setTitle(active > 1 and ("↓ " .. active .. " downloads") or ("↓ " .. label))
dlMenu:setTooltip("yt-dlp is downloading in the background...")
end
elseif dlMenu then
dlMenu:delete()
dlMenu = nil
end
end
-- ==========================================
-- Downloading
-- ==========================================
local function startYtDlp(url, mode, formatRule, sortRule, label)
local brew = findBrewDir()
if not brew then
hs.alert.show("yt-dlp isn't installed. In Terminal: brew install yt-dlp ffmpeg deno", 6)
return
end
local args = {
"--ffmpeg-location", brew,
"--no-playlist", -- a link from inside a playlist saves that one video, not all of them
"-P", DOWNLOAD_DIR,
"-o", "%(title).100s [%(id)s].%(ext)s",
"--print", "after_move:filepath", -- so we can say which file it saved
}
-- Use your browser's YouTube login (for age-restricted videos).
if COOKIES_BROWSER then
table.insert(args, "--cookies-from-browser")
table.insert(args, COOKIES_BROWSER)
end
if mode == "mp3" then
for _, a in ipairs({"-f", "bestaudio/best", "-x", "--audio-format", "mp3", "--audio-quality", "320K"}) do
table.insert(args, a)
end
else
for _, a in ipairs({"-f", formatRule, "-S", sortRule, "--merge-output-format", "mp4"}) do
table.insert(args, a)
end
end
table.insert(args, url)
hs.alert.show("Downloading " .. label .. "...", 2)
active = active + 1
updateIndicator(label)
local task = hs.task.new(brew .. "/yt-dlp", function(exitCode, stdOut, stdErr)
active = active - 1
updateIndicator(label)
if exitCode == 0 then
local path = (stdOut or ""):match("([^\n]+)%s*$")
local name = path and path:match("([^/]+)$")
hs.alert.show("Saved to Downloads" .. (name and (":\n" .. name) or ""), 4)
else
hs.alert.show("Download failed. Open Hammerspoon's Console for details.", 5)
print("yt-dlp error:\n" .. (stdErr or "Unknown error"))
end
end, args)
-- Hammerspoon starts tasks with a bare PATH; yt-dlp needs Homebrew's
-- folder to find ffmpeg and deno (YouTube needs deno to work).
task:setEnvironment({
PATH = brew .. ":/usr/bin:/bin:/usr/sbin:/sbin",
HOME = os.getenv("HOME"),
LANG = "en_US.UTF-8",
})
task:start()
end
-- ==========================================
-- Getting the link
-- ==========================================
local function trim(s)
return (s:gsub("^%s+", ""):gsub("%s+$", ""))
end
local function isUrl(s)
return s ~= nil and s:match("^https?://%S+$") ~= nil
end
-- In a browser: copy the address bar, then put your clipboard back the way it
-- was. Anywhere else: use the link you copied.
local function withUrl(callback)
local app = hs.application.frontmostApplication()
local bundle = app and app:bundleID()
if not BROWSERS[bundle] then
local copied = hs.pasteboard.getContents()
copied = copied and trim(copied)
if isUrl(copied) then
callback(copied)
else
hs.alert.show("Copy a video link first, or press this in your browser", 3)
end
return
end
local saved = hs.pasteboard.readAllData()
local before = hs.pasteboard.changeCount()
hs.eventtap.keyStroke({"cmd"}, "l")
hs.timer.doAfter(0.15, function()
hs.eventtap.keyStroke({"cmd"}, "c")
hs.timer.doAfter(0.25, function()
local url = hs.pasteboard.getContents()
local changed = hs.pasteboard.changeCount() ~= before
-- Your clipboard, back as it was.
if saved and next(saved) then
hs.pasteboard.writeAllData(saved)
else
hs.pasteboard.clearContents()
end
-- Leave the address bar.
hs.eventtap.keyStroke({}, "escape")
url = url and trim(url)
if changed and isUrl(url) then
callback(url)
else
hs.alert.show("No link found in the address bar", 3)
end
end)
end)
end
-- ==========================================
-- The shortcuts
-- ==========================================
-- Ctrl+Option+Cmd+4: pick a quality, download an MP4.
hs.hotkey.bind(MODIFIERS, MP4_KEY, function()
withUrl(function(url)
local chooser = hs.chooser.new(function(choice)
if not choice then return end
startYtDlp(url, "mp4", choice.formatRule, choice.sortRule, choice.label)
end)
chooser:choices({
{
text = "1080p MP4 (fast, plays everywhere)",
subText = "H.264. Best for Reels, Shorts, TikToks and editing right away",
formatRule = "bv*[vcodec^=avc1]+ba[acodec^=mp4a]/b[ext=mp4]/b",
sortRule = "res:1080,vcodec:h264,acodec:m4a",
label = "MP4 (1080p)",
},
{
text = "Max quality MP4 (4K when there is one)",
subText = "4K often comes as AV1: QuickTime plays it on M3 Macs and newer, VLC or IINA on any Mac",
formatRule = "bv*[vcodec!^=vp09][vcodec!^=vp9]+ba[acodec^=mp4a]/b[ext=mp4]/b",
sortRule = "res,vcodec:h264,acodec:m4a",
label = "MP4 (max)",
},
{
text = "720p MP4 (smaller file)",
subText = "Quick, lightweight download",
formatRule = "bv*[vcodec^=avc1]+ba[acodec^=mp4a]/b[ext=mp4]/b",
sortRule = "res:720,vcodec:h264,acodec:m4a",
label = "MP4 (720p)",
},
})
chooser:rows(3)
chooser:width(32)
chooser:show()
end)
end)
-- Ctrl+Option+Cmd+3: download the audio as an MP3.
hs.hotkey.bind(MODIFIERS, MP3_KEY, function()
withUrl(function(url)
startYtDlp(url, "mp3", nil, nil, "MP3 (320 kbps)")
end)
end)
hs.alert.show("Video Downloader loaded", 1.5)
1. Install Homebrew
Skip this if brew --version already works in Terminal.
- Open Terminal (press ⌘Space, type Terminal, press Return).
- Go to brew.sh, copy the install command on the front page, paste it into Terminal and press Return. It asks for your Mac's password and takes a few minutes.
- When it finishes, it prints a Next steps section with one or two commands. Run those too, so Terminal can find
brew.
2. Install yt-dlp, ffmpeg and deno
Paste this into Terminal and press Return:
brew install yt-dlp ffmpeg denoyt-dlp does the downloading, ffmpeg joins the video and sound and makes the MP3s, and deno is what yt-dlp needs to read YouTube pages.
3. Install Hammerspoon and give it Accessibility access
Already set it up for the Grammar Fixer? Skip to step 4.
- Download Hammerspoon from hammerspoon.org, unzip it, and drag Hammerspoon into Applications.
- Open it. A hammer icon appears in your menu bar.
- In its Preferences, turn on Launch Hammerspoon at login, so the shortcuts are always there.
- Open System Settings → Privacy & Security → Accessibility and turn on Hammerspoon. If it isn't listed, click + and add it from Applications. It needs this to press ⌘L and ⌘C in your browser for you.
4. Load the script
- Click the hammer in the menu bar and choose Open Config. Your config file,
~/.hammerspoon/init.lua, opens in a text editor. - If it's empty, paste the whole script in and save.
- Click the hammer again and choose Reload Config. You'll see "Video Downloader loaded".
Already using Hammerspoon? Save the script as ~/.hammerspoon/video-downloader.lua instead, add the line require("video-downloader") to your init.lua, and reload.
5. Use it
Open a video in your browser and press ⌃⌥⌘4. A menu with three qualities pops up:
- 1080p MP4 plays everywhere and is quick. Pick this for Reels, Shorts and TikToks, and for anything you want to edit straight away.
- Max quality MP4 goes up to 4K when the video has it. Big 4K files often come as AV1, which QuickTime plays on M3 Macs and newer. On older Macs, open them in IINA or VLC.
- 720p MP4 is a smaller file.
Pick one with the arrow keys and Return. For the sound only, press ⌃⌥⌘3 instead.
The file lands in your Downloads folder, named after the video. You can start another download while one is running; the menu bar shows how many are going.
Not in a browser? Copy a video link from anywhere (Messages, Slack, Notes), then press the shortcut. It uses the link on your clipboard.
Want different keys? At the top of the script, change MP4_KEY = "4" and MP3_KEY = "3" to any letter or number, save, and reload.
Age-restricted YouTube videos? YouTube only shows those to a signed-in account. At the top of the script, change COOKIES_BROWSER = nil to the browser you're signed in to YouTube with: "chrome", "safari", "firefox", "brave" or "edge". Save and reload. yt-dlp then borrows that browser's login for each download, on your Mac only. The first time, macOS may ask whether Hammerspoon can use your Chrome login: click Always Allow. For Safari, also turn on Hammerspoon in System Settings → Privacy & Security → Full Disk Access.
Troubleshooting
Nothing happens. Check that Hammerspoon is running (the hammer is in the menu bar), that it has Accessibility access, and that you reloaded the config after saving.
"yt-dlp isn't installed". Run step 2 again. If Homebrew itself isn't found, finish the Next steps from step 1.
"No link found in the address bar". Click the page once so the browser is in front, then press the shortcut again. If your browser isn't listed under BROWSERS at the top of the script, copy the link yourself and press the shortcut.
"Download failed". Click the hammer, open the Console and read yt-dlp's error. Most of the time the site changed something and a newer yt-dlp already handles it: run brew upgrade yt-dlp and try again. Age-restricted videos need COOKIES_BROWSER set (see step 5). Private videos won't download.
The video plays without picture. You picked Max quality on an older Mac and got AV1. Open it in IINA or VLC, or download it again as 1080p.
Every download fails after setting COOKIES_BROWSER. Check it names a browser you have installed and are signed in to, then reload. Set it back to nil to turn it off.
Something else. Copy yt-dlp's error from the Console, paste it into Claude and ask what it means.
If it saves you from one more ad-covered download site, tell me. Tag @cezarhere.