0

I'm currently working on a project and I can't manage to figure out how to retrieve data (giving for example an artist/song/album name) from MusicBrainz.

To be more specific

My final goal is to have something similar to this one script that works on DBPedia:

    function myQuery(artist,title) {
    var DBP = "http://dbpedia.org/sparql";
    var query = [
       "SELECT DISTINCT ?abstract WHERE {",
        "?artist foaf:name \"" + artist +"\"@en .",
        "?title a dbo:Song ;",
            "dbo:artist ?artist ;",
            "foaf:name \"" + title +"\"@en ;",
            "dbo:abstract ?abstract .",

        "FILTER (langMatches(lang(?abstract),\"it\")) }" ].join(" ");

    var queryURL = DBP + "?query=" + encodeURIComponent(query) + "&format=json" ;
    return queryURL;
    }

The myQuery() function is called in a sendQuery() function that basically creates a xhttp object and uses the GET method on the generated string.

After running the HTTP request I get a JSON file with the results I need.

Following the same path on the MusicBrainz SPARQL endpoint only gives me an error:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I understand what CORS are, but still I have no clue on how to get past this obstacle.

What approach should I keep in order to implement this service in my work?

Zaren Wienclaw
  • 181
  • 4
  • 15
  • One way to get past is to write a server-side script that makes the request (using for instance PHP) and send the AJAX request to your own server. –  Aug 28 '18 at 15:51
  • 1
    You've left out some key details, like which MusicBrainz SPARQL endpoint you're working with, which is where the CORS header needs to be set up. You might try spinning up your own mirror, or targeting a different endpoint that has the MusicBrainz dataset loaded, such as OpenLink Software's LOD Cloud Cache ([SPARQL endpoint](http://lod.openlinksw.com/sparql), or [Faceted Browser](http://lod.openlinksw.com/fct)) – TallTed Aug 28 '18 at 17:48
  • @TallTed In my attempts I used this endpoint: http://dbtune.org/musicbrainz/snorql/. – Salvatore Perri Aug 30 '18 at 19:14
  • I would suggest you [contact the maintainers](http://dbtune.org/#contact) of that endpoint, and ask them to add the CORS headers ... or consider setting up your own SPARQL endpoint against which you can execute Federated SPARQL -- which might join data from the public endpoints for DBpedia and Musicbrainz, which seems to be your end goal. – TallTed Aug 30 '18 at 21:06
  • @SalvatorePerri just to make clear, the data inside this endpoint is pretty old! you should generate the latest RDF dump by yourself and load it into a local store. – UninformedUser Sep 01 '18 at 07:44
  • Do you have any tutorials for someone who's completely at the beginning? – Salvatore Perri Sep 03 '18 at 17:19

0 Answers0