Sha256: afe4c8259f9c92610479425a95d7676a2a42281dd8b2ee5ef5465bee71acdeb5

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

#!/usr/bin/env ruby

require "iyoutu"
require 'tty-prompt'

#require 'clipboard'
#puts "Clipboard content: #{Clipboard.paste}"

if ARGV.length != 1
  STDERR.puts "Need an argument (URL to fetch)"
  exit 1
end

video_url = ARGV[0]

youtube_dl_path = "youtube-dl"

formats_out = %x{#{youtube_dl_path} -F #{video_url}}
formats = Iyoutu::YoutubeDLFormats.new(formats_out)
choices = formats.video_with_audio.map do |format|
  {
    name:  "#{format.extension}/#{format.resolution_note}",
    value: format.format_code
  }
end
choices << {
  name: "-> Download audio and video seperately",
  value: :separate
}
choices << Iyoutu::ABORT_CHOICE

prompt = TTY::Prompt.new
choice = prompt.select("Select format (audio and video combined)",
                        choices,
                        echo: false,
                        filter: true,
                        per_page: choices.length)

if choice == :abort
  exit 0
elsif choice == :separate
  video_choice = Iyoutu::user_choose_format(prompt,
                                            "Video format",
                                            formats.video_only)
  exit 0 if video_choice == :abort

  audio_choice = Iyoutu::user_choose_format(prompt,
                                            "Audio format",
                                            formats.audio_only)
  exit 0 if audio_choice == :abort

  exec "#{youtube_dl_path} -f #{video_choice}+#{audio_choice} #{video_url}"
else
  exec "#{youtube_dl_path} -f #{choice} #{video_url}"
end

exit 0

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iyoutu-0.1.0 exe/iyoutu