From: Jos Backus Date: 2008-09-10T02:05:10+09:00 Subject: Re: [ANN] mp3scrape --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Thanks for this gem, Ara. Attached is a patch which changes mp3scrape to use Hpricot. It also prepends the supplied URL to relative URLs (that do not match with /^http:/). This allows mp3scrape to be used on pages such as http://staff.telkomsa.net/packages/SRPMS/openldap/ to download RPMs instead. Please let me know what you think. -- Jos Backus jos at catnook.com --SLDf9lqlvOQaIe6s Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="mp3scrape.patch" --- /usr/lib/ruby/gems/1.8/gems/mp3scrape-0.0.1/bin/mp3scrape- 2008-09-09 12:52:02.000000000 -0400 +++ /usr/lib/ruby/gems/1.8/gems/mp3scrape-0.0.1/bin/mp3scrape 2008-09-09 13:06:27.000000000 -0400 @@ -31,7 +31,7 @@ option("pattern", "p"){ description "specifiy the mp3 pattern" argument_required - default %|['"](http://[^\\s]+[^/\\s]+.mp3)["']| + default %|(http://[^\\s]+[^/\\s]+.mp3)| } option("basedir", "b"){ @@ -60,10 +60,23 @@ description "show the downloads that would be performed" } + def sources(uri) + doc = Hpricot(open(uri)) + links = doc/"//a" + links.map.map do |link| + href = link.attributes['href'] + next if href.nil? + unless href =~ /^http:/ + href = uri + '/' + href + end + href + end + end + def run uri = param["uri"].value pattern = %r/#{ param["pattern"].value }/ - srcs = open(uri.to_s).read.scan(pattern).flatten.compact + srcs = sources(uri.to_s).grep(pattern) if param["list"].given? puts srcs exit @@ -148,6 +161,13 @@ exit 1 end + begin + require "hpricot" + rescue LoadError + STDERR.puts "gem install hpricot" + exit 1 + end + STDERR.sync = STDOUT.sync = true trap("INT"){ exit! } --SLDf9lqlvOQaIe6s--