Skip to content

Instantly share code, notes, and snippets.

@NicholasTD07
Forked from mertdumenci/download-nsscreencast.rb
Last active August 22, 2020 05:01
Show Gist options
  • Save NicholasTD07/9c37d3edd480ee35aad2 to your computer and use it in GitHub Desktop.
Save NicholasTD07/9c37d3edd480ee35aad2 to your computer and use it in GitHub Desktop.
# 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 END=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
start_at = ENV["START"].to_i
end_at = ENV["END"].to_i
Parallel.each((start_at..end_at)) 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)
path = "videos/#{raw_filename}"
video.save(path)
puts "Saved #{video_url} as #{path}"
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