Created
August 17, 2013 23:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brief description of requirements and usage here.