Skip to content

Instantly share code, notes, and snippets.

@eyenx
Created July 19, 2013 22:42
Show Gist options
  • Select an option

  • Save eyenx/6042891 to your computer and use it in GitHub Desktop.

Select an option

Save eyenx/6042891 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
### ompldr upload script
use v5.14;
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
## def
my $url="http://ompldr.org/upload";
# usage sub
sub usage(){
say "ompldr.pl - Upload files to http://ompldr.org";
say "Usage:";
say "ompldr.pl <filename>";
exit 1;
}
## test params
if (@ARGV != 1){
usage();
}
## test file
my $file=shift;
if (! -e $file){
say "File does not exist!\n";
usage();
}
# upload file, get output
my $ua=LWP::UserAgent->new(agent=>'Mozilla/5.0');
my $rsp=$ua->request(POST $url, Content_Type=>"multipart/form-data",Content=>[file1=>[$file]]);
my $out;
if ($rsp->is_success){
$out=$rsp->decoded_content;
}
else {
say "there was something wrong";
exit 1;
}
my @outl=split /\n/, $out;
# get data
my %outhash;
foreach (@outl){
if ( $_=~/w file:.*(http:.*)<\/a>/){
$outhash{'url'}=$1;
}
elsif ($_=~/Thumbnail:.*(http:.*)<\/a>/){
$outhash{'thumb'}=$1;
}
elsif ($_=~/BBCode:.*(\[url.*\])<\/div>/){
$outhash{'bbcode'}=$1;
}
elsif ($_=~/Info:.*(http.*)<\/a>/){
$outhash{'info'}=$1;
}
}
if ( keys %outhash < 1){
say "ERROR\n";
say "there was something wrong";
exit 1;
}
# output it
say "ompldr.org upload successfull!\n";
say "InfoUrl:\t".$outhash{'info'};
say "ImageUrl:\t".$outhash{'url'};
say "Thumbnail:\t".$outhash{'thumb'};
say "BBCode:\t\t".$outhash{'bbcode'};
say "\nThe BBCode and ImageUrl were xclipped";
# xclip it
system("echo ".$outhash{'bbcode'}."|xclip -i -se c");
system("echo ".$outhash{'url'}."|xclip -i -se p");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment