Commons:Command-line upload

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

It is possible to upload to Wikimedia Commons using command-line tools.

Tools to upload local files[edit]

Script Dependencies Batch upload {{Information}} support
<tvar name=upload.pl>Nichalp's Upload Script</tvar> Perl Yes 7 licenses
<tvar name=anuta>Anuta</tvar> Perl, Python and csv_creator.pl Yes 7 licenses
<tvar name=simple-commons-uploader>Simple Commons Uploader</tvar> Python Yes only Cc-by-sa-2.0
<tvar name=upload.py>upload.py</tvar> from <tvar name=pywikibot>Pywikibot</tvar> Python No none

Nichalp's upload script[edit]

A Perl script that creates a CSV file with the list of photographs in a folder. Enter all information, such as description, licence, category, latitude, longitude and so on. Also embeds certain Exif data to the photograph such as GPS data, name, licence etc. In addition, you can also rotate and rename it on-the-fly.

Wmigda's upload script[edit]

A Python version of Nichalp's upload script but that is dependent on the upload.csv-file that one of Nichalp's two Perl script generates.

Requirement: At least Perl and Python and one of Nichalp's two scripts, see documentation for further details

Fastily's upload script[edit]

A Python program which can upload whole folders on your computer with basic information and a category (determined by the name of the enclosing folder).

Tools to upload files from other websites[edit]

Flickrripper[edit]

Flickrripper is a free Python program for easy upload of large numbers of images from Flickr to Wikimedia Commons. The program is documented in mw:Manual:Pywikibot/flickrripper.py.

Python Wikipedia Bot[edit]

The python framework includes various file upload tools. These tools require installing Python and the pywikibot framework. If each upload is checked prior to upload (see verifyDescription option below), it isn't considered a bot.

For detailed information on its usage:

To login with this tool, your configuration file needs the following settings.

family = 'commons'
mylang = 'commons'
usernames['commons']['commons'] = 'nick'

Usage:

Sample using pywikibot's UploadRobot in your own script
# -*- coding: utf-8  -*-

import sys

import pywikibot
from pywikibot.specialbots import UploadRobot

def complete_desc_and_upload(filename, pagetitle, desc, date, categories):
    #complete this once if applies to all files

    description = u"""{{Information
|Description    = {{en|1=""" + desc + """}}
|Source         = <!-- if applicable: {{own}} --->
|Author         = <!-- your name:  --->
|Date           = """ + date + """
|Permission     = 
|other_versions = 
}}
=={{int:license-header}}==
<!-- your license --->

""" + categories + """
[[Category:Taken with camera 123]]
"""
    url = [ filename ]
    keepFilename = False        #set to True to skip double-checking/editing destination filename
    verifyDescription = True    #set to False to skip double-checking/editing description => change to bot-mode
    targetSite = pywikibot.getSite('commons', 'commons')
    
    bot = UploadRobot(url, description=description, useFilename=pagetitle, keepFilename=keepFilename, verifyDescription=verifyDescription, targetSite=targetSite)
    bot.run()

def main(args):
    #list each file here
    
    filename    = """testimage-1.jpg"""
    pagetitle   = """testimage-1-from asdfasdfa.jpg"""
    desc        = """Mount St Helens viewed from ... in the rain"""
    date        = "2010-04-07"
    categories  = """[[Category:Locality]]
[[Category:Theme]]
[[Category:View type]]
[[Category:Feature1]]
[[Category:Feature2]]"""
    complete_desc_and_upload(filename, pagetitle, desc, date, categories)


    #sample with:  - local file name identical to file name at Commons
    #              - date as previous file
    #              - less quotes (no CR or " in fields)
    filename   = "testimage-2.jpg"
    pagetitle  = filename
    desc       = "Mount St Helens as seen from ... at sunset"
    categories = "[[Category:Locality]] [[Category:Theme]] [[Category:View type]] [[Category:Feature1]] [[Category:Feature2]]"
    complete_desc_and_upload(filename, pagetitle, desc, date, categories)
   

if __name__ == "__main__":
    try:
        main(sys.argv[1:])
    finally:
        pywikibot.stopme()

For other tools based on pywikipediabot, see multichill/bot and erfgoedbot.

BotClasses.php[edit]

Some bots, like User:BrooklynMuseumBot, were written in PHP based on BotClasses.php