Class: Cinch::Plugins::YouTube

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/you_tube.rb

Instance Method Summary collapse

Instance Method Details

#execute(m, query) ⇒ Object



17
18
19
20
21
22
# File 'lib/cinch/plugins/you_tube.rb', line 17

def execute(m, query)
  query.gsub! /\s/, '+'
  data = lookup(m, query)
  return m.reply "No results found for #{query}." if data.empty?
  result(m, data)
end

#lookup(m, terms) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cinch/plugins/you_tube.rb', line 24

def lookup(m, terms)
       = "0,4You1,0Tube"
      query = URI::encode(terms)
      doc = Nokogiri::XML(open("https://gdata.youtube.com/feeds/api/videos?q=%s" % query))
      info = doc.css("entry")
      results = []
   
      for i in info
        title = i.css("title").inner_text()
        content = i.css("content").inner_text()
        author = i.css("author").css("name").inner_text()
        url = i.css("id").inner_text().split("/")[-1]
     
        results.push("%s Title: %s | %s | By: %s | http://youtu.be/%s" % [, title, content, author, url])
  end
   
return results
end

#result(m, data) ⇒ Object



43
44
45
# File 'lib/cinch/plugins/you_tube.rb', line 43

def result(m, data)
      data[0..2].each{|i| m.reply i}
end