- #!/usr/bin/perl
- use warnings;
- use strict;
- my $COOKIEFILE = '/home/fluff/curl_cookiejar';
- my $COMMENT = "put your TT comment here";
- my $CURL_BASE = <<EOF;
- <?php
- ini_set("error_reporting", E_ALL);
- function GET(\$url,\$referer = "",\$proxy="", \$header=false) {
- \$ch = curl_init();
- curl_setopt(\$ch, CURLOPT_URL,"\$url");
- curl_setopt(\$ch, CURLOPT_COOKIEJAR, '$COOKIEFILE');
- curl_setopt(\$ch, CURLOPT_COOKIEFILE, '$COOKIEFILE');
- if (\$referer != "")
- curl_setopt (\$ch, CURLOPT_REFERER, \$referer);
- if (\$proxy != "")
- {
- curl_setopt(\$ch, CURLOPT_PROXY, "");
- curl_setopt(\$ch, CURLOPT_HTTPPROXYTUNNEL,true);
- }
- if (\$header) {
- curl_setopt(\$ch, CURLOPT_HEADER, true);
- }
- curl_setopt(\$ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.1) Gecko/20090612 Firefox/ 3.5");
- curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, true);
- \$result = curl_exec(\$ch);
- curl_close(\$ch);
- return \$result;
- }
- function POST(\$url,\$data,\$referer = "",\$proxy="") {
- \$ch = curl_init();
- curl_setopt(\$ch, CURLOPT_URL,"\$url");
- if (\$referer != "")
- curl_setopt (\$ch, CURLOPT_REFERER, \$referer);
- curl_setopt(\$ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.1) Gecko/20090612 Firefox/ 3.5");
- if (\$proxy != "") {
- curl_setopt(\$ch, CURLOPT_PROXY, "");
- curl_setopt(\$ch, CURLOPT_HTTPPROXYTUNNEL,true);
- }
- curl_setopt(\$ch, CURLOPT_COOKIEJAR, '$COOKIEFILE');
- curl_setopt(\$ch, CURLOPT_COOKIEFILE, '$COOKIEFILE');
- curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt(\$ch, CURLOPT_POST, true );
- curl_setopt(\$ch, CURLOPT_POSTFIELDS, \$data );
- curl_setopt(\$ch, CURLOPT_HEADER, true);
- curl_setopt(\$ch, CURLOPT_HTTPHEADER, array('Expect:'));
- \$result = curl_exec(\$ch);
- curl_close(\$ch);
- return \$result;
- }
- EOF
- my $NYAA_POST_PHP = <<EOF;
- \$data = array(
- 'torrent'=>"\@___TORRENTFILE___",
- 'catid'=>"___CATID___",
- 'description'=>"Hi Lance",
- 'submit'=>"Upload",
- 'rules'=>"1",
- 'info'=>'',
- );
- \$a = POST("http://www.nyaatorrents.org/?page=upload",\$data,"http://www.nyaatorrents.org/?page=upload");
- if (preg_match('/Record-ID:\\s*(\\d+)/i', \$a, \$m))
- echo \$m[1];
- else
- echo "Couldn't post to Nyaatorrents";
- EOF
- my $TT_POST_PHP = <<EOF;
- POST("http://tokyotosho.info/new.php","type=___CATID___&url=".urlencode("___URL___")."&comment=".urlencode("___COMMENT___").
- "&countdown=156&website=&send=Submit+New+Torrent","http://tokyotosho.info/new.php");
- EOF
- my $JISHAKU_POST_PHP = <<EOF;
- GET(
- "http://www.jishaku.net/api.php?action=add&key=MAKEUPYOUROWNGODDAMNEDKEY&url=".urlencode('___URL___').
- "&website=&comment=".urlencode("___COMMENT___").
- "&category=___CATID___&translation=xx&nsfw=0&batch=0"
- );
- EOF
- sub get_category_id_nyaa {
- my $name = shift;
- return '1_11' if ($name eq 'anime');
- return '5_20' if ($name eq 'drama');
- return '5_22' if ($name eq 'music');
- return '1_11';
- }
- sub get_category_id_tt {
- my $name = shift;
- return '7' if ($name eq 'anime');
- return '9' if ($name eq 'music');
- return '8' if ($name eq 'drama');
- return '7';
- }
- sub get_category_id_jishaku {
- my $name = shift;
- return '1' if ($name eq 'anime');
- return '3' if ($name eq 'drama');
- return '5' if ($name eq 'music');
- return '1';
- }
- sub post_torrent_nyaa {
- my ($torrentfile, $catid, $count) = @_;
- $count = (defined($count)) ? $count+1 : 0;
- my $phpfile = '/tmp/nyaapost-temp'.time().'.php';
- open(PFILE, ">", $phpfile) or (print("couldn't write to $phpfile: $!\n\n") and return);
- print PFILE $CURL_BASE;
- my $np = $NYAA_POST_PHP;
- $np =~ s/___TORRENTFILE___/$torrentfile/;
- $np =~ s/___CATID___/$catid/;
- print PFILE $np;
- close(PFILE);
- my $tid = `php $phpfile`;
- #print "nyaapost returned: $tid\n";
- if ($tid !~ /^\d+$/) {
- return undef unless $count < 3;
- return post_torrent_nyaa($torrentfile, $catid, $count);
- }
- unlink($phpfile);
- return 'http://nyaatorrents.org/?page=download&tid='.$tid;
- }
- sub post_tt {
- my ($url, $catid) = @_;
- my $phpfile = '/tmp/tokyotosho-temp'.time().'.php';
- open(PFILE, ">", $phpfile) or (print("couldn't write to $phpfile: $!\n\n") and return);
- print PFILE $CURL_BASE;
- my $tt = $TT_POST_PHP;
- $tt =~ s/___URL___/$url/;
- $tt =~ s/___CATID___/$catid/;
- $tt =~ s/___COMMENT___/$COMMENT/;
- print PFILE $tt;
- close(PFILE);
- `php $phpfile`;
- unlink($phpfile);
- }
- sub post_jishaku {
- my ($url, $catid) = @_;
- my $phpfile = '/tmp/jishaku-temp'.time().'.php';
- open(PFILE, ">", $phpfile);
- print PFILE $CURL_BASE;
- my $j = $JISHAKU_POST_PHP;
- $j =~ s/___URL___/$url/;
- $j =~ s/___CATID___/$catid/;
- $j =~ s/___COMMENT___/$COMMENT/;
- print PFILE $j;
- close(PFILE);
- `php $phpfile`;
- unlink($phpfile);
- }