Skip to content

Instantly share code, notes, and snippets.

@ayosec
Last active January 16, 2016 02:54
Show Gist options
  • Save ayosec/83c87765aa46d227edb8 to your computer and use it in GitHub Desktop.
Save ayosec/83c87765aa46d227edb8 to your computer and use it in GitHub Desktop.
mpv with bestaudio/bestvideo
#!/usr/bin/env ruby
URL = ARGV.first || raise("Missing video URL")
audio = IO.popen(["youtube-dl", "-f", "bestaudio", "-g", URL])
video = IO.popen(["youtube-dl", "-f", "bestvideo", "-g", URL])
title = IO.popen(["youtube-dl", "-e", URL])
audio_url = audio.read.chomp
video_url = video.read.chomp
window_title = title.read.chomp
[audio, video, title].each {|cmd| Process.waitpid(cmd.pid) }
puts "\033[1m#{window_title}\033[m"
exec(
"mpv",
"--no-ytdl",
"--cache-secs=45",
"--title", window_title,
"--audio-file=#{audio_url}",
video_url
)
alias mpv-yt-bests='mpv --cache-secs=45 --ytdl-format=bestvideo+bestaudio'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment