User:Ghanssen/Upload bot

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Upload bot[edit]

The Upload bot based on Nichalp's script that works can be found below.

I discovered that it has a major shortcoming. That is, it can re-upload any number of images without any problems, but any change of the page of the image itself is not easy to automate. The special upload page is just not designed to do that.

So I wrote another program that can edit the page of an image, change the textbox and save it. See below this one. If you want to try yourself: Put the script and the CSV-file (like the one at the very bottom) and the images to be uploaded in the same directory and it should work for you too.

Upload bot[edit]

#!/usr/bin/perl
# 		==================================================================
#		**      Date: 2009-01-30					**
#       	** 	Author:- Ger Hanssen:~ Wikibooks: [[nl:User:Ghanssen]]	**
# 		**	Filename:- upload.pl				        **
#		** 	Licence:- Published under the GPLv3 licence		**
# 		**	Revision:- 1.0  					**
#		**	Purpose: Read CSV file, format data as per wikisyntax,	**
# 		**		 then upload the file to Wikimedia commons. 	**
#		==================================================================  

# 		==================================================================
#		**				Headers				**
#		==================================================================

use strict;
use warnings;
use utf8; 
use Data::Dumper; 
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use HTTP::Cookies;
use HTTP::Request::Common;
use Encode qw(encode);
use Text::CSV_XS;
use Text::CSV::Encoded;
use Term::ReadKey;

#		==================================================================
#		**			Global declarations			**
#		==================================================================

#CSV Parser
my $csv;
if (defined $ARGV[3] && $ARGV[3] =~ /^UTF-?8$/i) {
    $csv = Text::CSV::Encoded->new({ encoding  => "utf8" });
} else {
    $csv = Text::CSV_XS->new({ binary => 1});
}

my $file = 'upload.csv';
if (defined $ARGV[0] && $ARGV[0] ne "-") {
    $file = $ARGV[0];
}
my $secure;
if (defined $ARGV[1] && $ARGV[1] eq "-s") {
    $secure = 1;
}
if (defined $ARGV[2] && $ARGV[2] eq "-d") {
    $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
}

# Login information
my $ignore_login_error;
my @responses;
my @response;
my $response;
my $eckey;
my (@ns_headers, $browser);

# Initializing values to picked from CSV file
my ($current_name, $description_language, $description, $description_language_2, $description_2, $description_language_3, $description_3,  $date, $author, $permission_value, $category_1, $category_2, $category_3, $category_4, $category_5, $other_version1, $other_version2, $other_information);
my ($year, $geo_parameters, $mastercategory, $photo_information, $flickr_self, $username, $password, $permission);
my @permission = ("user defined", "{{self|cc-by-sa-3.0,2.5,2.0,1.0|GFDL}}", "{{self|cc-by-sa-3.0}}", "{{self|cc-by-sa-3.0,2.5,2.0,1.0}}", "{{self|cc-by-sa-3.0|GFDL}}", "{{PD-self}}", "{{self|cc-pd}}", "{{self|cc-by-3.0}}"); # Storing permissions in an array
my ($licence, $information, $full_description,$metadata); 
my $err=0; # Errors: Zero indicates no error. If "1", the script 'dies' and forces you to enter the required parameters.

#Login information. You can directly store the $username variable if you wish by editing the line.
print "Enter your Commons username: ";
$username = <STDIN>;
chomp($username);
print "Enter your Commons password: ";
if ($secure) {
    ReadMode('noecho');
    $password = ReadLine(0);
    ReadMode('normal');
} else {
    $password = <STDIN>;
    chomp($password);
}
chomp ($username, $password);

# 		==================================================================
#		**			End global declarations			**
#		==================================================================

