0

Get the tracks by album

let apiKey := "8c6c8610-4f04-11ee-b74b-03c9318fae41";

let artist := substitute(text(Name), { " " : "%20" });
let album := substitute(text(Title), { " " : "%20" });

let url := "https://ws.audioscrobbler.com/2.0/?method=album.getinfo&artist=" + artist +
    "&album=" + album +
    "&api_key=" + apiKey +
    "&format=json";

let headers := {};
let body := null;

let response := http("GET", url, headers, body);

let albumData := record(response, "album");
let tracksData := record(albumData, "tracks");
let trackList := tracksData.track;

let allTracks := "";
for t in trackList do
    allTracks := allTracks + record(t, "name") + lineBreak()
end;

Tracks := allTracks

I'm trying to get the tracks by album from Last.fm but I haven't been able to and the AI isn't helping much. Any ideas?

3 replies

null
    • Sviluppatore Ninox
    • Fabio
    • 3 days ago
    • Reported - view

    Hello Rafael,

    I see you were trying to encode artist and album manually by replacing spaces with %20.
    However, it's better to use urlEncode() in Ninox, because it also handles special characters, accents, and Unicode properly.

    let artist := urlEncode(Name);
    let album := urlEncode(Title);
    

     

    In the second part, after retrieving the result, you need to iterate through the response using a key-value loop.

    Here is the complete code:

    let apiKey := "your-api-key";
    
    let artist := urlEncode(Name);
    let album := urlEncode(Title);
    
    let url := ---
        https://ws.audioscrobbler.com/2.0/?method=album.getinfo
        &artist= { artist }
        &album={ album }
        &api_key={ apiKey }
        &format=json
        ---;
    
    let response := http("GET", url, {}, {});
    
    let allTracks := for key, value in response.result do
            if key = "album" then
                join(for t in value.tracks.track do
                    text(t.name)
                end, "
    ")
            end
        end;
    
    allTracks
    
      • Rafael Sanchis
      • Rafael_Sanchis
      • 18 hrs ago
      • Reported - view

       

      Works now

      let api := "API key";
      let artist := urlEncode(Name);
      let album := urlEncode(Title);
      let url := "https://ws.audioscrobbler.com/2.0/?method=album.getinfo" + "&artist=" + artist +
          "&album=" +
          album +
          "&api_key=" +
          api +
          "&format=json";
      let response := http("GET", url, {}, {});
      let allTracks := "";
      for key, value in response.result do
          if key = "album" then
              allTracks := join(for t in value.tracks.track do
                      text(t.name)
                  end, "
      ")
          end
      end;
      allTracks

    • Rafael Sanchis
    • Rafael_Sanchis
    • 15 hrs ago
    • Reported - view

    Better

    let api := "API Key";
    let artist := urlEncode(Name);
    let album := urlEncode(Title);
    let url := "https://ws.audioscrobbler.com/2.0/?method=album.getinfo" + "&artist=" + artist +
        "&album=" +
        album +
        "&api_key=" +
        api +
        "&format=json";
    let response := http("GET", url, {}, {});
    let allTracks := "";
    for key, value in response.result do
        if key = "album" then
            let i := 1;
            allTracks := join(for t in value.tracks.track do
                    let line := number(i) + ". " + text(t.name);
                    i := i + 1;
                    line
                end, "
    ")
        end
    end;
    allTracks