Class: YoutubeAudio::PlayerResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/youtube_audio/player_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_raw, script_player_url: nil) ⇒ PlayerResponse

Returns a new instance of PlayerResponse.



8
9
10
11
# File 'lib/youtube_audio/player_response.rb', line 8

def initialize(response_raw, script_player_url: nil)
  @response_raw = response_raw
  @script_player_url = script_player_url
end

Instance Attribute Details

#script_player_urlObject (readonly)

Returns the value of attribute script_player_url.



5
6
7
# File 'lib/youtube_audio/player_response.rb', line 5

def script_player_url
  @script_player_url
end

Instance Method Details

#formatsObject



13
14
15
16
17
# File 'lib/youtube_audio/player_response.rb', line 13

def formats
  (@response_raw&.dig('streamingData', 'adaptiveFormats') || []).map do |f|
    to_youtube_format(f)
  end
end

#to_youtube_format(format_raw) ⇒ Object



19
20
21
# File 'lib/youtube_audio/player_response.rb', line 19

def to_youtube_format(format_raw)
  Format.new(format_raw, script_player_url: script_player_url)
end