Created
July 19, 2013 22:42
-
-
Save eyenx/6042891 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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