{# Begin integrity check block

# 		==================================================================
#		**			Part 1: Integrity check 		**
#		==================================================================

open(my $data, '<', $file) or die "Could not open '$file'\n";
<$data>;

while (my $line = <$data>) {
    chomp $line;
    if ($csv->parse($line)) {
        ($current_name, $description_language, $description, $description_language_2, $description_2, $description_language_3, $description_3, $date, $author, $permission_value, $category_1, $category_2, $category_3, $category_4, $category_5, $other_version1, $other_version2, $other_information) = $csv->fields();       

    # Check to see if compulsory fields "Description, Permissions, and Category" has been added. Warn and exit if not.
        if ($description eq ""){print "Please add a description to $current_name\n" ;$err=1;};

    #Permissions
        if ($permission_value eq "") {print "Please enter the permission details to $current_name\n";$err=1}
        elsif (($permission_value > 7) || ($permission_value < 0)) {print "Please enter a correct permissions value for $current_name\n"; $err=1;}
        elsif (($permission_value < 7) && ($permission_value >= 0)) {}
        else {print "Invalid permissions for $current_name\n";$err=1;}

    #Category check
        if ($category_1 eq ""){print "Please enter a category to $current_name\n"; $err=1;};

    } # End of if parser loop
    else {
        warn "Line could not be parsed: $line\n";
    }

} #End while loop
if ($err == 1) {die "\nExiting! Please add the above values and try again...\n\n";};

# 		==================================================================
#		** 			Testing login				**
#		==================================================================

$ignore_login_error=0;# should be obsolete due to wpSkipCookieCheck=1

$browser=LWP::UserAgent->new();
@ns_headers = (
   'User-Agent' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4',
   'Accept' => 'image/jpeg, image/pjpeg, */*',
   'Accept-Charset' => 'iso-8859-1,*,utf-8',
   'Accept-Language' => 'en-US',
);

$browser->cookie_jar({});

$response=$browser->post(
    "http://commons.wikimedia.org/w/index.php?title=Special:UserLogin&action=submitlogin&type=login",
    @ns_headers,
    Content_Type=>"application/x-www-form-urlencoded",
    Content_Encoding=>"utf-8",
    Content=>[
        wpName=>$username,
        wpPassword=>$password,
        wpRemember=>"1",
        wpSkipCookieCheck=>"1",
        wpLoginattempt=>"Log in"
    ]
);

# After logging in, we should be redirected to another page. 
# If we aren't, something is wrong.
if($response->code!=200 && $response->code!=302 && !$ignore_login_error) {
    print 
"Unable able to login. This could be due to:

* The username ($username) or password might be incorrect.
  Solution: Edit upload.pl.
* You are trying to hack this script for other wikis. The wiki you
  are uploading to has cookie check disabled.
  Solution: Try setting \$ignore_login_error to 1 in upload.pl.
 
Writing the login output from the server to debug.txt... ";
    open(DEBUG,">debug.txt") or die "Could not write file.\n";
    print DEBUG "Login output from the server:\n";
    print DEBUG "$response->as_string\n";
    print
"Done writing the login output from the server to debug.txt.\n";
    close(DEBUG);
    exit 1;
}

# 		==================================================================
#		**			End integrity check	 		**
#		==================================================================
}# End integrity check block

