diff options
Diffstat (limited to 'lass/2configs')
-rw-r--r-- | lass/2configs/radio/controls.html | 83 | ||||
-rw-r--r-- | lass/2configs/radio/default.nix (renamed from lass/2configs/radio.nix) | 109 | ||||
-rw-r--r-- | lass/2configs/radio/news.nix (renamed from lass/2configs/radio-news.nix) | 64 | ||||
-rw-r--r-- | lass/2configs/radio/weather_for_ips.py | 33 | ||||
-rw-r--r-- | lass/2configs/themes.nix | 12 |
5 files changed, 193 insertions, 108 deletions
diff --git a/lass/2configs/radio/controls.html b/lass/2configs/radio/controls.html new file mode 100644 index 000000000..858dc3656 --- /dev/null +++ b/lass/2configs/radio/controls.html @@ -0,0 +1,83 @@ +<!doctype html> + +<html lang="en"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + + <title>The_Playlist Voting!</title> +<style> +#good { + display: block; + width: 100%; + border: none; + background-color: #04AA6D; + padding: 14px; + margin: 14px 0 0 0; + height: 100px; + font-size: 16px; + cursor: pointer; + text-align: center; +} +#bad { + display: block; + width: 100%; + border: none; + background-color: red; + padding: 14px; + height: 100px; + + margin: 14px 0 0 0; + font-size: 16px; + cursor: pointer; + text-align: center; +} +</style> + +</head> + +<body> + <div id=votenote></div> + <button id=good type="button"> GUT </button> + + <button id=bad type="button"> SCHLECHT </button> + <center> + Currently Running: <br/><div> + <b id=current></b> + </div> + <div id=vote> + </div> + <audio controls autoplay="autoplay"> + <source src="https://radio.lassul.us/radio.ogg" type="audio/ogg"> + Your browser does not support the audio element. + </audio> + </center> + + <script> + document.getElementById("good").onclick=async ()=>{ + let result = await fetch("https://radio.lassul.us/good", {"method": "POST"}) + document.getElementById("vote").textContent = "Dieses Lied findest du gut" + }; + document.getElementById("bad").onclick=async ()=>{ + let result = await fetch("https://radio.lassul.us/skip", {"method": "POST"}) + document.getElementById("vote").textContent = "Dieses Lied findest du schlecht" + document.getElementById("bad").disabled = true + window.setTimeout(function(){ + document.getElementById("bad").disabled = false + }, 100000) + + }; + + async function current() { + let result = await fetch("https://radio.lassul.us/current", {"method": "GET"}) + let data = await result.json() + document.getElementById("current").textContent = data.name + } + window.onload = function() { + window.setInterval('current()', 10000) + current() + } + + </script> +</body> +</html> diff --git a/lass/2configs/radio.nix b/lass/2configs/radio/default.nix index 15d07dada..0611be7ce 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio/default.nix @@ -105,6 +105,10 @@ let ''; in { + imports = [ + ./news.nix + ]; + users.users = { "${name}" = rec { inherit name; @@ -161,14 +165,14 @@ in { output.icecast(mount = '/music.ogg', password = 'hackme', %vorbis(quality = 1), source) output.icecast(mount = '/music.mp3', password = 'hackme', %mp3.vbr(), source) - output.icecast(mount = '/music.opus', password = 'hackme', %opus(), source) + output.icecast(mount = '/music.opus', password = 'hackme', %opus(bitrate = 64), source) extra_input = audio_to_stereo(input.harbor("live", port=1338)) o = smooth_add(normal = source, special = extra_input) output.icecast(mount = '/radio.ogg', password = 'hackme', %vorbis(quality = 1), o) output.icecast(mount = '/radio.mp3', password = 'hackme', %mp3.vbr(), o) - output.icecast(mount = '/radio.opus', password = 'hackme', %opus(), o) + output.icecast(mount = '/radio.opus', password = 'hackme', %opus(bitrate = 64), o) ''; services.icecast = { enable = true; @@ -227,7 +231,7 @@ in { systemd.services.radio-recent = let recentlyPlayed = pkgs.writeDash "recentlyPlayed" '' - set -xeu + set -xefu LIMIT=1000 #how many tracks to keep in the history HISTORY_FILE=/var/lib/radio/recent while :; do @@ -368,88 +372,17 @@ in { locations."= /good".extraConfig = '' proxy_pass http://localhost:8001; ''; + locations."= /radio.sh".alias = pkgs.writeScript "radio.sh" '' + #!/bin/sh + while sleep 1; do + mpv \ + --cache-secs=0 --demuxer-readahead-secs=0 --untimed --cache-pause=no \ + 'http://lassul.us:8000/radio.opus' + done + ''; locations."= /controls".extraConfig = '' default_type "text/html"; - alias ${pkgs.writeText "controls.html" '' -<!doctype html> - -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - - <title>The_Playlist Voting!</title> -<style> -#good { - display: block; - width: 100%; - border: none; - background-color: #04AA6D; - padding: 14px; - margin: 14px 0 0 0; - height: 100px; - font-size: 16px; - cursor: pointer; - text-align: center; -} -#bad { - display: block; - width: 100%; - border: none; - background-color: red; - padding: 14px; - height: 100px; - - margin: 14px 0 0 0; - font-size: 16px; - cursor: pointer; - text-align: center; -} -</style> - -</head> - -<body> - <div id=votenote></div> - <button id=good type="button"> GUT </button> - - <button id=bad type="button"> SCHLECHT </button> - <center> - Currently Running: <br/><div> - <b id=current></b> - </div> - <div id=vote> - </div> - <audio controls autoplay="autoplay"> - <source src="https://radio.lassul.us/radio.ogg" type="audio/ogg"> - Your browser does not support the audio element. - </audio> - </center> - - <script> - document.getElementById("good").onclick=async ()=>{ - let result = await fetch("https://radio.lassul.us/good", {"method": "POST"}) - document.getElementById("vote").textContent = "Dieses Lied findest du gut" - }; - document.getElementById("bad").onclick=async ()=>{ - let result = await fetch("https://radio.lassul.us/skip", {"method": "POST"}) - document.getElementById("vote").textContent = "Dieses Lied findest du schlecht" - }; - - async function current() { - let result = await fetch("https://radio.lassul.us/current", {"method": "GET"}) - let data = await result.json() - document.getElementById("current").textContent = data.name - } - window.onload = function() { - window.setInterval('current()', 10000) - current() - } - - </script> -</body> -</html> - ''}; + alias ${./controls.html}; ''; extraConfig = '' add_header 'Access-Control-Allow-Origin' '*'; @@ -482,11 +415,9 @@ in { }; services.syncthing.declarative.folders."the_playlist" = { path = "/home/radio/music/the_playlist"; - devices = [ "mors" "phone" "prism" ]; - }; - krebs.permown."/home/radio/music/the_playlist" = { - owner = "radio"; - group = "syncthing"; - umask = "0002"; + devices = [ "mors" "phone" "prism" "omo" ]; }; + krebs.acl."/home/radio/music/the_playlist"."u:syncthing:X".parents = true; + krebs.acl."/home/radio/music/the_playlist"."u:syncthing:rwX" = {}; + krebs.acl."/home/radio/music/the_playlist"."u:radio:rwX" = {}; } diff --git a/lass/2configs/radio-news.nix b/lass/2configs/radio/news.nix index eb7d3bd9a..a3b39a9ea 100644 --- a/lass/2configs/radio-news.nix +++ b/lass/2configs/radio/news.nix @@ -1,14 +1,31 @@ { config, lib, pkgs, ... }: let + weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" { + libraries = [ pkgs.python3Packages.geoip2 ]; + } ./weather_for_ips.py; + weather_report = pkgs.writers.writeDashBin "weather_report" '' - set -efu - ${pkgs.curl}/bin/curl -fsSL https://wttr.in/''${1-}?format=j1 \ - | ${pkgs.jq}/bin/jq -r ' - [.nearest_area[0] | "Weather report for \(.areaName[0].value), \(.country[0].value)."] - + [.current_condition[0] | "Currently it is \(.weatherDesc[0].value) outside with a temperature of \(.temp_C) degrees."] - | join("\n") - ' + set -efu + export PATH="${lib.makeBinPath [ + pkgs.coreutils + pkgs.curl + pkgs.iproute2 + pkgs.jc + pkgs.jq + ]}" + curl -z /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb + MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB + OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY + ss -no 'sport = :8000' | + jc --ss | jq -r '.[] | + select( + .local_address != "[::ffff:127.0.0.1]" + and .local_address != "[::1]" + ) | .peer_address | gsub("[\\[\\]]"; "") + ' | + ${weather_for_ips}/bin/weather_for_ips ''; + send_to_radio = pkgs.writers.writeDashBin "send_to_radio" '' ${pkgs.vorbisTools}/bin/oggenc - | ${pkgs.libshout}/bin/shout --format ogg --host localhost --port 1338 --mount /live @@ -26,17 +43,15 @@ let ''; newsshow = pkgs.writers.writeDashBin "newsshow" /* sh */ '' - echo " + cat << EOF hello crabpeople! - $(${pkgs.ddate}/bin/ddate | sed 's/YOLD/Year of Discord/')! + $(${pkgs.ddate}/bin/ddate +'Today is %{%A, the %e of %B%}, %Y. %N%nCelebrate %H') It is $(date --utc +%H) o clock UTC. todays news: $(get_current_news) $(gc_news) - $(weather_report berlin) - $(weather_report 70173) - $(weather_report munich) - " + $(weather_report) + EOF ''; in { @@ -59,6 +74,9 @@ in startAt = "*:00:00"; serviceConfig = { User = "radio-news"; + LoadCredential = [ + "openweather_api:${toString <secrets>}/openweather_api_key" + ]; }; }; @@ -73,15 +91,23 @@ in }; script = ''. ${pkgs.writers.writeDash "htgen-news" '' set -xefu - case "$Method $Request_URI" in + case "''${Method:-GET} $Request_URI" in + "GET /") + printf 'HTTP/1.1 200 OK\r\n' + printf 'Access-Control-Allow-Origin: *\r\n'; + printf 'Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n'; + printf 'Connection: close\r\n' + printf '\r\n' + cat "$HOME"/news | jq -sc . + exit + ;; "POST /") - payload=$(head -c "$req_content_length" \ - | sed 's/+/ /g;s/%\(..\)/\\x\1/g;' \ - | xargs -0 echo -e \ - ) + payload=$(head -c "$req_content_length") echo "$payload" | jq 'has("from") and has("to") and has("text")' >&2 - echo "$payload" | jq -c '{ from: (.from | fromdate | todate), to: (.to | fromdate | todate), text: .text }' >> $HOME/news + echo "$payload" | jq -c '{ from: (.from | fromdate | todate), to: (.to | fromdate | todate), text: .text }' >> "$HOME"/news printf 'HTTP/1.1 200 OK\r\n' + printf 'Access-Control-Allow-Origin: *\r\n'; + printf 'Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n'; printf 'Connection: close\r\n' printf '\r\n' exit diff --git a/lass/2configs/radio/weather_for_ips.py b/lass/2configs/radio/weather_for_ips.py new file mode 100644 index 000000000..8d9a2e7bc --- /dev/null +++ b/lass/2configs/radio/weather_for_ips.py @@ -0,0 +1,33 @@ +import geoip2.database +import fileinput +import json +import requests +import os + + +geoip = geoip2.database.Reader(os.environ['MAXMIND_GEOIP_DB']) +seen = {} +output = [] +for ip in fileinput.input(): + location = geoip.city(ip.strip()) + if location.city.geoname_id not in seen: + seen[location.city.geoname_id] = True + weather_api_key = os.environ['OPENWEATHER_API_KEY'] + url = ( + f'https://api.openweathermap.org/data/2.5/onecall' + f'?lat={location.location.latitude}' + f'&lon={location.location.longitude}' + f'&appid={weather_api_key}' + f'&units=metric' + ) + resp = requests.get(url) + weather = json.loads(resp.text)['current'] + output.append( + f'Weather report for {location.city.name}' + f', {location.country.name}. ' + f'Currently it is {weather["weather"][0]["description"]} outside ' + f'with a temperature of {weather["temp"]} degrees ' + f'and a windspeed of {weather["wind_speed"]} meter per second. ' + ) + +print('\n'.join(output)) diff --git a/lass/2configs/themes.nix b/lass/2configs/themes.nix index 118619c1d..e020c62c4 100644 --- a/lass/2configs/themes.nix +++ b/lass/2configs/themes.nix @@ -12,6 +12,7 @@ ${pkgs.rsync}/bin/rsync --chown=lass:users -a --delete "/etc/themes/$1/" /var/theme/config/ echo "$1" > /var/theme/current_theme ${pkgs.coreutils}/bin/chown lass:users /var/theme/current_theme + ${pkgs.xorg.xrdb}/bin/xrdb -merge /var/theme/config/xresources ${pkgs.procps}/bin/pkill -HUP xsettingsd else echo "theme $1 not found" @@ -26,6 +27,8 @@ in { serviceConfig = { ExecStart = "${pkgs.xsettingsd}/bin/xsettingsd -c /var/theme/config/xsettings.conf"; User = "lass"; + Restart = "always"; + RestartSec = "15s"; }; }; systemd.tmpfiles.rules = [ @@ -38,11 +41,20 @@ in { "themes/light/xsettings.conf".text = '' Net/ThemeName "Adwaita" ''; + "themes/light/xresources".text = '' + *background: #ffffff + *foreground: #000000 + ''; "themes/dark/xsettings.conf".text = '' Net/ThemeName "Adwaita-dark" ''; + "themes/dark/xresources".text = '' + *background: #000000 + *foreground: #ffffff + ''; }; system.activationScripts.theme.text = '' + export DISPLAY=:0 if test -e /var/theme/current_theme; then ${switch-theme}/bin/switch-theme "$(cat /var/theme/current_theme)" || ${switch-theme}/bin/switch-theme dark |