Skip to content

Instantly share code, notes, and snippets.

@gf3
Forked from anonymous/shotweb.rb
Created Dec 11, 2008
Embed
What would you like to do?
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
BASE_URL = "http://www.kniteforcerevolution.com"
PAGE_URL = "#{BASE_URL}/music/"
FILE_URL = "#{BASE_URL}/file_download/"
pages = []
files = []
downloaded = []
doc = open(PAGE_URL) { |f| Hpricot(f) }
# Get pages
puts " [*] Loading pages..."
(doc/"/html/body//a").each do |link|
pages << link.attributes['href'] if link.attributes['href'] =~ /#{PAGE_URL}.?/i
end
pages = pages.reject{|p| p == PAGE_URL}
puts " finished loading #{pages.length} pages."
# Load links
puts " [*] Loading downlaods from pages..."
pages.each do |page|
page_doc = open(page) { |f| Hpricot(f) }
page_files = []
(page_doc/"/html/body//a").each do |link|
page_files << link.attributes['href'] if link.attributes['href'] =~ /#{FILE_URL}.*\.zip/i
end
puts " queued #{page_files.length} dowloads from #{page}"
files += page_files
end
files = files.uniq
puts " finished loading #{files.length} files."
# Download files
files.each do |file|
name = file.split(/\//).last
if File.exists? name
puts " [*] File already exists: #{name}"
else
puts " [*] Downloading #{downloaded.length+1} of #{files.length}: #{name}..."
pbar = nil
open("#{name}.tmp", "w").write open(file).read
File.rename "#{name}.tmp", name
puts " done."
end
downloaded << file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment