Created
August 28, 2010 05:04
-
-
Save mateomurphy/554751 to your computer and use it in GitHub Desktop.
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 'net/http' | |
def check_response(response, expected) | |
raise "Unexpected response from server: #{response.code} #{response.message}" unless response.is_a?(expected) | |
end | |
def get_actual_download_url(download_url) | |
puts "requesting #{download_url}" | |
url = URI.parse(download_url) | |
response = Net::HTTP.start(url.host, url.port) { |http| http.get(url.path) } | |
check_response(response, Net::HTTPRedirection) | |
response['location'] | |
end | |
def get_response(actual_download_url) | |
puts "requesting #{actual_download_url}" | |
url = URI.parse(actual_download_url) | |
response = Net::HTTP.start(url.host, url.port) { |http| http.head(url.path) } | |
check_response(response, Net::HTTPSuccess) | |
response | |
end | |
download_url = "http://soundcloud.com/omegadubstep/pink-floyd-brain-damage-omega-remix-v1-free-320-download/download" | |
actual_download_url = get_actual_download_url(download_url) | |
response = get_response(actual_download_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment