User talk:Nichalp/Upload script

From Wikimedia Commons, the free media repository

Jump to: navigation, search
Evolution-tasks.png Pending tasks for Nichalp/Upload script: edit this list - add to watchlist - purge
  • Rewrite for PNG, SVG, OGG, PDF and GIF.
  • Combine for all
  • Mask password

Contents

[edit] Customisation

Many of the fields are unnecessary to most users. For example, I generally geocode in decimal degrees, and my images are referenced to N and E. Similarly I release my images under one licence. Hence, you can customise the scripts to automatically encode this. A little bit of Perl coding is necessary. Nichalp (talk) 07:49, 6 September 2008 (UTC)


[edit] About non-JPEG's

Is it possible to use this script to batch upload images, with the descriptions set as you do, without modifying the images, if the images are not jpeg's? Specifically, I have a large number of PNG's that I'd like to upload, along with similar descriptions for each one. No need to modify the file itself. Is that available? --DragoonWraith (talk) 19:27, 1 November 2008 (UTC)

Yes, it can be done, 2-3 lines of the code need to be changed. . Sorry, this page had got off my watchlist for no reason, therefore the delay. :( Give me a two days to respond. Nichalp (talk) 12:50, 9 November 2008 (UTC)
  1. In User:Nichalp/Upload script/csv creator.pl change
    @files = grep (/\.jpe?g$/i, readdir(DIR));
    • to
    @files = grep (/\.png$/i, readdir(DIR));
  2. In User:Nichalp/Upload script/upload.pl change
    $new_name .= ".jpg" unless $new_name =~ /\.jpe?g$/i; # adding JPG extn
    • to
    $new_name .= ".png" unless $new_name =~ /\.png$/i; # adding PNG extn
  3. Make sure that you add the categories, description, licence and date. That is needed. Rest you can leave blank.
  4. The date field will be blank (no EXIF values to pick up of course), so you would have to ensure that you add the date manually. If you have just one date to add, you could program the $date=(set the date) into the code:
  5. Before this line: $ignore_login_error=0; add $date="2008-11-09"; (PS Change the date to the current date you upload!)

Nichalp (talk) 13:06, 9 November 2008 (UTC)

[edit] Problems

I wasn't able to archive my goal with this script:

  • There seems to be problems with character sets. German Umlauts (ΓΌ) could be read from file names into CSV, but upload.pl couldn't find the files again
  • Licence type 0 was not reconized as valid (bug in upload.pl I think: permission_value > 0 should have been permission_value => 0)
  • Log on to Commons failed with the comment "You are trying to hack this script for other wikis". I changed the suggested value in the source, but finally I gave up altogether.

Nillerdk (talk) 01:17, 21 January 2009 (UTC)

Should be fixed now! Try version 1.2 of upload.pl, use it like this (adding "utf8" as argument #4). --- Best regards, Melancholie (talk) 10:35, 30 January 2009 (UTC)
Did you test it? I get errors like:
 C:\Documents and Settings\Nils\Desktop\upload1>perl upload.pl - - - utf8
Global symbol "$csv" requires explicit package name at upload.pl line 124.
Global symbol "$csv" requires explicit package name at upload.pl line 125.
Global symbol "$csv" requires explicit package name at upload.pl line 388.
Global symbol "$csv" requires explicit package name at upload.pl line 389.
Execution of upload.pl aborted due to compilation error
and
 Global symbol "$csv" requires explicit package name at upload.pl line 124.
Global symbol "$csv" requires explicit package name at upload.pl line 125.
Global symbol "$csv" requires explicit package name at upload.pl line 388.
Global symbol "$csv" requires explicit package name at upload.pl line 389.
Execution of upload.pl aborted due to compilation errors.
I give up... sorry. Faster to do it manually Nillerdk (talk) 08:46, 27 February 2009 (UTC)
Someone made a very silly mistake. $csv had been declared, but as my $csv within a subroutine. So the rest of the program will not know any variable like that. Hence the cryptic "requires explicit package" error. Change it into this:
#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});
}

Ger Hanssen (talk) 14:08, 20 March 2009 (UTC)
More fixes, otherwise you'll get an error when using permission value 1 or 7, of which the first is quite likely to be used.
#################################
#Permissions
	if ($permission_value == 0)	
            {
            defaultlicence:	 
            print "Enter custom permission: ";
            $licence = <STDIN>;
            $permission_value = $licence; # line added, Ger Hanssen 2009-03-20
            }
 	elsif (($permission_value >= 1) &&  ($permission_value <= 7)) # equal signs added, Ger Hanssen 2009-03-20
            {
            $licence= $permission[$permission_value];
            }
	else {print "Invalid licence\n"; goto defaultlicence;}

$exif_permission_text = $exif_permission_information[$permission_value];

Ger Hanssen (talk) 21:54, 20 March 2009 (UTC)

Thank you Ger Hanssen! @Nillerdk: The cause had been the first issue pointed out by Ger Hanssen (a silly copy&paste frivolity /o\). Unfortunately, the script seems to not have any active maintainer anymore, and I myself just do not have anything to upload and test with; furthermore I cannot (and thus did not) properly test it because the script execution aborts for me because of missing/unavailable exif module(s). Sorry! Because of this and that I will add this page to my RSS watchlist. @Ger Hanssen: I also have added/changed your second code changes to the original code, thanks again! --- Best regards, Melancholie (talk) 04:33, 26 March 2009 (UTC)

[edit] Cant find the file error

Hi, I get the error below when trying to run the upload script. Can some help me with it? --Jarekt (talk) 03:53, 1 May 2009 (UTC)

C:\Perl\images>C:\Perl\bin\perl upload.pl
Malformed UTF-8 character (unexpected continuation byte 0xa9, with no preceding start byte) at upload.pl line 713.
Malformed UTF-8 character (unexpected continuation byte 0xa9, with no preceding start byte) at upload.pl line 714.
Embedding Exif information to Joshua_Tree_-_Dandelion_1.jpg... Successful!
Uploading Joshua_Tree_-_Dandelion_1.jpg to the Wikimedia Commons.
Description: Joshua Tree National Park: Climbing Dandelion 5.10a route on Old Woman Rock in Hidden Valey Campground
Can't open file Joshua_Tree_-_Dandelion_1.jpg: No such file or directory at C:/Perl/lib/LWP/UserAgent.pm line 434

The last message says that file "Joshua_Tree_-_Dandelion_1.jpg" is missing where it was expected with that name, most probably because of the initial UTF-8 issue: This should be fixed with the new version (1.3.1), use that one. If the message still appears, please leave a note. To get it working then you may use the script in plain non-utf mode (if there are only ASCII characters in names (English)), see User:Nichalp/Upload_script#Executing_the_script. --- Best regards, Melancholie (talk) 13:51, 7 May 2009 (UTC)