mirror of
https://github.com/kmein/niveum
synced 2026-03-21 04:11:07 +01:00
feat(radio): serve html of current song
This commit is contained in:
@@ -1,19 +1,45 @@
|
|||||||
{ lib, pkgs, config, ... }:
|
{ lib, pkgs, config, ... }:
|
||||||
let
|
let
|
||||||
meddl = {
|
radioStore = "/var/lib/radio";
|
||||||
streamPort = 8000;
|
htgenPort = 8080;
|
||||||
mpdPort = 6600;
|
meddl = { streamPort = 8000; mpdPort = 6600; };
|
||||||
};
|
lyrikline = { streamPort = 8001; mpdPort = 6601; };
|
||||||
lyrikline = {
|
lyrik = { streamPort = 8002; mpdPort = 6602; };
|
||||||
streamPort = 8001;
|
mpd-add-with-tags = pkgs.writers.writeHaskell "mpd-add-with-tags" {
|
||||||
mpdPort = 6601;
|
libraries = with pkgs.haskellPackages; [ optparse-generic libmpd ];
|
||||||
};
|
} ''
|
||||||
lyrik = {
|
{-# LANGUAGE DeriveGeneric, OverloadedStrings #-}
|
||||||
streamPort = 8002;
|
import Control.Monad (void)
|
||||||
mpdPort = 6602;
|
import Data.String
|
||||||
};
|
import Network.MPD
|
||||||
|
import Options.Generic
|
||||||
|
|
||||||
|
data Options = Options { url :: String, artist :: Maybe String, title :: Maybe String }
|
||||||
|
deriving (Generic)
|
||||||
|
|
||||||
|
instance ParseRecord Options
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
options <- getRecord "Add to MPD with tags"
|
||||||
|
void $ withMPD $ do
|
||||||
|
songId <- addId (fromString $ url options) Nothing
|
||||||
|
maybe (pure ()) (addTagId songId Artist . fromString) $ artist options
|
||||||
|
maybe (pure ()) (addTagId songId Title . fromString) $ title options
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
imports = [ <stockholm/krebs/3modules/htgen.nix> ];
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
(self: super: { htgen = super.callPackage <stockholm/krebs/5pkgs/simple/htgen> {}; })
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"d '${radioStore}' 0755 ${config.users.extraUsers.radio.name} - 1d -"
|
||||||
|
];
|
||||||
|
|
||||||
|
users.extraUsers.radio.isSystemUser = true;
|
||||||
|
|
||||||
containers.lyrik = {
|
containers.lyrik = {
|
||||||
autoStart = true;
|
autoStart = true;
|
||||||
config = {config, pkgs, ...}: {
|
config = {config, pkgs, ...}: {
|
||||||
@@ -38,6 +64,49 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
krebs.htgen.radio = {
|
||||||
|
port = htgenPort;
|
||||||
|
user.name = "radio";
|
||||||
|
script = ''. ${pkgs.writers.writeDash "meinskript" ''
|
||||||
|
case "$Method $Request_URI" in
|
||||||
|
"GET /lyrikline/status")
|
||||||
|
printf 'HTTP/1.1 200 OK\r\n'
|
||||||
|
printf 'Content-Type: text/html; charset=UTF-8\r\n'
|
||||||
|
printf 'Connection: close\r\n'
|
||||||
|
printf '\r\n'
|
||||||
|
|
||||||
|
hash="$(
|
||||||
|
MPD_PORT=${toString lyrikline.mpdPort} ${pkgs.mpc_cli}/bin/mpc status -f '%file%' \
|
||||||
|
| head -n 1 \
|
||||||
|
| md5sum \
|
||||||
|
| cut -d' ' -f 1
|
||||||
|
)"
|
||||||
|
url="$(cat ${radioStore}/$hash)"
|
||||||
|
|
||||||
|
echo "<html><body style='margin:0'><iframe style='width:100%;height:100%;border:0' src="$url"></iframe></body></html>"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
"GET /meddl/status")
|
||||||
|
printf 'HTTP/1.1 200 OK\r\n'
|
||||||
|
printf 'Content-Type: text/html; charset=UTF-8\r\n'
|
||||||
|
printf 'Connection: close\r\n'
|
||||||
|
printf '\r\n'
|
||||||
|
|
||||||
|
hash="$(
|
||||||
|
MPD_PORT=${toString meddl.mpdPort} ${pkgs.mpc_cli}/bin/mpc status -f '%file%' \
|
||||||
|
| head -n 1 \
|
||||||
|
| md5sum \
|
||||||
|
| cut -d' ' -f 1
|
||||||
|
)"
|
||||||
|
url="$(cat ${radioStore}/$hash)"
|
||||||
|
|
||||||
|
echo "<html><body style='margin:0'><iframe style='width:100%;height:100%;border:0' src="$url"></iframe></body></html>"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
''}'';
|
||||||
|
};
|
||||||
|
|
||||||
containers.meddl = {
|
containers.meddl = {
|
||||||
autoStart = true;
|
autoStart = true;
|
||||||
config = {config, pkgs, ...}: {
|
config = {config, pkgs, ...}: {
|
||||||
@@ -92,15 +161,31 @@ in
|
|||||||
after = [ "container@lyrikline.service" ];
|
after = [ "container@lyrikline.service" ];
|
||||||
wantedBy = [ "container@lyrikline.service" ];
|
wantedBy = [ "container@lyrikline.service" ];
|
||||||
startAt = "*:00/5";
|
startAt = "*:00/5";
|
||||||
environment.MPD_PORT = toString lyrikline.mpdPort;
|
environment = {
|
||||||
|
MPD_PORT = toString lyrikline.mpdPort;
|
||||||
|
MPD_HOST = "127.0.0.1";
|
||||||
|
};
|
||||||
|
serviceConfig.User = config.users.extraUsers.radio.name;
|
||||||
|
preStart = "${pkgs.mpc_cli}/bin/mpc crop";
|
||||||
script = ''
|
script = ''
|
||||||
set -efu
|
set -efu
|
||||||
|
|
||||||
lyrikline=https://www.lyrikline.org
|
lyrikline=https://www.lyrikline.org
|
||||||
for _ in $(seq 1 10); do
|
for _ in $(seq 1 10); do
|
||||||
random_route="$(${pkgs.curl}/bin/curl -sSL "$lyrikline/index.php/tools/getrandompoem" --data-raw 'lang=de' --compressed | ${pkgs.jq}/bin/jq -r .link)"
|
random_route="$(${pkgs.curl}/bin/curl -sSL "$lyrikline/index.php/tools/getrandompoem" --data-raw 'lang=de' --compressed | ${pkgs.jq}/bin/jq -r .link)"
|
||||||
poem_url="$(${pkgs.curl}/bin/curl -sSL "$lyrikline$random_route" | grep -o 'https://.*\.mp3' | head -n1)"
|
poem_url="$lyrikline$random_route"
|
||||||
${pkgs.mpc_cli}/bin/mpc add "$poem_url"
|
|
||||||
|
poem_file="$(
|
||||||
|
${pkgs.curl}/bin/curl -sSL "$poem_url" \
|
||||||
|
| grep -o 'https://.*\.mp3' \
|
||||||
|
| head -n1
|
||||||
|
)"
|
||||||
|
|
||||||
|
hash="$(echo "$poem_file" | md5sum | cut -d' ' -f 1)"
|
||||||
|
echo "$poem_file ($hash) -> $poem_url"
|
||||||
|
echo "$poem_url" > "${radioStore}/$hash"
|
||||||
|
|
||||||
|
${pkgs.mpc_cli}/bin/mpc add "$poem_file"
|
||||||
done
|
done
|
||||||
|
|
||||||
${pkgs.mpc_cli}/bin/mpc play
|
${pkgs.mpc_cli}/bin/mpc play
|
||||||
@@ -113,6 +198,7 @@ in
|
|||||||
environment.MPD_PORT = toString lyrik.mpdPort;
|
environment.MPD_PORT = toString lyrik.mpdPort;
|
||||||
preStart = "${pkgs.mpc_cli}/bin/mpc crop";
|
preStart = "${pkgs.mpc_cli}/bin/mpc crop";
|
||||||
restartIfChanged = true;
|
restartIfChanged = true;
|
||||||
|
serviceConfig.User = config.users.extraUsers.radio.name;
|
||||||
script =
|
script =
|
||||||
let
|
let
|
||||||
videoIds = import <niveum/lib/hot-rotation/lyrik.nix>;
|
videoIds = import <niveum/lib/hot-rotation/lyrik.nix>;
|
||||||
@@ -120,7 +206,6 @@ in
|
|||||||
streamsFile = pkgs.writeText "hotrot" streams;
|
streamsFile = pkgs.writeText "hotrot" streams;
|
||||||
in ''
|
in ''
|
||||||
set -efu
|
set -efu
|
||||||
|
|
||||||
${pkgs.mpc_cli}/bin/mpc add < ${toString streamsFile}
|
${pkgs.mpc_cli}/bin/mpc add < ${toString streamsFile}
|
||||||
|
|
||||||
${pkgs.mpc_cli}/bin/mpc crossfade 5
|
${pkgs.mpc_cli}/bin/mpc crossfade 5
|
||||||
@@ -136,6 +221,8 @@ in
|
|||||||
wantedBy = [ "container@meddl.service" ];
|
wantedBy = [ "container@meddl.service" ];
|
||||||
startAt = "*:00/10";
|
startAt = "*:00/10";
|
||||||
environment.MPD_PORT = toString meddl.mpdPort;
|
environment.MPD_PORT = toString meddl.mpdPort;
|
||||||
|
serviceConfig.User = config.users.extraUsers.radio.name;
|
||||||
|
preStart = "${pkgs.mpc_cli}/bin/mpc crop";
|
||||||
script = ''
|
script = ''
|
||||||
set -efu
|
set -efu
|
||||||
host=http://antenne-asb.ga
|
host=http://antenne-asb.ga
|
||||||
@@ -152,6 +239,11 @@ in
|
|||||||
| ${pkgs.pup}/bin/pup 'audio source attr{src}' \
|
| ${pkgs.pup}/bin/pup 'audio source attr{src}' \
|
||||||
| prepend_host
|
| prepend_host
|
||||||
)"
|
)"
|
||||||
|
|
||||||
|
hash="$(echo "$song_url" | md5sum | cut -d' ' -f 1)"
|
||||||
|
echo "$song_url ($hash) -> $song"
|
||||||
|
echo "$song" > "${radioStore}/$hash"
|
||||||
|
|
||||||
${pkgs.mpc_cli}/bin/mpc add "$song_url"
|
${pkgs.mpc_cli}/bin/mpc add "$song_url"
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -172,8 +264,12 @@ in
|
|||||||
];
|
];
|
||||||
|
|
||||||
services.nginx.virtualHosts."radio.xn--kiern-0qa.de".locations = {
|
services.nginx.virtualHosts."radio.xn--kiern-0qa.de".locations = {
|
||||||
"= /meddl.ogg".proxyPass = "http://127.0.0.1:${toString meddl.streamPort}";
|
"= /meddl/status".proxyPass = "http://127.0.0.1:${toString htgenPort}";
|
||||||
"= /lyrikline.ogg".proxyPass = "http://127.0.0.1:${toString lyrikline.streamPort}";
|
"= /meddl/listen.ogg".proxyPass = "http://127.0.0.1:${toString meddl.streamPort}";
|
||||||
|
"= /lyrikline/status".proxyPass = "http://127.0.0.1:${toString htgenPort}";
|
||||||
|
"= /lyrikline/listen.ogg".proxyPass = "http://127.0.0.1:${toString lyrikline.streamPort}";
|
||||||
"= /lyrik.ogg".proxyPass = "http://127.0.0.1:${toString lyrik.streamPort}";
|
"= /lyrik.ogg".proxyPass = "http://127.0.0.1:${toString lyrik.streamPort}";
|
||||||
|
"= /meddl.ogg".return = "301 http://radio.xn--kiern-0qa.de/meddl/listen.ogg";
|
||||||
|
"= /lyrikline.ogg".return = "301 http://radio.xn--kiern-0qa.de/lyrikline/listen.ogg";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user