class DetektorFm::Stream
Public Instance Methods
get_playlist_url()
click to toggle source
# File lib/detektorfm.rb, line 46 def get_playlist_url "#{@@PLAYLIST_URL}/#{get_stream_key}" end
get_stream_key()
click to toggle source
# File lib/detektorfm.rb, line 42 def get_stream_key "" end
get_stream_url(type = :mp3)
click to toggle source
# File lib/detektorfm.rb, line 50 def get_stream_url(type = :mp3) "#{@@STREAM_URL}/#{type}/#{get_stream_key}" end
most_played_artist()
click to toggle source
# File lib/detektorfm.rb, line 32 def most_played_artist artists = [] url = "#{get_playlist_url}" html_doc = Nokogiri::HTML(open(url)) html_doc.xpath('//ul[@class="tagcloud"]/li/a/text()').each do |a| artists << a.to_s.strip end return artists end
played(limit = 100) { |e, e, e| ... }
click to toggle source
# File lib/detektorfm.rb, line 15 def played(limit = 100) timetable = [] # only 100 are show per page, so iterate over page in case # limit >100 requested (limit/101+1).times do |i| url = "#{get_playlist_url}/P#{i*100}" html_doc = Nokogiri::HTML(open(url)) parse_htmldoc_played(html_doc) do |time, artist, title| timetable << {:time => time, :artist => artist, :title => title} end end timetable[0,limit].each do |e| yield e[:time], e[:artist], e[:title] end end
Private Instance Methods
parse_htmldoc_played(html_doc) { |time, artist, title| ... }
click to toggle source
# File lib/detektorfm.rb, line 55 def parse_htmldoc_played(html_doc) html_doc.xpath('//table[@class="timetable"]/tbody/tr').each do |row| time = row.xpath('td[@class="time"]/text()').to_s.strip #stream = row.xpath('td[@class="stream"]/a/text()').to_s.strip artist = row.xpath('td[@class="artist"]/a/text()').to_s.strip title = row.xpath('td[@class="title"]/text()').to_s.strip yield time, artist, title end end