As mentioned in my blog post, I wanted to grab images from the wonderful site WikiArt.org for a side-project game I am working on. You can read some details about the issues I ran into while writing this code in that post, so I will simply detail how it works below.

WikiArtApi

The WikiArtApi object, once created, can be used to retrieve/create Artist objects, which in turn can be used to retrieve Artwork objects (if I have time at a later date I will add the ability to grab an Artwork object on its own, or pull it from someone who wants to fix it). Doing so is rather simple:

  • WikiArtApi.GetArtist accepts an artist’s name as an argument and returns an Artist object, or will throw an exception if an artist with the passed name is not found on WikiArt.org.
  • WikiArtApi.GetArtistsByLetter accepts a letter of the alphabet, and returns a list of Artist objects containing every artist found on WikiArt.org whose last name starts with that letter.
  • WikiArtApi.GetAllArtists takes no arguments and simply returns a list of Artist objects for every artist found on WikiArt.org (this simply calls GetArtistsByLetter for every letter of the alphabet).

Artist

An Artist object initially contains only an artist’s name and WikiArt.org URL in order to cut down on requests to WikiArt.org. However, if any other data is requested, then the necessary request is made and all artist info is grabbed at once for the same reason. The properties pulled from WikiArt.org are:

  • Name: The artist’s name
  • Born: The date the artist was born (just a string for now because I didn’t want to deal with however WikiArt.org formats their dates)
  • Died: The date the artist died (also a string for the same reason)
  • Movement: The artistic movement the artist belonged to (e.g. Expressionism or Impressionism)
  • Genre: The genre in which an artist’s “creative career reached its height” according to WikiArt.org
  • School: The collection of artists which the artist notably belonged to (for example the Hudson River School)
  • Nationalities: The artist’s nationality (or nationalities)
  • Fields: The materials that the artist worked with (e.g. engraving or painting)
  • Influenced On: A list of Artist objects representing artists that this artist influenced
  • Influenced By: A list of Artist objects representing artists that influenced this artist
  • Teachers: A list of Artist objects representing artists that taught this artist
  • Pupils: A list of Artist objects representing artists that this artist taught
  • PageUrl: The URL of this artist’s page on WikiArt.org
  • WorksListUrl: The URL on WikiArt.org that contains a list of this artist’s works
  • Works: A list of Artwork objects representing works created by this artist

Artwork

An Artwork object has the following properties pulled from WikiArt.org:

  • Title: The title of the work
  • Artist: The Artist object representing the artist who created this work
  • Style: The style of the work (referring “to its distinctive visual elements, techniques and methods”)
  • Genre: The genre of the work (classified “according to depicted themes and objects”)
  • Media: The media refers to “materials the artwork is made from, and to techniques used by the artist to create that artwork”
  • Tags: Any tags that may have been applied to the work on WikiArt.org
  • DimensionsCm: The dimensions of the artwork in centimeters
  • ImageUrl: The URL at which the actual image of the artwork can be found

The Artwork object also has the following two methods:

  • GetImageStream: Returns a Stream object that pulls from the work’s image URL, for easy downloading
  • GetImageBitmap: Returns a Bitmap object of the image, for easy saving

Here is a quick example of the API in use:

WikiArtApi api = new WikiArtApi();

// Download all of Rembrandt's works
WikiArtApi.Artist rembrandt = api.GetArtist("Rembrandt"); 
Console.WriteLine(rembrandt.School); // "Dutch school"
rembrandt.Works.ForEach(work => work.GetImageBitmap().Save("C:/Rembrandt/" + work.Title.Replace(' ', '-') + ".jpg")); 

// Find all artists starting with the letter M
List<WikiArtApi.Artist> artistsM = api.GetArtistsByLetter('m');
artistsM.ForEach(a => Console.WriteLine(a.Name)); // "Ma Yuan", "Dora Maar", "Manabu Mabe", "Mabuse", etc.

A link to the source code for this library can be found at the top of this page, or you can just grab and use the library .dll here.