diff --git a/stream/radio.liq b/stream/radio.liq
index 4913280..3e58526 100644
--- a/stream/radio.liq
+++ b/stream/radio.liq
@@ -143,3 +143,34 @@ harbor.http.register(
resp.json({skipped=true})
end
)
+
+# Télécharger le fichier du morceau en cours. Le chemin vient de la métadonnée
+# `filename` de la source diffusée : c'est bien le fichier à l'antenne, et il est
+# forcément encore sur le disque tant qu'il joue (pas encore évincé par le LRU).
+def content_type_of(name) =
+ low = string.case(lower=true, name)
+ if string.contains(suffix=".flac", low) then "audio/flac"
+ elsif string.contains(suffix=".ogg", low) then "audio/ogg"
+ elsif string.contains(suffix=".opus", low) then "audio/opus"
+ elsif string.contains(suffix=".m4a", low) or string.contains(suffix=".aac", low) then "audio/mp4"
+ elsif string.contains(suffix=".wav", low) then "audio/wav"
+ else "audio/mpeg"
+ end
+end
+
+harbor.http.register(
+ port=8000, method="GET", "/download",
+ fun(_, resp) -> begin
+ m = now_playing()
+ fname = m["filename"]
+ if fname == "" or not file.exists(fname) then
+ resp.status_code(404)
+ resp.data("no track currently available")
+ else
+ base = path.basename(fname)
+ resp.content_type(content_type_of(base))
+ resp.header("Content-Disposition", "attachment; filename=\"#{base}\"")
+ resp.data(file.contents(fname))
+ end
+ end
+)