#!/usr/bin/env ruby require 'net/http' require 'socket' Thread.abort_on_exception = true threads = [] line = File.open("links.dat") IO.foreach("links.dat") {|line| if %r{http://([^/]+)/([^/]+/+.+)}i =~ line domain,path = $1, $2 end web = TCPSocket.new(domain,"http") web.print "GET /"+path+" HTTP/1.0\n\n" web.print "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2" answer = web.gets(nil) web.close # for mp3 arr = answer.scan(/http:\/\/www.+mp3/) arr.each do |e| threads << Thread.new(e){|mp3| if %r{http://([^/]+)/([^/]+/+.+)/(.+mp3)}i =~ mp3 website,song,name = $1, $2, $3 end a=Net::HTTP.new(website,80) song_get = "/"+song+"/"+name puts "Fetching #{website}#{song_get}" resp, data = a.get(song_get,nil) puts "Got #{website}#{song_get}: #{resp.message}" open(name,'w'){|f| f.write(data)} } end } threads.each {|aThread| aThread.join}
You need to create an account or log in to post comments to this site.