{# Begin formatting master block
# 		==================================================================
#		**			Integration	        		**
#		==================================================================

# Creating the gallery text file
open (GALLERY,">gallery.txt") or die "Could not write gallery file.\n";
print GALLERY "<gallery>\n";

open(my $data, '<', $file) or die "Could not open '$file'\n";
<$data>;
while (my $line = <$data>) {
    chomp $line;
    if ($csv->parse($line)) {
        ($current_name, $description_language, $description, $description_language_2, $description_2, $description_language_3, $description_3, $date, $author, $permission_value, $category_1, $category_2, $category_3, $category_4, $category_5, $other_version1, $other_version2, $other_information) = $csv->fields();
    $current_name=~s/\s/_/g; # converting spaces to underscores

    #################################
    #Permissions
    if ($permission_value == 0)	{
        defaultlicence:	 
        print "Enter custom permission: ";
        $licence = <STDIN>;
        $permission_value = $licence; 
        }
    elsif (($permission_value >= 1) &&  ($permission_value <= 7)) {
        $licence= $permission[$permission_value];
        }
    else {print "Invalid licence\n"; goto defaultlicence;}

    ##################################
    #Author
    my $computed_author;
    if ($author eq "") {
        $computed_author = $username;
    }
    else {
        $computed_author = "[[User:$username|$author]]";
    }

    ##################################
    #Formatting the Description parameter
    if ($description_language eq "") {$description_language = "en";}; # Default language set to English;
    
    $full_description = "{{$description_language|$description}}";
    if (($description_language_2 ne "") && ($description_2 ne "")) {
        $full_description .= "{{$description_language_2|$description_2}}"; 
    }
    if (($description_language_3 ne "") && ($description_3 ne "")) {
        $full_description .= "{{$description_language_3|$description_3}}";
    }

    ##################################
    # Categories: Combining all categories as one master category
    $mastercategory="[[Category:$category_1]]";
    if ($category_2 ne "") {$mastercategory.="\n[[Category:$category_2]]" ;}
    if ($category_3 ne "") {$mastercategory.="\n[[Category:$category_3]]" ;}
    if ($category_4 ne "") {$mastercategory.="\n[[Category:$category_4]]" ;}
    if ($category_5 ne "") {$mastercategory.="\n[[Category:$category_5]]" ;}
    $mastercategory.="\n[[Category:Files uploaded by Ger Hanssen's script]]";

    ##################################
    #Other versions
    my $other_versions = "";
    if (($other_version1 ne "") || ($other_version2 ne "")) {
        if ($other_version1 ne "") {
            $other_version1 = "\n* [[:Image:$other_version1|$other_version1]]";
        }
        if ($other_version2 ne "") {
            $other_version2 = "\n* [[:Image:$other_version1|$other_version1]]";
        }
        $other_versions = "$other_version1.$other_version2";
    }

    ##################################
    # Information template
    $information = "\n==Summary==";
    $information .= "\n{{Information";
    $information .= "\n| Description\t= $full_description";
    $information .= "\n| Source\t= Own work";
    $information .= "\n| Author\t= $computed_author";
    $information .= "\n| Date\t\t= $date";
    $information .= "\n| Permission\t= Free";
    $information .= "\n| Other versions= $other_versions\n}}\n";
    $metadata = $information;
    $metadata .= "\n==[[Commons:Copyright tags|Licensing]]==\n$licence\n$mastercategory";
    $metadata .= "\n<!-- Uploaded by Ger Hanssen's upload script. Contact Wikibooks [[nl:User:Ghanssen|Ger Hanssen]] for more information. -->";
    $metadata .= "\n<!-- Many thanks to [[User:Nichalp|Nichalp/Upload_script]] -->";

# 		==================================================================
#		**		Uploading images to commons	        	**
#		==================================================================

    print "Uploading $current_name to the Wikimedia Commons. ";      
    print "\nDescription: " . $description."\n";
    uploadfile:
    $eckey = encode('utf8',$metadata);
    if($eckey ne $metadata) {
        symlink("$metadata","$eckey");
    }
    #<just checking----------------
    #print "Continue? y/n  ";
    #my $continue = <STDIN>;
    #chomp($continue);
    #if ($continue ne "y") {die "Script aborted by user. "};
    #just checking---------------->
    $response=$browser->post(
        "http://commons.wikimedia.org/wiki/Special:Upload",
        @ns_headers,
        Content_Type=>'form-data',
        Content=> [
            wpUploadFile=>["$current_name"],
            wpDestFile=>["$current_name"],
            wpUploadDescription=>$eckey,
            wpWatchthis=>"1",
            wpIgnoreWarning=>"1",
            wpUpload=>"Upload file"
        ]
    );
    #wpUploadAffirm=>"1" (now obsolete)
    push @responses,$response->base;
    push @responses,$response->code;
    push @responses,$response->content;
    if($response->code!=200 && $response->code!=302) {
            print "Upload failed! Will try again. Output was:\n";
            print $response->as_string;
            goto uploadfile;
    } else {
            print "Uploaded successfully.\n";
    }

#-----------------------------------------------------------------------------------------------------------

#		==================================================================
#		**			   Gallery 		        	**
#		==================================================================

    #Just incase you need a gallery
    print GALLERY "[[Image:$current_name|$description]]\n";
    } # End of if loop
    else {
        warn "Line could not be parsed: $line\n";
    }

} # End of while loop

#Log file
print "All OK. Log written to debug.txt.\n";
open (DEBUG,">debug.txt") or die "Could not write debug file.\n";
foreach $response (@responses) {
    print DEBUG "\n-*-*-\n" . $response;
}
close (DEBUG);

#Closing the gallery
print GALLERY '</gallery>';
close(GALLERY);

print "\n ~*~ Thank you for using my script! -Ger Hanssen- ~*~\n";

} #End formatting master block

#-----------------------------------------------------------------------------------------------------------

__END__

Credits:
Wish to thank the following: 
1. User Eloquence (Erik Möller) File upload service script --> http://commons.wikimedia.org/wiki/Commons:File_upload_service -- Mercilessly hacked. :)
2. Phil Harvey's ExifTool --> http://www.sno.phy.queensu.ca/~phil/exiftool/
3. Thouroughly based on: Nicholas http://commons.wikimedia.org/wiki/User:Nichalp/Upload_script

Test bot[edit]

