Class: Ghost::Caption::YoutubeCaption

Inherits:
Object
  • Object
show all
Defined in:
lib/caption/youtube_caption.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, language = 'en') ⇒ YoutubeCaption

Returns a new instance of YoutubeCaption.



8
9
10
11
# File 'lib/caption/youtube_caption.rb', line 8

def initialize(url, language = 'en')
  @url = url
  @language = language
end

Instance Method Details

#downloadObject



13
14
15
16
17
18
19
20
21
# File 'lib/caption/youtube_caption.rb', line 13

def download
  command = "yt-dlp --write-auto-sub --sub-lang #{@language} --skip-download #{@url}"
  stdout_str, stderr_str, status = Open3.capture3(command)
  if status.success?
    stdout_str
  else
    raise Ghost::Errors::CaptionError, "Error during caption download: #{stderr_str}"
  end
end