Icecast, SHOUTcast and AzuraCast: the stream URL to give AudD
Find the stream URL to send to addStream on an Icecast, SHOUTcast or AzuraCast server (the mount or listen URL, not the status page or a playlist page), check it with ffprobe, add it, and show the recognized songs on the station's site or in the stream's titles.
If you run an internet radio station on Icecast, SHOUTcast or AzuraCast, you can use the AudD real-time music recognition service for audio streams to identify the songs it plays. We wanted to make the API as simple as possible: you send us the URLs of radio streams, and we send you the recognition results in real time. The tricky part is the URL: the server has several pages, and only one of them is the stream. Listeners can connect to the stream at these URLs:
- Icecast: the address of the server, then the mount point, like
http://radio.example.com:8000/stream. - SHOUTcast DNAS 2: the address of the server, then
/stream/and the ID of the stream, likehttp://radio.example.com:8000/stream/1/. - AzuraCast: the listen URL of a mount point, like
https://radio.example.com/listen/my_station/radio.mp3.
The URL can start with http://: you don’t need to set up HTTPS on your radio server. Don’t send the URL of the status page, of the station’s web player, or of a .pls file.
Find the stream URL
Icecast
Each Icecast server can house multiple streams, called mount points. A mount point is a unique name on your server identifying a particular stream, and it looks like a filename, such as /stream.ogg (MP3 streams usually don’t have an extension, like /stream). Listeners open http://your-server:port/<mount point>, and that’s the URL to send to AudD. The default port is 8000.
You can find the URLs of all the mount points in the JSON statistics of the server, /status-json.xsl:
curl -s http://radio.example.com:8000/status-json.xsl | python3 -c "import json, sys; s = json.load(sys.stdin)['icestats'].get('source', []); [print(m.get('listenurl')) for m in (s if isinstance(s, list) else [s])]"
Our servers connect to the stream from the internet, so if listenurl starts with http://localhost, use the public address of your server instead.
SHOUTcast
SHOUTcast DNAS serves the stream and its web pages on the same port (portbase, 8000 by default). Listeners can connect to the stream at one of these URLs:
http://your-server:8000/stream/1/, where1is the ID of the stream;http://your-server:8000/, if you use the default values for stream 1;http://your-server:8000/<streampath>, if you specified astreampathfor the stream.
The pages with ?sid= are not the stream: index.html?sid=1 is the status page, stats?sid=1 and currentsong?sid=1 return information about it, and listen.pls?sid=1 and listen.m3u?sid=1 are playlist files.
AzuraCast
In AzuraCast, mount points are how listeners connect and listen to your broadcasts. With multiple mount points, you can output the broadcast in multiple formats (MP3, Ogg Vorbis) or bitrates (128 kbps or 64 kbps). You’ll find all of them on the Profile page of the station. By default, the URL of a mount point looks like https://your-azuracast/listen/<station>/<mount>, like https://demo.azuracast.com/listen/azuratest_radio/radio.mp3 on the AzuraCast demo.
You can also take the URL from the Now Playing API: station.listen_url is the URL of the default mount point, and mounts[].url has the others. Don’t use public_player_url: it leads to the web player of the station, not to the stream. If HLS is enabled, you can also send the hls_url, an .m3u8 address: we support HLS too.
AzuraCast already knows the songs that its AutoDJ plays. For these songs, use AzuraCast’s Now Playing API: it will show you the current song of the station, with the time it started. Stream recognition can be useful on an AzuraCast station, e.g., to identify the music of a live DJ set that comes without titles.
Playlist files: .m3u and .pls
We support most of the stream formats, including DASH, Icecast, HLS, m3u/m3u8. Icecast serves an .m3u playlist for every mount point: add .m3u to the mount point (/stream.m3u). The .pls format isn’t in that list, but a .pls file is just a text file with the URL of the stream inside. Open it and send the URL from the File1= line:
[playlist]
File1=https://demo.azuracast.com/listen/azuratest_radio/radio.mp3
Title1=AzuraTest Radio - /radio.mp3 (128kbps MP3)
Length1=-1
Check the URL before you add it
We can only recognize the music if we can connect to the stream, so before you add it, make sure that the URL works from outside your network:
# A stream prints its codec, like codec_name=mp3.
# A web page (a status page, a web player) prints "Invalid data found when processing input".
# A .pls playlist prints codec_name=text: it's a text file, not audio.
ffprobe -hide_banner -v error -show_entries stream=codec_name -of default=nw=1 \
https://demo.azuracast.com/listen/azuratest_radio/radio.mp3
If you don’t have ffprobe, curl can show the content type:
# A stream prints an audio type, like "200 audio/mpeg"; curl stops it after 5 seconds.
# A web page prints "200 text/html", and a .pls playlist "200 audio/x-scpls".
curl -s -o /dev/null -m 5 -w '%{http_code} %{content_type}\n' \
https://demo.azuracast.com/listen/azuratest_radio/radio.mp3
Add the stream
Set the URL for callbacks using the setCallbackUrl API method. Callbacks are the requests with recognition results our servers will send to your server. Then add the stream using the addStream API method:
from audd import AudD
audd = AudD("your-api-token") # get your own token at dashboard.audd.io
audd.streams.set_callback_url("https://your-server.example.com/audd-callback")
audd.streams.add(url="http://radio.example.com:8000/stream", radio_id=1)
The radio_id is any integer that will identify this stream for you. By default, we will send new results after songs end playing, with the total played time: that’s what you need for airplay logs. Add the stream with callbacks="before" if you want to get the results when songs start playing, for a now-playing display or for the stream’s titles.
You can also add the stream with the AudD CLI: audd streams add http://radio.example.com:8000/stream --id 1 (add --start to get the results when songs start playing).
Note. The
testtoken doesn’t work with streams. Get your own token at dashboard.audd.io.
When the URL changes
If you move the station to a new server, change the port, or rename the mount point, the old URL stops working. Use the setStreamUrl method to update the URL of a stream:
from audd import AudD
audd = AudD("your-api-token")
audd.streams.set_url(radio_id=1, url="https://radio.example.com/listen/my_station/radio.mp3")
The radio_id stays the same, so your results and the widget keep working. If we can’t connect to the stream, we’ll let you know by sending a notification with the code 650. For more information, see Stream health.
Show the song on the station’s website
You can use our widget for this. It shows the last recognized song as well as the history (if you want it to show the history). Use the longpoll category with ”-” before it as the ch URL parameter. As the category, use the longpoll_category field from the getStreams response:
from audd import AudD
audd = AudD("your-api-token")
for s in audd.streams.list():
print(s.radio_id, s.longpoll_category, s.url)
Then add the widget to the page:
<!-- replace 92b1cc7f0 with the longpoll_category of your stream -->
<iframe src="https://widget.audd.tech/?ch=-92b1cc7f0&background&history"
width="320" height="480" style="border: 0" title="Now playing"></iframe>
You can share the categories with your clients or users, but please don’t include your API tokens in the client-side software. Set the callback URL to https://audd.tech/empty/ if you don’t have a server for callbacks and want to use the widget. If you want to build your own widget, see Build a now-playing widget.
Put the song in the stream’s titles
Players show the title the server sends with the stream. If a live show or a relay has no titles, you can set them from the callbacks. Icecast has an admin function for this: it lets any external program update the metadata information for a particular mount point.
import os
import httpx
from flask import Flask, request
from audd import AudD
from audd.errors import AudDSerializationError
audd = AudD(os.environ["AUDD_API_TOKEN"]) # get your own token at dashboard.audd.io
app = Flask(__name__)
ICECAST = "http://radio.example.com:8000" # your Icecast server
MOUNT = "/stream" # the mount you added to AudD
ADMIN_PASSWORD = os.environ["ICECAST_ADMIN_PASSWORD"]
RADIO_ID = 1 # the radio_id you gave this stream in addStream
@app.post("/audd-callback")
def audd_callback():
try:
match, notification = audd.streams.handle_callback(request)
except AudDSerializationError:
return "", 200
if match and match.radio_id == RADIO_ID and match.song.artist and match.song.title:
try:
httpx.get(
f"{ICECAST}/admin/metadata",
params={"mount": MOUNT, "mode": "updinfo",
"song": f"{match.song.artist} - {match.song.title}"},
auth=("admin", ADMIN_PASSWORD),
timeout=10,
).raise_for_status()
except httpx.HTTPError as e:
print(f"title update failed: {e}")
return "", 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
Install it with pip install audd flask httpx, and add the stream with callbacks="before", so the title changes when the song starts and not when it ends. The callbacks from all your streams come to one URL, so the handler checks the radio_id first. It answers 200 OK even when the title update fails: otherwise, we’d put the callback in a queue and send it again later, when the song is over.
For SHOUTcast DNAS 2, use admin.cgi with the stream ID and the admin password instead. In the handler, replace the call to httpx.get() with the following code:
httpx.get(
"http://radio.example.com:8000/admin.cgi",
params={"sid": 1, "mode": "updinfo",
"pass": os.environ["SHOUTCAST_ADMIN_PASSWORD"],
"song": f"{match.song.artist} - {match.song.title}"},
timeout=10,
).raise_for_status()
With SHOUTcast, the new title is used until the next use of this method or the next title update is received from the source. The callbacks aren’t signed, so anyone can send a request to this URL. For more information, see Securing your callback endpoint.
Related
Reading this as an AI agent? The raw Markdown is at integrations/internet-radio-servers.md, and the full index is /resources/llms.txt.
