Automating SPARQL queries on MusicBrainz endpoint

357 Views Asked by At

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?

0

There are 0 best solutions below