Created
December 11, 2008 16:51
-
-
Save anonymous/34776 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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