Pages

08 November 2012

mediafire.pl [Mediafire Downloader]

#!/usr/bin/perl

# mediafire folder download script
# designed to download the contents of a folder on mediafire
# it's actually kind of slow, but that's mediafire's fault
# unsure if downloading portion has error or if that's the uploader's fault 
# but not all archives arrive intact
# provides:
#	 &list_contents(mediafire_folder_id)
#	 &mfget(mediafire_download_id)
# will prompt for captcha once every ~6 downloads unfortunately, delays 80 seconds between dls
# names files by mediafire id since url-encoded utf8 strings are retarded
# :3c

use strict;
use warnings "all";
use LWP::UserAgent;

my $ua = LWP::UserAgent->new(agent=>'loldongs/1.0',timeout=>'15',show_progress=>'1');
my $method = "wget"; #wget or lwp

&list_contents('1h0h4dsc2b0y2');

sub list_contents {
	my $folder = shift(@_);
	my $res = $ua->get("http://www.mediafire.com/api/folder/get_content.php?r=plwp&content_type=files&filter=all&order_by=name&order_direction=asc&version=2&folder_key=" . $folder . "&response_format=json");
	if ($res->is_success) {
		my $content = $res->decoded_content;
		my @links;
		while ($content=~s/"quickkey":"(.+?)","filename":"(.+?)",//) {
			my $link = $1; my $name = $2;
			if ($name=~/flac/i) { next; }
			push @links, $1;
		}
		my $total = scalar(@links);
		$total--;
		for (0..$total) {
			print "[$_ / $total] http://www.mediafire.com/?" . $links[$_] . "\n";
			&mfget($links[$_]);
		}
	}
}

sub mfget {
	my $id = shift(@_);
	my $res = $ua->get("http://www.mediafire.com/?" . $id);
	if ($res->decoded_content=~m|= "(http://.+?/[0-9a-z]{12}/$id/.+?)";|) {
		my $url = $1;
		my $ext = $url;
		$ext=~s/^.+\.//; #get only the extension
		if ($method eq "lwp") {
			$ua->get($url,":content_file" => $id . $ext);
		} elsif ($method eq "wget") {
			system("wget -U 'loldongs/1.0' $url");
		}
		{$| = 1; for (1..80) { print "#"; sleep(1); } }
	} else {
		print "OH NO IT'S A CAPTCHA!!!\n";
		system("start http://www.mediafire.com/?" . $id);
		system("pause");
		&mfget($id);
	}
}

0 comments: