summaryrefslogtreecommitdiff
path: root/bucky2/rest/sendspace-single.pl
diff options
context:
space:
mode:
authorJules Laplace <carbon@melanarchy.org>2013-08-02 17:23:25 -0500
committerJules Laplace <carbon@melanarchy.org>2013-08-02 17:23:25 -0500
commite76b691e78e273226cba9284cb8cd22a423319ed (patch)
treea58d22f69869fe2bf3885f81bdda4952f87ff6d7 /bucky2/rest/sendspace-single.pl
parent753f60c7d4769fa72d3b910e491f37db6f130898 (diff)
bucky2
Diffstat (limited to 'bucky2/rest/sendspace-single.pl')
-rwxr-xr-xbucky2/rest/sendspace-single.pl70
1 files changed, 70 insertions, 0 deletions
diff --git a/bucky2/rest/sendspace-single.pl b/bucky2/rest/sendspace-single.pl
new file mode 100755
index 0000000..8d5e074
--- /dev/null
+++ b/bucky2/rest/sendspace-single.pl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+use lib "../lib";
+use Rest;
+my $browser = new Rest;
+my $BIN_WGET = "/usr/bin/wget";
+my ($WGET_SINGLE, $WGET_WEBPAGE) = & make_wget_commands;
+
+foreach my $sendspace_url (@ARGV)
+ {
+ my ($url_dl) = & sendspace_get($sendspace_url);
+ & dl($url_dl);
+ }
+exit;
+sub dl
+ {
+ my ($url) = @_;
+ return unless $url;
+ system($WGET_SINGLE . " " . $url);
+ }
+sub lemmingtrail_urls
+ {
+ my $lemmingtrail_url = "http://www.lemmingtrail.com/mb/207771/";
+ my $content = $browser->rest_get_raw($lemmingtrail_url);
+ my @urls = & html_scrape_urls($content, "sendspace.com");
+ return @urls;
+ }
+sub sendspace_get
+ {
+ my ($sendspace_url) = @_;
+ return unless $sendspace_url;
+ my $content = $browser->rest_post_raw($sendspace_url, {download=>"&nbsp;REGULAR DOWNLOAD&nbsp;"});
+ print "got content: " . length($content) . " bytes\n";
+ my @urls = & html_scrape_urls($content, "sendspace.com/dl");
+ return @urls;
+ }
+sub html_scrape_urls
+ {
+ my ($content, $valid_url_match) = @_;
+ my @lines = split "<a", $content;
+ my @urls = ();
+ foreach my $line (@lines)
+ {
+ next unless $line =~ /href=/;
+ $line =~ /href="([^"]+)"/;
+ # http://fs05n5.sendspace.com/dl/181e8d00c2955c7862d9a0d559c12cf1/4ade166e37a8af6c/bwbz9y/Sporelec.zip
+ my $url = $1;
+ next unless $url =~ /$valid_url_match/;
+ print "URL: " . $url ."\n";
+ push @urls, $url;
+ }
+ return @urls;
+ }
+sub make_wget_commands
+ {
+ my $ua = ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705)");
+ my $dp = $PROJECT || "wgetdir";
+
+ # -E = --html-extension
+ # -H = --span-hosts
+ # -k = --convert-links
+ # -K = --backup-converted
+ # -p = --page-requisite
+
+ my $SINGLE = "$BIN_WGET -erobots=off --user-agent='$ua' --directory-prefix=$dp";
+ my $WEBPAGE = "$BIN_WGET -erobots=off -d -o wgetlog " .
+ "--user-agent='$ua' -E -H -K -k -p --no-directories " .
+ "--directory-prefix=$dp";
+ return ($SINGLE, $WEBPAGE);
+ }
+1;