-
-
Save jaseemabid/4313649 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
#!/usr/bin/env ruby | |
require "nokogiri" | |
require "open-uri" | |
def download(url, output_file) | |
exit unless system("wget -c #{url} --load-cookies=cookies.txt -O #{output_file}") | |
end | |
def download_pages | |
(1..35).each do |i| | |
download "http://railscasts.com/?page=#{i}", "pages/page#{i}.html" | |
end | |
end | |
def extract_episode_links | |
links = [] | |
Dir["pages/*.html"].each do |page_html| | |
doc = Nokogiri::HTML(open(page_html)) | |
doc.css("div.episode h2 a").each do |link| | |
links << "http://railscasts.com#{link['href']}".tap { |l| puts l } | |
end | |
end | |
links | |
end | |
def extract_episode_name(episode_link) | |
episode_link.match(/.*\/(.+)/)[1] | |
end | |
def download_episode_pages(episode_link) | |
download episode_link, "episode_pages/#{extract_episode_name(episode_link)}.html" | |
end | |
def extract_mp4_links | |
links = [] | |
Dir["episode_pages/*.html"].each do |page_html| | |
# puts page_html | |
doc = Nokogiri::HTML(open(page_html)) | |
doc.css("a").each do |link| | |
links << link['href'].tap { |link| puts link } if link['href'] =~ /mp4$/ | |
end | |
end | |
links | |
end | |
trap(:INT) { | |
puts "INT signal caught, now exiting" | |
exit | |
} | |
# extract_episode_links.each { |link| download_episode_pages(link) } | |
# puts extract_episode_name("http://media.railscasts.com/assets/episodes/videos/099-complex-partials.mp4") | |
extract_mp4_links.each { |link| download link, "videos/#{extract_episode_name(link)}" } | |
# puts extract_episode_name("http://railscasts.com/episodes/90-fragment-caching-revised") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment