Upload Scripts

srrup.pl

#!/usr/bin/perl

use strict;
use warnings;
use v5.10;

use WWW::Mechanize;
use HTTP::Request::Common;
use HTML::TreeBuilder::XPath;

my $username = '';
my $password = '';

if (@ARGV < 1) {
  say STDERR "Usage: $0 file.srr [file.srr...]";
  exit 1;
}

my @files = @ARGV;

my $mech = WWW::Mechanize->new;  
$mech->post('http://www.srrdb.com/account/login', {
  username => $username,
  password => $password,
});

foreach (@files) {
  upload_srr($_);
};

sub upload_srr {
  my $file = shift;

  my $req = $mech->request(POST 'http://www.srrdb.com/upload', 
    Content_Type => 'form-data',
    Content => {
      file => [ $file ],
      upload => 'upload',
  });

  my $tree = HTML::TreeBuilder::XPath->new_from_content($req->decoded_content)->elementify;

  my $error = $tree->findvalue('//span[@class="error"]');
  if ($error) {
    say STDERR $error;
    exit 1;
  }

  say $tree->findvalue('//div[@class="oflow wName"');
}

srrup.py

#!/usr/bin/env python3

import sys
import os
import argparse

import requests

username = ""
password = ""

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("file", nargs="+")
    args = parser.parse_args()
    site = "https://www.srrdb.com/"
    s = requests.session()
    s.post(site + "account/login", data={"username": username, "password": password}) 
    if not "uid" in s.cookies:
        print("Login failed")
        sys.exit(1)
    for f in args.file:
        with open(f, "rb") as fh:
            r = s.post(
                    site + "release/upload",
                    files={"files[]": (os.path.basename(f), fh)},
                    headers={"X-Requested-With": "XMLHttpRequest"}
            )
        msg = r.json()["files"][0]["message"]
        print(msg)
        if r.json()["files"][0]["color"] == 0:
            print("Upload failed")
            sys.exit(1)

srrdb-uploader / srrdb.py

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License