Skip to content

Instantly share code, notes, and snippets.

@orendon
Created January 8, 2014 00:40
Show Gist options
  • Save orendon/8309611 to your computer and use it in GitHub Desktop.
Save orendon/8309611 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'pry'
class RailscastsScanner
end
uri = URI("http://railscasts.com/episodes/407")
Net::HTTP.start uri.host, uri.port do |http|
resp = http.head uri.path
case resp.code
when "404"
raise "URL doesn't exist"
when "302"
url = resp['location']
@name = File.basename url
@name = "0#{@name}" if @name =~ /^\d{2}-.*/
else
raise "Unknown HTTP code #{resp.code}"
end
end
sub_uid="41TjtXC14dnMq0aFyllyKw"
uri = URI("http://media.railscasts.com")
pro_path = "/assets/subscriptions/#{sub_uid}/videos/#{@name}.webm"
free_path = "/assets/episodes/videos/#{@name}.webm"
Net::HTTP.start uri.host, uri.port do |http|
resp = http.head pro_path
if resp.code == "200"
puts "pro episode"
exit
end
resp = http.head free_path
if resp.code == "200"
puts "free episode"
end
puts resp.code
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment