Searching for files in Wikimedia / Wikipedia

382 views Asked by At

I'm trying to search for specific file types in Wikimedia commons API with not much of luck.

Current status: I'm currently able to fetch images with jpeg, png, svg formats normally using this query

https://commons.wikimedia.org/w/api.php?action=query&generator=search&gsrnamespace=0|6&gsrsearch=searchTerm&gsrlimit=30&prop=imageinfo&iiprop=url|mime|thumbmime&iiurlwidth=400px&format=json

Where i'm searching in namespaces 0,6 for the term "searchTerm" which returns images in the mentioned format.

However I'm having alot of trouble filtering out specific file types, for example I need to return only GIF Files ( in .gif format ) or even video/audios. I cannot find that documented anywhere.

A current hack i'm using is a regex in the searchterm and it somehow parses it ( with low accuracy though )

?action=query&generator=search&gsrnamespace=0|6&gsrsearch=/^searchTerm .*gif$/&gsrlimit=30&prop=imageinfo&iiprop=url|mime&iiurlwidth=400px&format=json

Any help ?

1

There are 1 answers

0
Tgr On

Try the search keyword filemime:image/gif: https://commons.wikimedia.org/w/api.php?action=query&generator=search&gsrnamespace=6&gsrsearch=searchTerm%20filemime:image/gif&gsrlimit=30&prop=imageinfo&iiprop=url|mime|thumbmime&iiurlwidth=400px&format=jsonfm

The "Advanced parameters" dropdown on the search page is a good way about finding out about search keywords (although it does not include everything). You can also look at the full docs.