Class: YoutubeCrawler::Search
- Inherits:
-
Object
- Object
- YoutubeCrawler::Search
- Defined in:
- lib/youtube/crawler.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #auth ⇒ Object
-
#initialize(opts) ⇒ Search
constructor
A new instance of Search.
- #launch_player(player = 'vlc') ⇒ Object
- #query(query, max_results = 5) ⇒ Object
- #run ⇒ Object
- #user_input ⇒ Object
Constructor Details
#initialize(opts) ⇒ Search
Returns a new instance of Search.
13 14 15 16 17 18 |
# File 'lib/youtube/crawler.rb', line 13 def initialize(opts) = opts [:search] = opts[:search] || 'default search' [:max_results] = opts[:max_results] || 5 [:player] = opts[:player] || 'vlc' end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/youtube/crawler.rb', line 11 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/youtube/crawler.rb', line 11 def end |
Instance Method Details
#auth ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/youtube/crawler.rb', line 38 def auth # Change to single acc, pw prompting and save to file @client = YouTubeIt::Client.new( :username => KEYS['username'], :password => KEYS['password'], :dev_key => KEYS['key']) end |
#launch_player(player = 'vlc') ⇒ Object
51 52 53 |
# File 'lib/youtube/crawler.rb', line 51 def launch_player(player = 'vlc') system("#{player} #{@hash[@num.to_i]}") end |
#query(query, max_results = 5) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/youtube/crawler.rb', line 27 def query(query, max_results = 5) @number = 0 @hash = Hash.new @result = @client.videos_by(:query => query, :max_results => max_results) @result.videos.each do |x| @number += 1 puts "#{@number}: #{x.title}" @hash[@number] = x.player_url end end |
#run ⇒ Object
20 21 22 23 24 25 |
# File 'lib/youtube/crawler.rb', line 20 def run auth query([:search], [:max_results]) user_input launch_player([:player]) end |
#user_input ⇒ Object
46 47 48 49 |
# File 'lib/youtube/crawler.rb', line 46 def user_input puts 'What video(by number)?: ' @num = $stdin.gets end |