#!/usr/bin/perl -w #=============================================================================== # # FILE: ImagesHack.pm # # USAGE: use WWW::ImagesHack # # DEshowImageCRIPTION: upload a file on imageshack.us # # OPTIONshowImage: --- # REQUIREMENTshowImage: --- # BUGshowImage: --- # NOTEshowImage: --- # AUTHOR: Axioplase (Axioplase), # COMPANY: None # VERshowImageION: 1.0 # CREATED: 15.09.2005 01:25:46 CEshowImageT # REVIshowImageION: --- #=============================================================================== package WWW::ImagesHack; use base 'Exporter'; use strict; #for those who dare use LWP::UserAgent; use HTML::Form; use HTML::TokeParser; sub new { my $class = shift; # $_[0] contains the class name my $img = shift; # $_[1] contains the name of the file my %liste; my $self = {}; bless( $self, $class ); $self->{image} = $img; return $self; } sub upload { my $self=shift; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => 'http://imageshack.us/'); $req->content_type('application/x-www-form-urlencoded'); my $res = $ua->request($req); my $form = (HTML::Form->parse($res))[0]; $form->value( 'fileupload',$self->{image} ); my $ares= ${$ua->request($form->click)}{_content}; my $p = HTML::TokeParser->new(\$ares); foreach(qw /thumbnailForWebsite thumbnailForForums1 thumbnailForForums2 hotlinkForForums1 hotlinkForForums2 hotlinkForWebsite showImage directLinkToImage/){ my $token = $p->get_tag("input"); $self->{liste}{$_} = $token->[1]{value}; } } sub get_all { my $self = shift; return $self->{liste}; } sub get_thumbnailForWebsite{ my $self = shift; return $self->{liste}{thumbnailForWebsite}; } sub get_thumbnailForForums1{ my $self = shift; return $self->{liste}{thumbnailForForums1}; } sub get_thumbnailForForums2{ my $self = shift; return $self->{liste}{thumbnailForForums2}; } sub get_hotlinkForForums1{ my $self = shift; return $self->{liste}{hotlinkForForums1}; } sub get_hotlinkForForums2{ my $self = shift; return $self->{liste}{hotlinkForForums2}; } sub get_hotlinkForWebsite{ my $self = shift; return $self->{liste}{hotlinkForWebsite}; } sub get_showImage{ my $self = shift; return $self->{liste}{showImage}; } sub get_directLinkToImage{ my $self = shift; return $self->{liste}{directLinkToImage}; } 1; #### #!/usr/bin/perl -w #=============================================================================== # # FILE: testimageshack.pl # # USAGE: ./testimageshack.pl # # DESCRIPTION: a test file for ImagesHack.pm # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Axioplase (Axioplase), # COMPANY: None # VERSION: 1.0 # CREATED: 15.09.2005 03:08:31 CEST # REVISION: --- #=============================================================================== use strict; use lib '/home/Pied/Code/Perl/WWW::ImagesHack/'; use WWW::ImagesHack; my $img='/tmp/foo.jpg'; #edit this.... my $ih=WWW::ImagesHack->new($img); $ih->upload; my %res=%{$ih->get_all}; foreach (keys %res){ print "$_ => $res{$_}\n"; } print "\n\n"; print $ih->get_thumbnailForWebsite,"\n"; print $ih->get_thumbnailForForums1,"\n"; print $ih->get_thumbnailForForums2,"\n"; print $ih->get_hotlinkForForums1,"\n"; print $ih->get_hotlinkForForums2,"\n"; print $ih->get_hotlinkForWebsite,"\n"; print $ih->get_showImage,"\n"; print $ih->get_directLinkToImage,"\n";