Skip to content

audio

Type: <boolean>
Default: false
It enables audio source detection over the target url.

The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT' URL with 'audio' API parameter:

CLI Microlink API example

microlink https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT&audio

cURL Microlink API example

curl -G "https://api.microlink.io" \
  -d "url=https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT" \
  -d "audio=true"

JavaScript Microlink API example

import mql from '@microlink/mql'

const { data } = await mql('https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT', {
  audio: true
})

Python Microlink API example

import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT",
    "audio": "true"
}

response = requests.get(url, params=querystring)

print(response.json())

Ruby Microlink API example

require 'uri'
require 'net/http'

base_url = "https://api.microlink.io/"

params = {
  url: "https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT",
  audio: "true"
}

uri = URI(base_url)
uri.query = URI.encode_www_form(params)

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
response = http.request(request)

puts response.body

PHP Microlink API example

<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT",
    "audio" => "true"
];

$query = http_build_query($params);
$url = $baseUrl . '?' . $query;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET"
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}

Golang Microlink API example

package main

import (
    "fmt"
    "net/http"
    "net/url"
    "io"
)

func main() {
    baseURL := "https://api.microlink.io"

    u, err := url.Parse(baseURL)
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("url", "https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT")
    q.Set("audio", "true")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}
Some websites can be different output based on User Agent.
The audio source URL detected will be in a browser-friendly format to be possible embedded it.
The audio detection introduce some human readable fields as part of the payload:
{
  "status": "success",
  "data": {
    "title": "Format",
    "description": "Format, a song by _91nova on Spotify",
    "lang": "en",
    "author": "_91nova",
    "publisher": "Spotify",
    "image": {
      "url": "https://i.scdn.co/image/ab67616d0000b27351b9595d03c3a8fb3ffe9f1a",
      "type": "jpg",
      "size": 88064,
      "height": 640,
      "width": 640,
      "size_pretty": "88.1 kB"
    },
    "audio": {
      "url": "https://p.scdn.co/mp3-preview/f36438afe87418f2dc0b7497eb5e7e5fa89e6bf8?cid=162b7dc01f3a4a2ca32ed3cec83d1e02",
      "type": "mp3",
      "duration": 30.040816,
      "size": 362861,
      "duration_pretty": "30s",
      "size_pretty": "363 kB"
    },
    "url": "https://open.spotify.com/track/1W2919zs8SBCLTrOB1ftQT",
    "date": "2019-11-11T08:50:08.000Z",
    "logo": {
      "url": "https://open.scdn.co/static/images/favicon.png",
      "type": "png",
      "size": 11125,
      "height": 196,
      "width": 196,
      "size_pretty": "11.1 kB"
    }
  }
}
You can read data fields section to know more about the data returned.