Look below for test.pl (waiting for a better name later). It's almost identical to the one above, but this one doesn't work. In order for it to work it requires a csv file with information about the files to be uploaded or changed. See below if you want to try yourself. Put the script and the CSV-file and the images to be adjusted in the same directory and it should work for you too.

The important part starts with 'Adjusting page content'. You can read the debug.txt after everything has worked and it will show no evident reason for not working.

#!/usr/bin/perl
# 		==================================================================
#		**      Date: 2009-01-30					**
#       	** 	Author:- Ger Hanssen:~ Wikibooks: [[nl:User:Ghanssen]]	**
# 		**	Filename:- test.pl				        **
#		** 	Licence:- Published under the GPLv3 licence		**
# 		**	Revision:- 1.0  					**
#		**	Purpose: Read CSV file, format data as per wikisyntax,	**
# 		**		 then upload the file to Wikimedia commons. 	**
#		==================================================================  

# 		==================================================================
#		**				Headers				**
#		==================================================================

use strict;
use warnings;
use utf8; 
use Data::Dumper; 
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use HTTP::Cookies;
use HTTP::Request::Common;
use Encode qw(encode);
use Text::CSV_XS;
use Text::CSV::Encoded;
use Term::ReadKey;

#		==================================================================
#		**			Global declarations			**
#		==================================================================

#CSV Parser
my $csv;
if (defined $ARGV[3] && $ARGV[3] =~ /^UTF-?8$/i) {
    $csv = Text::CSV::Encoded->new({ encoding  => "utf8" });
} else {
    $csv = Text::CSV_XS->new({ binary => 1});
}

my $file = 'upload.csv';
if (defined $ARGV[0] && $ARGV[0] ne "-") {
    $file = $ARGV[0];
}
my $secure;
if (defined $ARGV[1] && $ARGV[1] eq "-s") {
    $secure = 1;
}
if (defined $ARGV[2] && $ARGV[2] eq "-d") {
    $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
}

# Login information
my $ignore_login_error;
my @responses;
my @response;
my $response;
my $eckey;
my (@ns_headers, $browser);

# Initializing values to picked from CSV file
my ($current_name, $description_language, $description, $description_language_2, $description_2, $description_language_3, $description_3,  $date, $author, $permission_value, $category_1, $category_2, $category_3, $category_4, $category_5, $other_version1, $other_version2, $other_information);
my ($year, $geo_parameters, $mastercategory, $photo_information, $flickr_self, $username, $password, $permission);
my @permission = ("user defined", "{{self|cc-by-sa-3.0,2.5,2.0,1.0|GFDL}}", "{{self|cc-by-sa-3.0}}", "{{self|cc-by-sa-3.0,2.5,2.0,1.0}}", "{{self|cc-by-sa-3.0|GFDL}}", "{{PD-self}}", "{{self|cc-pd}}", "{{self|cc-by-3.0}}"); # Storing permissions in an array
my ($licence, $information, $full_description,$metadata); 
my $err=0; # Errors: Zero indicates no error. If "1", the script 'dies' and forces you to enter the required parameters.

#Login information. You can directly store the $username variable if you wish by editing the line.
print "Enter your Commons username: ";
$username = <STDIN>;
chomp($username);
print "Enter your Commons password: ";
if ($secure) {
    ReadMode('noecho');
    $password = ReadLine(0);
    ReadMode('normal');
} else {
    $password = <STDIN>;
    chomp($password);
}
chomp ($username, $password);

# 		==================================================================
#		**			End global declarations			**
#		==================================================================

