Skip to content

Instantly share code, notes, and snippets.

@DR3WH0
Created August 17, 2013 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DR3WH0/6259121 to your computer and use it in GitHub Desktop.
Save DR3WH0/6259121 to your computer and use it in GitHub Desktop.
Auto-Resume script for the free Last.fm Web service. Documentation link in comments.
require 'selenium-webdriver'
def get_radio # station name
print "Enter artist/tag/track name: "
station = STDIN.gets.chomp
puts "Loading \'#{station}\' Radio in Firefox >> Please wait..."
return station
end
def load_radio(station) # in Firefox 'lastfm' profile
driver = Selenium::WebDriver.for :firefox, :profile => 'lastfm'
driver.manage.window.resize_to(580, 520)
driver.navigate.to "http://last.fm/listen/"
element = driver.find_element(:name, "name")
element.send_keys "#{station}"
element.submit
return driver
end
def resume_radio(driver) # when 'deaf ears' dialog appears
while (1) do
wait = Selenium::WebDriver::Wait.new(:timeout => 3960) # 70 min.
wait.until { driver.find_element(:class => "dialogButton") }
element = driver.find_element(:class, "dialogConfirm")
element.submit
next
end
end
station = get_radio
driver = load_radio(station)
stopper =
Thread.new do # end radio station
puts "Last.fm loaded >> AutoResume ON"
print "\nEnter \'quit\' to turn off AutoResume: "
loop do
Kernel.exit if gets =~ /quit/
end
end
resume_radio(driver)
@DR3WH0
Copy link
Author

DR3WH0 commented Aug 18, 2013

Brief description of requirements and usage here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment