Make results appear by relevance level

0

I have a JS query that returns me the songs of an artist when searching for the name of the artist, can someone tell me how I can make the songs appear by level of relevance? That is, from the most famous to the least famous? I'm using the youtube API and the muscibrainz API.

JS:

$("#submeter").click(function(){
    if ($("#artist").val()!="") {

      query = $("#artist").val()

      let url ="http://musicbrainz.org/ws/2/artist/?query=artist:"+ query +"&fmt=json";
      url=encodeURI(url);

      $.get(url,function(response,status){
        if (status=='success') {
          //alert(response.works)
          //alert(query);
          $(".form").hide();
          $(".div-pesquisa").show();
          $(".div-pesquisa h3").html("You searched for \" " + $("#artist").val() +  " \" ");

          url="http://musicbrainz.org/ws/2/artist/"+ response.artists[0].id +"?inc=releases&fmt=json";
          url=encodeURI(url);
          //alert(url);
          $.get(url,function(response,status){
            if (status=='success') {
              url="http://musicbrainz.org/ws/2/release/"+ response.releases[0].id +"?inc=recordings&fmt=json";
              url=encodeURI(url);
              $.get(url,function(response,status){
                if (status=='success') {
                  //for (var i = -1; i < 3 ; i++){


                  url ="https://www.googleapis.com/youtube/v3/search?q="+ query + " " +response.media[0].tracks[0].title+"&maxResults=1&part=snippet&key="+youtubeAPIKey;
                  url=encodeURI(url);
                  //alert(url);
                  //alert(i);
                    $.get(url,function(response,status){
                      if (status=='success') {
                        //$("#topmusic1 figure img").attr("src", response.items[0].snippet.thumbnails.high.url).css("height", "240px").css("width", "100%");
                        $("#topmusic1 figure div h6").html(response.items[0].snippet.title);
                        $("#topmusic1 figure i").click(function(){
                          $(".div-pesquisa").hide();
                          $(".player").show();
                          $(".player iframe").attr('src', "https://www.youtube.com/embed/"+response.items[0].id.videoId).css("border", "0").css("width", "100%").css("height", "100%");
                        });
                      }
                    });


                    url ="https://www.googleapis.com/youtube/v3/search?q="+ query + " " +response.media[0].tracks[1].title+"&maxResults=1&part=snippet&key="+youtubeAPIKey;
                    url=encodeURI(url);
                    //alert(url);
                    //alert(i);
                      $.get(url,function(response,status){
                        if (status=='success') {
                         // $("#topmusic2 figure img").attr("src", response.items[0].snippet.thumbnails.high.url).css("height", "240px").css("width", "100%");
                          $("#topmusic2 figure div h6").html(response.items[0].snippet.title);
                          $("#topmusic2 figure i").click(function(){
                            $(".div-pesquisa").hide();
                            $(".player").show();
                            $(".player iframe").attr('src', "https://www.youtube.com/embed/"+response.items[0].id.videoId).css("border", "0").css("width", "100%").css("height", "100%");
                          });
                        }
                      });


                      url ="https://www.googleapis.com/youtube/v3/search?q="+ query + " " +response.media[0].tracks[2].title+"&maxResults=1&part=snippet&key="+youtubeAPIKey;
                      url=encodeURI(url);
                      //alert(url);
                      //alert(i);
                        $.get(url,function(response,status){
                          if (status=='success') {
                           // $("#topmusic3 figure img").attr("src", response.items[0].snippet.thumbnails.high.url).css("height", "240px").css("width", "100%");
                            $("#topmusic3 figure div h6").html(response.items[0].snippet.title);
                            $("#topmusic3 figure i").click(function(){
                              $(".div-pesquisa").hide();
                              $(".player").show();
                              $(".player iframe").attr('src', "https://www.youtube.com/embed/"+response.items[0].id.videoId).css("border", "0").css("width", "100%").css("height", "100%");
                            });
                          }
                        });

                  //}
                }
              });
    
asked by anonymous 13.05.2018 / 15:19

0 answers