1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/systems/ful/radio.nix

177 lines
5.9 KiB
Nix
Raw Normal View History

2022-03-10 21:52:12 +01:00
{
pkgs,
config,
lib,
2022-03-10 21:52:12 +01:00
...
2025-12-27 22:22:54 +01:00
}:
let
2022-02-10 19:28:28 +01:00
liquidsoapDirectory = "/var/cache/liquidsoap";
2022-02-08 00:47:10 +01:00
icecastPassword = "hackme";
refresh-qasaid = pkgs.writers.writeDashBin "refresh-qasaid" ''
(
for i in $(seq 1 22)
do
${pkgs.curl}/bin/curl -sSL "https://www.hindawi.org/poems/$i/"
done
) | ${pkgs.htmlq}/bin/htmlq '.poems li' \
| ${pkgs.fq}/bin/fq -d html '
.html.body.li
| map(.a
| {
id: .[0].["@href"] | sub("/poems/"; "") | sub("/$"; "") | tonumber,
poem: .[0].["#text"],
author: .[1].["#text"]
})
' | ${pkgs.cyberlocker-tools}/bin/cput qasaid.json
'';
qasida-poem = pkgs.writers.writeDash "qasida.sh" ''
set -efu
2025-12-27 22:22:54 +01:00
${pkgs.jq}/bin/jq -c '.[]' < ${
pkgs.fetchurl {
url = "https://c.krebsco.de/qasaid.json";
sha256 = "0vh1jzdrvjrdyq7dzya9k9g3jyli9jr0zfsqb2m1phm39psy4g2b";
}
} \
| shuf -n1 \
| ${pkgs.jq}/bin/jq -r '"annotate:title=\"\(.poem) | https://www.hindawi.org/poems/\(.id)/\",artist=\"\(.author)\":https://downloads.hindawi.org/poems/\(.id)/\(.id).m4a"'
'';
2022-02-08 00:47:10 +01:00
lyrikline-poem = pkgs.writers.writeDash "lyrikline.sh" ''
set -efu
2022-02-08 00:47:10 +01:00
html=$(mktemp)
trap clean EXIT
clean() {
rm "$html"
}
2022-02-08 00:47:10 +01:00
lyrikline=https://www.lyrikline.org
random_route="$(${pkgs.curl}/bin/curl -sSL "$lyrikline/index.php/tools/getrandompoem" --data-raw 'lang=de' --compressed | ${pkgs.jq}/bin/jq -r .link)"
2022-02-08 00:47:10 +01:00
poem_url="$lyrikline$random_route"
${pkgs.curl}/bin/curl -sSL "$poem_url" > "$html"
2022-02-08 00:47:10 +01:00
poem_file="$(${pkgs.gnugrep}/bin/grep -o 'https://.*\.mp3' "$html" | head -n1)"
author="$(${pkgs.htmlq}/bin/htmlq -f "$html" --text '#gedicht-autor')"
title="$(${pkgs.htmlq}/bin/htmlq -f "$html" --text .gedicht-originaltitel)"
2022-02-08 19:21:03 +01:00
echo "annotate:title=\"$title | $poem_url\",artist=\"$author\":$poem_file"
2022-02-08 00:47:10 +01:00
'';
stavenhagen-poem = pkgs.writers.writeDash "stavenhagen.sh" ''
base=https://www.deutschelyrik.de
author=$(${pkgs.curl}/bin/curl -sSL "$base" | ${pkgs.htmlq}/bin/htmlq option --attribute value | shuf -n1)
poem=$(${pkgs.curl}/bin/curl -sSL "$base/$author" | ${pkgs.htmlq}/bin/htmlq '#mnav2 li > a' --attribute href | shuf -n1)
html=$(mktemp)
trap clean EXIT
clean() {
rm "$html"
}
${pkgs.curl}/bin/curl -sSL "$base/$poem" > "$html"
2022-02-08 19:21:03 +01:00
printf "annotate:title=\"%s | %s\",artist=\"%s\":$base/%s\n" \
2022-02-08 00:47:10 +01:00
"$(${pkgs.htmlq}/bin/htmlq --text '.ce_text h1' -f "$html")" \
"$base/$poem" \
"$(${pkgs.htmlq}/bin/htmlq --text 'h1 + p em' -f "$html")" \
"$(${pkgs.htmlq}/bin/htmlq 'audio source' --attribute src -f "$html")"
'';
2022-02-08 19:21:03 +01:00
wikipedia-article = pkgs.writers.writeDash "wikipedia.sh" ''
set -efu
2022-02-10 19:28:28 +01:00
opus=$(mktemp ${liquidsoapDirectory}/wikipedia.XXX.opus)
2022-02-08 19:21:03 +01:00
html=$(mktemp)
trap clean EXIT
clean() {
rm "$html"
}
${pkgs.curl}/bin/curl -sSL https://de.wikipedia.org/wiki/Spezial:Zuf%C3%A4llige_Seite > "$html"
${pkgs.htmlq}/bin/htmlq '.mw-parser-output p' --text -f "$html" \
| ${pkgs.gnused}/bin/sed 's/\[[0-9]\+]//g' \
| ${pkgs.espeak}/bin/espeak -v german-mbrola-6 -w /dev/stdout \
| ${pkgs.opusTools}/bin/opusenc --quiet - "$opus"
printf "annotate:title=\"%s\":%s" \
"$(${pkgs.htmlq}/bin/htmlq -f "$html" --text h1)" \
"$opus"
'';
2025-12-27 22:22:54 +01:00
in
{
2022-02-08 00:47:10 +01:00
# https://github.com/savonet/liquidsoap/issues/1043#issuecomment-593354427
services.liquidsoap.streams.radio = pkgs.writeText "lyrikline.liq" ''
2023-03-22 07:47:57 +01:00
set("protocol.external.curl","${pkgs.torsocks}/bin/torsocks ${pkgs.curl}/bin/curl")
2022-02-08 00:47:10 +01:00
2022-02-08 19:21:03 +01:00
def random_url(script) =
mksafe(audio_to_stereo(request.dynamic.list(
2023-03-22 07:47:57 +01:00
fun () -> list.map(request.create, process.read.lines(script))
2022-02-08 19:21:03 +01:00
)))
2022-02-08 00:47:10 +01:00
end
2022-02-14 08:14:15 +01:00
def make_streams(name, audio, ~description, ~genre) =
output.icecast(%vorbis, audio, mount = name ^ ".ogg", genre = genre, description = description,
port = ${toString config.services.icecast.listen.port},
password = "${icecastPassword}",
)
output.icecast(%opus, audio, mount = name ^ ".opus", genre = genre, description = description,
port = ${toString config.services.icecast.listen.port},
password = "${icecastPassword}",
)
end
# make_streams("lyrikline", random_url("${lyrikline-poem}"), description="lyrikline. listen to the poet (unofficial)", genre="poetry")
make_streams("qasida", random_url("${qasida-poem}"), description="Qasa'id. Classical arabic poetry", genre="poetry")
2022-02-14 08:14:15 +01:00
make_streams("lyrik", random_url("${stavenhagen-poem}"), description="Fritz Stavenhagen Lyrik für alle | www.deutschelyrik.de", genre="poetry")
# make_streams("wikipedia", random_url("${wikipedia-article}"), description="Zufällige Artikel von Wikipedia", genre="useless knowledge")
2022-02-08 00:47:10 +01:00
'';
2024-04-28 11:02:37 +02:00
systemd.services.radio = {
environment.TMPDIR = liquidsoapDirectory;
2025-12-27 22:22:54 +01:00
wants = [ "network-online.target" ];
2024-04-28 11:02:37 +02:00
serviceConfig = {
RuntimeMaxSec = "${toString (5 * 60 * 60)}s";
2024-04-28 11:02:37 +02:00
Restart = "always";
};
};
2022-02-10 19:28:28 +01:00
2025-12-27 22:22:54 +01:00
environment.systemPackages = [ refresh-qasaid ];
2022-02-10 19:28:28 +01:00
systemd.tmpfiles.rules = [
(pkgs.lib.niveum.tmpfilesConfig {
2022-02-10 19:28:28 +01:00
type = "d";
path = liquidsoapDirectory;
mode = "0750";
user = "liquidsoap";
group = "liquidsoap";
age = "1h";
})
];
2022-02-08 00:47:10 +01:00
services.icecast = {
enable = true;
hostname = "radio.kmein.de";
admin.password = "hackme";
listen.port = 6457;
extraConf = ''
<authentication>
2022-02-08 19:21:03 +01:00
<source-password>${icecastPassword}</source-password>
2022-02-08 00:47:10 +01:00
</authentication>
'';
};
2021-12-03 12:07:51 +01:00
services.nginx.virtualHosts."radio.kmein.de" = {
2021-06-08 22:04:17 +02:00
enableACME = true;
forceSSL = true;
2022-02-08 00:47:10 +01:00
locations."/".proxyPass = "http://127.0.0.1:${toString config.services.icecast.listen.port}";
};
2022-05-22 11:47:59 +02:00
niveum.passport.services = [
{
title = "Radio";
link = "https://radio.kmein.de";
description = "broadcasts a few little (and mostly useless) web-radio stations.";
}
];
}