Skip to content

Instantly share code, notes, and snippets.

@mertdumenci
Created May 1, 2014 12:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mertdumenci/b74b440421247f1e5fe0 to your computer and use it in GitHub Desktop.
Save mertdumenci/b74b440421247f1e5fe0 to your computer and use it in GitHub Desktop.
Download NSScreencast videos for offline viewing in a batch
# Using this script downloads ALL the videos in NSScreencast.
# Use it wisely, it's extra load/bandwidth for the NSScreencast website.
# Usage: `EMAIL=your email PASSWORD=your password COUNT=how many videos should be downloaded? ruby download-nsscreencast.rb`
require "mechanize"
require "parallel"
mechanize = Mechanize.new
mechanize.post("https://www.nsscreencast.com/user_sessions", {"email" => ENV["EMAIL"], "password" => ENV["PASSWORD"]})
mechanize.pluggable_parser.default = Mechanize::Download
count = ENV["COUNT"].to_i
Parallel.each((1..count)) do |idx|
begin
video_url = "http://www.nsscreencast.com/episodes/#{idx}.mp4"
puts "Downloading #{video_url}"
video = mechanize.get(video_url)
raw_filename = File.basename(video.uri.path)
episode_number = raw_filename.split("-")[0].gsub("ns", "").gsub("nss", "").to_i
episode_name = raw_filename.split("-").drop(1).map(&:capitalize).join(" ")
video.save("videos/##{episode_number} - #{episode_name}")
puts "Saved #{video_url}"
rescue
puts "Couldn't save #{video_url}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment