Skip to content

Instantly share code, notes, and snippets.

@luislee818
Created June 14, 2013 02:53
Show Gist options
  • Save luislee818/5779157 to your computer and use it in GitHub Desktop.
Save luislee818/5779157 to your computer and use it in GitHub Desktop.
Download RubyTapas episodes and files
require 'httpclient'
require 'nokogiri'
require 'fileutils'
def sanitize_file_name(file_name)
file_name.gsub(/[\*<>\[\]=\+"\\\/:;?]/, '_')
end
LOGIN_URL = 'https://rubytapas.dpdcart.com/subscriber/content'
URL_PREFIX = 'https://rubytapas.dpdcart.com'
USERNAME = ''
PASSWORD = ''
WGET_PATH = 'T:\Dropbox\Soft_Setup\UnxUtils\wget.exe'
SAVE_PATH = 'e:\\rubytapas'
client = HTTPClient.new
client.post LOGIN_URL, { username: USERNAME, password: PASSWORD }
content_form = client.get LOGIN_URL
content_form_doc = Nokogiri::HTML content_form.body
entries = content_form_doc.css '.blog-entry'
entries.each do |entry|
title = sanitize_file_name entry.css('h3').text
puts "Downloading #{title}"
directory_path = "#{SAVE_PATH}\\#{title}"
next if File.exists? directory_path
FileUtils.mkdir_p directory_path
href = entry.css('.content-post-meta a')[0].attributes['href'].value
entry_url = "#{URL_PREFIX}#{href}"
entry_detail_form = client.get entry_url
entry_detail_form_doc = Nokogiri::HTML entry_detail_form.body
download_anchors = entry_detail_form_doc.css('#blog-container .blog-entry ul li a')
download_anchors.each do |anchor|
file_name = sanitize_file_name anchor.text
#next if file_name.end_with? '.mp4'
file_download_href = anchor.attributes['href'].value
file_download_url = "#{URL_PREFIX}#{file_download_href}"
file_path = "#{directory_path}\\#{file_name}"
%x(#{WGET_PATH} --no-check-certificate #{file_download_url} -c -O \"#{file_path}.tmp\")
%x(mv \"#{file_path}.tmp\" \"#{file_path}\")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment