Skip to content

Instantly share code, notes, and snippets.

@nikhgupta
Created March 20, 2012 23:47
Show Gist options
  • Save nikhgupta/2142633 to your computer and use it in GitHub Desktop.
Save nikhgupta/2142633 to your computer and use it in GitHub Desktop.
RailsCasts: get a list of links to MP4 Version of the Episodes
#!/usr/bin/env /Users/nikhilgupta/.rvm/wrappers/ruby-1.9.3-p0@tools/ruby
# a tiny script that crawls 'railscasts.com' and stores the path to MP4 versions
# of the episodes in the file: 'downloads.txt'
# currently, set to track only the last 3 pages of the site's free section.
# you can then run: $(for tut in `cat downloads.txt`; do wget --continue $tut; done) to download them.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
def get_railscasts_episodes(pages, file)
pages = pages.to_i
raise "Not a valid integer" if pages.nil?
downloads = File.readlines(file)
while pages > 0 do
puts "Searching for Episodes on Page ##{pages} on RailsCasts.com"
doc = Nokogiri::HTML(open("http://railscasts.com/?type=free&page=#{pages}"))
doc.css('.episodes .main h2 a').each do |episode|
epidoc = Nokogiri::HTML(open("http://railscasts.com#{episode.attribute('href')}"))
epidoc.css('ul.downloads li a').each do |link|
link.attribute('href').to_s.scan(/.*\.mp4/) do | mp4link |
if downloads.include?("#{mp4link}\n")
puts "Already added: #{mp4link}"
else
File.open(file, 'a+') { |f1| f1.write("#{mp4link}\n") }
puts "New Download: #{mp4link}"
end
end
end
end
pages -= 1
end
end
get_railscasts_episodes 3, "downloads.txt"
@Utterer
Copy link

Utterer commented Jul 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment