dotfiles/bin/youtube
2020-06-03 08:31:58 -06:00

26 lines
514 B
Ruby
Executable File

#!/usr/bin/env ruby
require "uri"
module Clipboard
class << self
def paste
`pbpaste`.chomp
end
end
end
def parse_params(url)
url.query.split("&").each_with_object({}) do |param, acc|
key, value = *param.split("=", 2)
acc[key] = value
end
end
url = URI.parse Clipboard.paste
params = parse_params url
id = params.fetch("v") { raise "Probably not a youtube URL" }
clean_url = "https://www.youtube.com/watch?v=#{id}"
system "(cd ~/Downloads && youtube-dl -f best \"#{clean_url}\")"