Class: YoutubeCaptions::Captions

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/youtube-captions/captions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info:, lang:) ⇒ Captions

Returns a new instance of Captions.



9
10
11
12
# File 'lib/youtube-captions/captions.rb', line 9

def initialize(info:, lang:)
  @info = info
  @lang = lang
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



8
9
10
# File 'lib/youtube-captions/captions.rb', line 8

def info
  @info
end

#langObject (readonly)

Returns the value of attribute lang.



8
9
10
# File 'lib/youtube-captions/captions.rb', line 8

def lang
  @lang
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/youtube-captions/captions.rb', line 14

def call
  if lang.nil?
    lang_info = default_lang_info
  else
    lang_info = search_lang_info
  end

  return raise LangNotAvailableError.new("Lang no available") unless lang_info_has_base_url?(lang_info)

  response = self.class.get(lang_info["baseUrl"])
  captions = response["transcript"]["text"]

  clean_captions(captions)
end