{# Begin integrity check block

# 		==================================================================
#		**			Part 1: Integrity check 		**
#		==================================================================

open(my $data, '<', $file) or die "Could not open '$file'\n";
<$data>;

while (my $line = <$data>) {
    chomp $line;
    if ($csv->parse($line)) {
        ($current_name, $description_language, $description, $description_language_2, $description_2, $description_language_3, $description_3, $date, $author, $permission_value, $category_1, $category_2, $category_3, $category_4, $category_5, $other_version1, $other_version2, $other_information) = $csv->fields();       

    # Check to see if compulsory fields "Description, Permissions, and Category" has been added. Warn and exit if not.
        if ($description eq ""){print "Please add a description to $current_name\n" ;$err=1;};

    #Permissions
        if ($permission_value eq "") {print "Please enter the permission details to $current_name\n";$err=1}
        elsif (($permission_value > 7) || ($permission_value < 0)) {print "Please enter a correct permissions value for $current_name\n"; $err=1;}
        elsif (($permission_value < 7) && ($permission_value >= 0)) {}
        else {print "Invalid permissions for $current_name\n";$err=1;}

    #Category check
        if ($category_1 eq ""){print "Please enter a category to $current_name\n"; $err=1;};

    } # End of if parser loop
    else {
        warn "Line could not be parsed: $line\n";
    }

} #End while loop
if ($err == 1) {die "\nExiting! Please add the above values and try again...\n\n";};

# 		==================================================================
#		** 			Testing login				**
#		==================================================================

$ignore_login_error=0;# should be obsolete due to wpSkipCookieCheck=1

$browser=LWP::UserAgent->new();
@ns_headers = (
   'User-Agent' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4',
   'Accept' => 'image/jpeg, image/pjpeg, */*',
   'Accept-Charset' => 'iso-8859-1,*,utf-8',
   'Accept-Language' => 'en-US',
);

$browser->cookie_jar({});

$response=$browser->post(
    "http://commons.wikimedia.org/w/index.php?title=Special:UserLogin&action=submitlogin&type=login",
    @ns_headers,
    Content_Type=>"application/x-www-form-urlencoded",
    Content_Encoding=>"utf-8",
    Content=>[
        wpName=>$username,
        wpPassword=>$password,
        wpRemember=>"1",
        wpSkipCookieCheck=>"1",
        wpLoginattempt=>"Log in"
    ]
);

# After logging in, we should be redirected to another page. 
# If we aren't, something is wrong.
if($response->code!=200 && $response->code!=302 && !$ignore_login_error) {
    print 
"Unable able to login. This could be due to:

* The username ($username) or password might be incorrect.
  Solution: Edit upload.pl.
* You are trying to hack this script for other wikis. The wiki you
  are uploading to has cookie check disabled.
  Solution: Try setting \$ignore_login_error to 1 in upload.pl.
 
Writing the login output from the server to debug.txt... ";
    open(DEBUG,">debug.txt") or die "Could not write file.\n";
    print DEBUG "Login output from the server:\n";
    print DEBUG "$response->as_string\n";
    print
"Done writing the login output from the server to debug.txt.\n";
    close(DEBUG);
    exit 1;
}

# 		==================================================================
#		**			End integrity check	 		**
#		==================================================================
}# End integrity check block

