Download images with MediaWiki API?
Asked Answered
S

2

7

Is it possible to download images from Wikipedia with MediaWiki API?

Seismic answered 19/9, 2012 at 17:38 Comment(1)
Are you looking for a specific image or set of images? The API will help you find say the images used on a page but you don't need the API to actually download the image. You just need to point your browser or curl or wget at the image URL.Magness
E
10

No, it is not possible to get the images via the API. Images in a MediaWiki are stored just in folders, not in a database and are not delivered dynamically (more information on that in the Manual:Image administration).

However, you can retrieve the URLs of those image files via the API. For example see the API:Allimages list or imageinfo property querymodules. Then you can download the files from those URLs with your favourite tool (curl, wget, whatever).

If your question is about downloading all images from Wikipedia, meta:data dumps would be a good start. You also may ask on the data-dump mailing list on how to sync with a repository like Wikimedia Commons.

Eductive answered 19/9, 2012 at 17:52 Comment(2)
This is not strictly true, private wikis force image requests to go via a PHP file that streams them only after an authentication check. And while MediaWiki defaults to storing on the file system, it does support alternative file backends.Ivanna
@Ivanna Thanks, I must have missed the link to Manual:Image Authorization. Still, regardless of the file backend, the API only will get you the location of the image file.Eductive
A
2

Given you know the file's name, no need for the API. This works:

# Curl download, -L: follow redirect, -C -: resume downloads, -O: keep filename
curl -L -C - -O http://commons.wikimedia.org/wiki/Special:FilePath/Example.jpg # Example.jpg
Amicable answered 7/11, 2021 at 21:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.