Demian Sims
Demian Sims

Reputation: 921

How to get specific results using MediaWiki API in Rails backend?

I'm doing my final project for a coding school that will be a deep song search app that returns every detail about a song (composer, personnel on the track, lyrics, studio, media uses, images, etc). I'm using React frontend/Rails backend API. I'm new to API's and have tried Discogs and Musicbrainz but find the Mediawiki to be the easiest to traverse. Messing with their sandbox using Query, I feel like I'm getting closer but wondering if anyone with more experience out there could help me get precisely what I need.

I would like a music search to return a list of matches (could be same title but different songs or same title but different recordings). A user can click on the results to see the details. I would like the API to return links and hopefully images (album cover, etc). Does anyone know the best way to go about this?

I've also tried using the Ruby Gem wrapper Mediawikitory https://github.com/molybdenum-99/mediawiktory. I like the clean interface but can't quite find the right parameters.

The closest I've come to what I'm looking for in the Mediawiki sandbox is an example like this for the All Star (Smash Mouth):

https://en.wikipedia.org//w/api.php?action=query&format=json&prop=&list=search&continue=-%7C%7C&srsearch=star%20(song)&srlimit=5&sroffset=15&srqiprofile=engine_autoselect&srwhat=text&srinfo=totalhits%7Csuggestion%7Crewrittenquery&srinterwiki=1

This gives a list of songs (I'll have to concatenate '(song)' in every search unless there's a specific category parameter I don't know about).

Upvotes: 1

Views: 124

Answers (1)

Demian Sims
Demian Sims

Reputation: 921

So with further research I was able to drill down to specific song searches (and this will work for any thing this specific). You have to use srsearch and then search option in lists. So an example for a list of songs based on a given title:

https://en.wikipedia.org/w/api.php?action=query&formatversion=2&format=json&prop=info%7Cpageimages&generator=search&inprop=url&piprop=thumbnail%7Cname&gsrsearch=I%20love%20you%20(song)&gsrwhat=text

Make sure you choose version 2 as it gives you a better formatted Object to map over.

The Mediawiki API is very robust. You just have to spend a little time with it. The sandbox is great.

Upvotes: 2

Related Questions