Class: YoutubeAudio::Search

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keywords) ⇒ Search

Returns a new instance of Search.



7
8
9
# File 'lib/youtube_audio/search.rb', line 7

def initialize(keywords)
  @keywords = keywords
end

Instance Attribute Details

#keywordsObject (readonly)

Returns the value of attribute keywords.



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

def keywords
  @keywords
end

Instance Method Details

#resultsObject



11
12
13
14
15
16
17
# File 'lib/youtube_audio/search.rb', line 11

def results
  selector = '.section-list li ol.item-section li .yt-lockup-tile'
  search_url = 'https://www.youtube.com/results?search_query='
  @results ||= agent.get(search_url + CGI.escape(keywords))
                    .search(selector)
                    .map { |element| to_search_item(element) }
end