Created
January 8, 2014 00:40
-
-
Save orendon/8309611 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
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