Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aninder/f7bdc8b3632451c64179a18d92a2cece to your computer and use it in GitHub Desktop.
Save aninder/f7bdc8b3632451c64179a18d92a2cece to your computer and use it in GitHub Desktop.
rupsy.ru goa current song details from discogs
require 'mechanize'
playlist = []
playlist_details = []
def find_more(song)
page=Mechanize.new.get("https://www.discogs.com/search/?q=#{song}")
links=page.search('#search_results .card').map{|f| f.search('a').first[:href]}
link = find_link(links)
if link
get_details("http://#{page.uri.host}#{link}")
else
nil
end
end
def get_details(link)
o = OpenStruct.new
page = Mechanize.new.get(link)
o.album = page.search('#profile_title').text.strip.gsub("\n",'').gsub(' ','')
o.rest = page.search(".profile .content").map{|h| "#{h.previous_element.text.strip.gsub("\n",'').gsub(' ','')} #{h.text.strip.gsub("\n",'').gsub(' ','')}"}
o
end
def find_link(links)
master_found=false
match=nil
links.each do |l|
if master_found
match = l
break
end
if l.match(/master/)
master_found = true
end
end
!master_found && links.size>0 ? links.first : match
end
loop do
page=Mechanize.new.post('http://www.rupsy.ru/_radio_goa_output.php');
song=page.search('b').first.text;
if(playlist.last != song)
playlist.push(song);
`say "#{song}"`
details = find_more(song)
if !details
puts "#{song} details not found".co_blink.red
puts "\n"
playlist_details.push([song, "details not found"]);
else
puts "#{song.co_fg_green}"
puts "Album: #{details.album}".co_fg_magenta
details.rest.each{|t| puts t.co_fg_magenta}
puts "\n"
playlist_details.push([song,details]);
end
end
sleep 30
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment