Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wikimedia API image search with public domain filter

I would like to query Wikimedia API to find all images that contain a keyword and filter only the images that are public domain. So no additional CC-SA license.

Curently I'm using the following query to extract the images:

http://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=roses&srnamespace=6&srinfo=totalhits%7Csuggestion&srprop=size%7Cwordcount%7Ctimestamp%7Cscore%7Csnippet%7Ctitlesnippet%7Credirecttitle%7Credirectsnippet%7Csectiontitle%7Csectionsnippet%7Chasrelated&srredirects=&srlimit=10&generator=images&titles=Wikipedia%3APublic_domain&gimlimit=10

But this is curently returning all the images regardless of their licencing. Maybe I need to modify the namespace but I don't know where to look.

Thanks

like image 484
CiprianIonescu Avatar asked Oct 09 '12 15:10

CiprianIonescu


People also ask

Are all Wikimedia images public domain?

Media on Wikimedia Commons are either in the public domain or published under a Creative Commons copyright license that allows them to be reused free of charge. The main requirement for reusing Creative Commons-licensed content is that you provide proper attribution.

How do you search images on Wikimedia Commons?

To get started, open Wikimedia Commons and then enter a search in the top-right corner of the screen. From here, hit the License dropdown to filter images by restrictions that come with their license. You can choose Use with attribution and same license, Use with attribution, No restrictions, or Other.

Is Wikipedia API free?

Wikipedia and other Wikimedia projects are free, collaborative repositories of knowledge, written and maintained by volunteers from around the world. The Wikimedia API gives you open access to add this free knowledge to your projects and apps.


1 Answers

Um, your current api query does two very distinct things:

  • get the first 10 images from the page Wikipedia:Public Domain - the pages result, you could specify additional properties to get for that result set
  • search the namespace 6 for the word roses

Unfortunately, you can't restrict the search module to search only in some categories, you can only limit it to a single namespace. So you would need to get the categories of all search results and filter them yourself for images in the Category:Public Domain (and all its subcategories). The API query would look like

api.php?action=query&prop=imageinfo|categories&generator=search&gsrsearch=roses&gsrnamespace=6&format=json

Don't forget to continue the query, if you want 10 images that match your category criteria you might need to query (a lot) more than that.

like image 164
Bergi Avatar answered Oct 21 '22 12:10

Bergi