{# Begin formatting master block
# 		==================================================================
#		**			Integration	        		**
#		==================================================================

# Creating the gallery text file
open (GALLERY,">gallery.txt") or die "Could not write gallery file.\n";
print GALLERY "<gallery>\n";

open(my $data, '<', $file) or die "Could not open '$file'\n";
<$data>;
while (my $line = <$data>) {
    chomp $line;
    if ($csv->parse($line)) {
        ($current_name, $description_language, $description, $description_language_2, $description_2, $description_language_3, $description_3, $date, $author, $permission_value, $category_1, $category_2, $category_3, $category_4, $category_5, $other_version1, $other_version2, $other_information) = $csv->fields();
    $current_name=~s/\s/_/g; # converting spaces to underscores

    #################################
    #Permissions
    if ($permission_value == 0)	{
        defaultlicence:	 
        print "Enter custom permission: ";
        $licence = <STDIN>;
        $permission_value = $licence; 
        }
    elsif (($permission_value >= 1) &&  ($permission_value <= 7)) {
        $licence= $permission[$permission_value];
        }
    else {print "Invalid licence\n"; goto defaultlicence;}

    ##################################
    #Author
    my $computed_author;
    if ($author eq "") {
        $computed_author = $username;
    }
    else {
        $computed_author = "[[User:$username|$author]]";
    }

    ##################################
    #Formatting the Description parameter
    if ($description_language eq "") {$description_language = "en";}; # Default language set to English;
    
    $full_description = "{{$description_language|$description}}";
    if (($description_language_2 ne "") && ($description_2 ne "")) {
        $full_description .= "{{$description_language_2|$description_2}}"; 
    }
    if (($description_language_3 ne "") && ($description_3 ne "")) {
        $full_description .= "{{$description_language_3|$description_3}}";
    }

    ##################################
    # Categories: Combining all categories as one master category
    $mastercategory="[[Category:$category_1]]";
    if ($category_2 ne "") {$mastercategory.="\n[[Category:$category_2]]" ;}
    if ($category_3 ne "") {$mastercategory.="\n[[Category:$category_3]]" ;}
    if ($category_4 ne "") {$mastercategory.="\n[[Category:$category_4]]" ;}
    if ($category_5 ne "") {$mastercategory.="\n[[Category:$category_5]]" ;}
    $mastercategory.="\n[[Category:Files uploaded by Ger Hanssen's script]]";

    ##################################
    #Other versions
    my $other_versions = "";
    if (($other_version1 ne "") || ($other_version2 ne "")) {
        if ($other_version1 ne "") {
            $other_version1 = "\n* [[:Image:$other_version1|$other_version1]]";
        }
        if ($other_version2 ne "") {
            $other_version2 = "\n* [[:Image:$other_version1|$other_version1]]";
        }
        $other_versions = "$other_version1.$other_version2";
    }

    ##################################
    # Information template
    $information = "\n==Summary==";
    $information .= "\n{{Information";
    $information .= "\n| Description\t= $full_description";
    $information .= "\n| Source\t= Own work";
    $information .= "\n| Author\t= $computed_author";
    $information .= "\n| Date\t\t= $date";
    $information .= "\n| Permission\t= Free";
    $information .= "\n| Other versions= $other_versions\n}}\n";
    $metadata = $information;
    $metadata .= "\n==[[Commons:Copyright tags|Licensing]]==\n$licence\n$mastercategory";
    $metadata .= "\n<!-- Uploaded by Ger Hanssen's upload script. Contact Wikibooks [[nl:User:Ghanssen|Ger Hanssen]] for more information. -->";
    $metadata .= "\n<!-- Many thanks to [[User:Nichalp|Nichalp/Upload_script]] -->";

# 		==================================================================
#		**	Adjusting page content of image in commons		**
#		==================================================================

    print "Adjusting $current_name in the Wikimedia Commons. ";      
    print "\nDescription: " . $description."\n";
    adjustfile:
    $eckey = encode('utf8',$metadata);
    if($eckey ne $metadata) {
        symlink("$metadata","$eckey");
    }
    #<just checking----------------
    #print "Continue? y/n  ";
    #my $continue = <STDIN>;
    #chomp($continue);
    #if ($continue ne "y") {die "Script aborted by user. "};
    #just checking---------------->
    #$response=$browser->get(
    #    "http://commons.wikimedia.org/w/index.php?title=File:$current_name&action=edit"
    #);
    $response=$browser->post(
        "http://commons.wikimedia.org/w/index.php?title=File:$current_name&action=submit",
        @ns_headers,
        Content_Type=>'form-data',
        Content=> [
            'wpTextbox1'=>$eckey,
            'wpWatchthis'=>"1",
            'wpSave'=>"Save page"
        ]
    );
    push @responses,$response->base;
    push @responses,$response->code;
    push @responses,$response->content;
    if($response->code!=200 && $response->code!=302) {
            print "Upload failed! Will try again. Output was:\n";
            print "\n#########\n#code:\n";
            print $response->code;
            print "\n#########\n#as_string:\n";
            print $response->as_string;
            goto adjustfile;
    } else {
            print "Adjusting succeeded.\n";
    }

#-----------------------------------------------------------------------------------------------------------

#		==================================================================
#		**			   Gallery 		        	**
#		==================================================================

    #Just incase you need a gallery
    print GALLERY "[[Image:$current_name|$description]]\n";
    } # End of if loop
    else {
        warn "Line could not be parsed: $line\n";
    }

} # End of while loop

#Log file
print "All OK. Log written to debug.txt.\n";
open (DEBUG,">debug.txt") or die "Could not write debug file.\n";
foreach $response (@responses) {
    print DEBUG "\n-*-*-\n" . $response;
}
close (DEBUG);

#Closing the gallery
print GALLERY '</gallery>';
close(GALLERY);

print "\n ~*~ Thank you for using my script! -Ger Hanssen ~*~\n";

} #End formatting master block

#-----------------------------------------------------------------------------------------------------------

__END__

Upload.csv[edit]

"Current name","Description lang","Description","Description lang 2","Description 2","Description lang 3","Description 3","Date","Author name","Permissions","Category1","Category2","Category3","Category4","Category5","Other versions 1","Other versions 2","Other information"
"gocursus-dia1-1.png",,"Go Course dia 1.1","nl","Go Cursus dia 1.1",,,"apr 2009","Ger Hanssen",1,"Go theory",,,,,,,"created using GOWrite 2"
"gocursus-dia1-2.png",,"Go Course dia 1.2","nl","Go Cursus dia 1.2",,,"apr 2009","Ger Hanssen",1,"Go theory",,,,,,,"created using GOWrite 2"