Skip to content

Instantly share code, notes, and snippets.

@cyc115
Created March 1, 2020 19:37
Show Gist options
  • Save cyc115/1129ff4de088d703a660bc6c12ae3dd6 to your computer and use it in GitHub Desktop.
Save cyc115/1129ff4de088d703a660bc6c12ae3dd6 to your computer and use it in GitHub Desktop.
Download a list of pluralsight courses
#! ruby
require 'optparse'
require 'fileutils'
# Usage: pluralsight-course-dl.rb --input file.txt --output ~/Videos -u username -p password
# file.txt contains a list of urls that youtube-dl can donwload.
Options = {}
OptionParser.new do |opts|
opts.banner = "Usage: pluralsight-course-dl.rb --input file.txt --output ~/Videos -u username -p password \nyoutube-dl need to be installed"
opts.on("-i" , "--input FILE", "input file") do |v|
Options[:input_file] = v
end
opts.on("-o" , "--output FOLDER", "output folder") do |v|
Options[:output_folder] = v
end
opts.on("-u" , "--user USERNAME", "username") do |v|
Options[:user] = v
end
opts.on("-p" , "--pass PASSWORD", "password") do |v|
Options[:pass] = v
end
end.parse!
def make_dir(url)
fn = File.join(Options[:output_folder], url.split('/').last).strip!
FileUtils.mkdir_p(fn)
puts "make dir: #{fn}"
fn
end
def download(url, folder)
cmd = "youtube-dl --continue --username \"#{Options[:user]}\" --password \"#{Options[:pass]}\" --sleep-interval 120 --restrict-filenames -o \"#{folder.strip}/%(id)s-%(title)s.%(ext)s\" #{url}\""
# puts "#{cmd}"
system(cmd)
end
def read_from_file file_name
File
.readlines(file_name)
.select{ |l| !l.strip.start_with?("#") && !l.strip.empty?}
end
def main
download_size = read_from_file(Options[:input_file]).size
read_from_file(Options[:input_file]).each do |url|
folder_name = make_dir(url)
download(url, folder_name)
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment