Have a bunch of megaupload links and ever felt the need for a simple, lightweight, text-based/command-line and eminently extensible script which does all the downloading for you?
Your search ends here!
Requirements
Your search ends here!
Requirements
- wget: which is present by default in almost linux distros
- ruby and nokogiri: These can be installed as shown here.
Steps
- Save the script as megaupload_dm.rb
- Make it executable using chmod +x megaupload_dm.rb
- Install the dependencies
- Dump all your megaupload links to a file named megaupload_list.txt in the current directory. You can also insert any content or comments in this file
- Tweak the LinkFile and OutputDirectory variables to your liking.
- Limit the download rate by adding --limit-rate=100k to the wget command at line #43 (optional)
- Run it using ./megaupload_dm.rb
- Your files are downloaded to ~/Downloads directory!
#!/usr/bin/env ruby
# Is the url a valid one?
def valid?(url)
url =~ %r|^http://www.megaupload.com/\?d=[a-zA-Z0-9]+$|
end
require 'rubygems'
require 'nokogiri'
require 'open-uri'
LinkFile = "./megaupload_list.txt"
OutputDirectory = "/home/vikas/Downloads"
TempFile = "/tmp/megaupload-tmp.html"
File.open(LinkFile, 'r') do |f|
f.each_line do |link|
link.strip!
next unless valid?(link)
begin
puts "Fetching information for #{link} ..."
`wget "#{link}" -U "Firefox/4.0.0" --quiet --output-document #{TempFile}`
doc = Nokogiri::HTML(File.read(TempFile))
# Filename and Direct Link
fname = doc.css("div.downl_main div.download_file_name").first.content
direct_link = doc.css("div.downl_main div.download_member_bl a").last.attributes['href'].value
# Actual download
puts "Downloading #{fname} ... \n"
`wget -c -P "#{OutputDirectory}" -U "Firefox/3.6.3" "#{direct_link}"`
puts "*********************************** DONE *******************************************"
puts "\n\n"
# Sleep 5 secs. Take some load off megaupload ;)
sleep 5
rescue
puts "ERROR! FileNotFound or otherwise; Skipping this file...."
puts "\n\n"
next
end
end
end
# Is the url a valid one?
def valid?(url)
url =~ %r|^http://www.megaupload.com/\?d=[a-zA-Z0-9]+$|
end
require 'rubygems'
require 'nokogiri'
require 'open-uri'
LinkFile = "./megaupload_list.txt"
OutputDirectory = "/home/vikas/Downloads"
TempFile = "/tmp/megaupload-tmp.html"
File.open(LinkFile, 'r') do |f|
f.each_line do |link|
link.strip!
next unless valid?(link)
begin
puts "Fetching information for #{link} ..."
`wget "#{link}" -U "Firefox/4.0.0" --quiet --output-document #{TempFile}`
doc = Nokogiri::HTML(File.read(TempFile))
# Filename and Direct Link
fname = doc.css("div.downl_main div.download_file_name").first.content
direct_link = doc.css("div.downl_main div.download_member_bl a").last.attributes['href'].value
# Actual download
puts "Downloading #{fname} ... \n"
`wget -c -P "#{OutputDirectory}" -U "Firefox/3.6.3" "#{direct_link}"`
puts "*********************************** DONE *******************************************"
puts "\n\n"
# Sleep 5 secs. Take some load off megaupload ;)
sleep 5
rescue
puts "ERROR! FileNotFound or otherwise; Skipping this file...."
puts "\n\n"
next
end
end
end
No comments:
Post a Comment