From 89f3a94638a425f6f07950874263f2b3da25be04 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 2 Mar 2020 20:52:21 +0100 Subject: l mpv: add autosub script --- lass/2configs/mpv.nix | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) (limited to 'lass/2configs') diff --git a/lass/2configs/mpv.nix b/lass/2configs/mpv.nix index b3de42c7b..7dc43a9ee 100644 --- a/lass/2configs/mpv.nix +++ b/lass/2configs/mpv.nix @@ -2,11 +2,84 @@ let + download_subs = pkgs.writers.writePython3 "download_sub" { + libraries = [ pkgs.python3Packages.subliminal ]; + } '' + from subliminal import download_best_subtitles, scan_video + from babelfish import Language + import sys + + video_filename = sys.argv[1] + + vid = scan_video(video_filename) + sub = download_best_subtitles([vid], {Language('eng')})[vid][0] + + filename = '/tmp/' + vid.title + '.srt' + + with open(filename, 'wb+') as file: + file.write(sub.content) + + print(filename) + ''; + + autosub = pkgs.writeText "autosub.lua" '' + -- Requires Subliminal version 1.0 or newer + -- Make sure to specify your system's Subliminal location below: + local utils = require 'mp.utils' + + -- Log function: log to both terminal and mpv OSD (On-Screen Display) + function log(string, secs) + secs = secs or 2 -- secs defaults to 2 when the secs parameter is absent + mp.msg.warn(string) -- This logs to the terminal + mp.osd_message(string, secs) -- This logs to mpv screen + end + + function download() + log('Searching subtitles ...', 10) + table = { args = {"${download_subs}", mp.get_property('path')} } + result = utils.subprocess(table) + if result.error == nil then + -- remove trailing newline from subtitle filename + filename = string.gsub(result.stdout, "\n", "") + log(filename) + mp.commandv('sub_add', filename) + log('Subtitles ready!') + else + log('Subtitles failed downloading') + end + end + + -- Control function: only download if necessary + function control_download() + duration = tonumber(mp.get_property('duration')) + if duration < 900 then + mp.msg.warn('Video is less than 15 minutes\n', '=> NOT downloading any subtitles') + return + end + -- There does not seem to be any documentation for the 'sub' property, + -- but it works on both internally encoded as well as external subtitle files! + -- -> sub = '1' when subtitles are present + -- -> sub = 'no' when subtitles are not present + -- -> sub = 'auto' when called before the 'file-loaded' event is triggered + sub = mp.get_property('sub') + if sub == '1' then + mp.msg.warn('Sub track is already present\n', '=> NOT downloading other subtitles') + return + end + mp.msg.warn('No sub track was detected\n', '=> Proceeding to download subtitles:') + download() + end + + mp.register_event('file-loaded', control_download) + mp.add_key_binding('S', "download_subs", download) + ''; + mpv = pkgs.symlinkJoin { name = "mpv"; paths = [ (pkgs.writeDashBin "mpv" '' - exec ${pkgs.mpv}/bin/mpv --no-config "$@" + exec ${pkgs.mpv}/bin/mpv --no-config --script=${autosub} "$@" + # exec ${pkgs.mpv}/bin/mpv --no-config "$@" '') pkgs.mpv ]; -- cgit v1.2.3 From 2ec1535de5c3e751d2c98952d0f2eeb80d1d2e1e Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 17 Mar 2020 21:39:38 +0100 Subject: l games: disable minecraft --- lass/2configs/games.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lass/2configs') diff --git a/lass/2configs/games.nix b/lass/2configs/games.nix index c0e6beba4..63bfa53e0 100644 --- a/lass/2configs/games.nix +++ b/lass/2configs/games.nix @@ -65,7 +65,7 @@ in { createHome = true; useDefaultShell = true; packages = with pkgs; [ - minecraft + # minecraft steam-run scummvm dolphinEmu -- cgit v1.2.3 From c7bc2cb7c28c2542e549c76195eb9a9d9cbb8e96 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 5 Apr 2020 11:46:38 +0200 Subject: l radio: kill skipped tracks --- lass/2configs/radio.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lass/2configs') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index b24d7af3e..639caa178 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -9,13 +9,25 @@ let admin-password = import ; source-password = import ; + music_dir = "/home/radio/music"; + add_random = pkgs.writeDashBin "add_random" '' ${pkgs.mpc_cli}/bin/mpc add "$(${pkgs.mpc_cli}/bin/mpc ls the_playlist/music | grep '\.ogg$' | shuf -n1)" ''; skip_track = pkgs.writeDashBin "skip_track" '' ${add_random}/bin/add_random - echo skipping: "$(${print_current}/bin/print_current)" + current_track=$(${pkgs.mpc_cli}/bin/mpc current -f %file%) + track_infos=$(${print_current}/bin/print_current) + skip_count=$(${pkgs.attr}/bin/getfattr -n user.skip_count --only-values "$current_track" || echo 0) + if [ "$skip_count" -gt 2 ]; then + mv "$music_dir"/"$current_track" "$music_dir"/.graveyard/ + echo killing: "$track_infos" + else + skip_count=$((skip_count+1)) + ${pkgs.attr}/bin/setfattr -n user.skip_count -v "$skip_count" "$music_dir"/"$current_track" + echo skipping: "$track_infos" skip_count: "$skip_count" + fi ${pkgs.mpc_cli}/bin/mpc -q next ''; @@ -57,7 +69,7 @@ in { services.mpd = { enable = true; group = "radio"; - musicDirectory = "/home/radio/music"; + musicDirectory = "${music_dir}"; extraConfig = '' log_level "default" auto_update "yes" -- cgit v1.2.3 From e6b18f0f178fa47ddb46952de6d103e2904d519a Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 5 Apr 2020 12:24:12 +0200 Subject: l radio skip_track: set music_dir --- lass/2configs/radio.nix | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lass/2configs') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 639caa178..c89dc91e5 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -16,7 +16,10 @@ let ''; skip_track = pkgs.writeDashBin "skip_track" '' + set -eu + ${add_random}/bin/add_random + music_dir=${escapeShellArg music_dir} current_track=$(${pkgs.mpc_cli}/bin/mpc current -f %file%) track_infos=$(${print_current}/bin/print_current) skip_count=$(${pkgs.attr}/bin/getfattr -n user.skip_count --only-values "$current_track" || echo 0) -- cgit v1.2.3 From 0a9aa4bc575364ec7a4d477ea98325a8282fde56 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 8 Apr 2020 11:13:54 +0200 Subject: l radio: prefix commands with the_playlist: --- lass/2configs/radio.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lass/2configs') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index c89dc91e5..1a5aadeba 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -22,7 +22,7 @@ let music_dir=${escapeShellArg music_dir} current_track=$(${pkgs.mpc_cli}/bin/mpc current -f %file%) track_infos=$(${print_current}/bin/print_current) - skip_count=$(${pkgs.attr}/bin/getfattr -n user.skip_count --only-values "$current_track" || echo 0) + skip_count=$(${pkgs.attr}/bin/getfattr -n user.skip_count --only-values "$music_dir"/"$current_track" || echo 0) if [ "$skip_count" -gt 2 ]; then mv "$music_dir"/"$current_track" "$music_dir"/.graveyard/ echo killing: "$track_infos" @@ -193,11 +193,15 @@ in { }; }; + # allow reaktor2 to modify files + systemd.services."reaktor2-the_playlist".serviceConfig.DynamicUser = mkForce false; + krebs.reaktor2.the_playlist = { hostname = "irc.freenode.org"; port = "6697"; useTLS = true; nick = "the_playlist"; + username = "radio"; plugins = [ { plugin = "register"; @@ -214,8 +218,8 @@ in { workdir = config.krebs.reaktor2.the_playlist.stateDir; hooks.PRIVMSG = [ { - #activate = "match"; - pattern = "^\\s*([0-9A-Za-z._][0-9A-Za-z._-]*)(?:\\s+(.*\\S))?\\s*$"; + activate = "match"; + pattern = "^(?:.*\\s)?\\s*the_playlist:\\s*([0-9A-Za-z._][0-9A-Za-z._-]*)(?:\\s+(.*\\S))?\\s*$"; command = 1; arguments = [2]; commands = { -- cgit v1.2.3 From 0578d851885e59b317d653982b7b74f10739b9f3 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 8 Apr 2020 12:33:08 +0200 Subject: syncthing: use upstream module --- lass/2configs/green-host.nix | 2 +- lass/2configs/radio.nix | 4 ++-- lass/2configs/sync/decsync.nix | 4 ++-- lass/2configs/sync/weechat.nix | 2 +- lass/2configs/syncthing.nix | 16 +++++++++------- lass/2configs/websites/domsen.nix | 6 +++--- 6 files changed, 18 insertions(+), 16 deletions(-) (limited to 'lass/2configs') diff --git a/lass/2configs/green-host.nix b/lass/2configs/green-host.nix index 1421eede7..0cccbc30e 100644 --- a/lass/2configs/green-host.nix +++ b/lass/2configs/green-host.nix @@ -20,7 +20,7 @@ with import ; } ]; - krebs.syncthing.folders."/var/lib/sync-containers".peers = [ "icarus" "skynet" "littleT" "shodan" ]; + services.syncthing.declarative.folders."/var/lib/sync-containers".devices = [ "icarus" "skynet" "littleT" "shodan" ]; krebs.permown."/var/lib/sync-containers" = { owner = "root"; group = "syncthing"; diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 1a5aadeba..74b15a0ab 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -277,9 +277,9 @@ in { alias ${html}; ''; }; - krebs.syncthing.folders."the_playlist" = { + services.syncthing.declarative.folders."the_playlist" = { path = "/home/radio/music/the_playlist"; - peers = [ "mors" "phone" "prism" "xerxes" ]; + devices = [ "mors" "phone" "prism" "xerxes" ]; }; krebs.permown."/home/radio/music/the_playlist" = { owner = "radio"; diff --git a/lass/2configs/sync/decsync.nix b/lass/2configs/sync/decsync.nix index c3f6511c2..9caefdd2d 100644 --- a/lass/2configs/sync/decsync.nix +++ b/lass/2configs/sync/decsync.nix @@ -1,7 +1,7 @@ { - krebs.syncthing.folders.decsync = { + services.syncthing.declarative.folders.decsync = { path = "/home/lass/decsync"; - peers = [ "mors" "blue" "green" "phone" ]; + devices = [ "mors" "blue" "green" "phone" ]; }; krebs.permown."/home/lass/decsync" = { owner = "lass"; diff --git a/lass/2configs/sync/weechat.nix b/lass/2configs/sync/weechat.nix index 30c7b262b..ccbfc75a1 100644 --- a/lass/2configs/sync/weechat.nix +++ b/lass/2configs/sync/weechat.nix @@ -1,5 +1,5 @@ { - krebs.syncthing.folders."/home/lass/.weechat".peers = [ "blue" "green" "mors" ]; + services.syncthing.declarative.folders."/home/lass/.weechat".devices = [ "blue" "green" "mors" ]; krebs.permown."/home/lass/.weechat" = { owner = "lass"; group = "syncthing"; diff --git a/lass/2configs/syncthing.nix b/lass/2configs/syncthing.nix index d4df17b9a..5397c2ca6 100644 --- a/lass/2configs/syncthing.nix +++ b/lass/2configs/syncthing.nix @@ -7,18 +7,20 @@ in { enable = true; group = "syncthing"; configDir = "/var/lib/syncthing"; + declarative = { + key = toString ; + cert = toString ; + devices = mk_peers all_peers; + folders."/home/lass/sync" = { + devices = attrNames (filterAttrs (n: v: n != "phone") own_peers); + # ignorePerms = false; + }; + }; }; krebs.iptables.tables.filter.INPUT.rules = [ { predicate = "-p tcp --dport 22000"; target = "ACCEPT";} { predicate = "-p udp --dport 21027"; target = "ACCEPT";} ]; - krebs.syncthing = { - enable = true; - cert = toString ; - key = toString ; - peers = mk_peers all_peers; - folders."/home/lass/sync".peers = attrNames (filterAttrs (n: v: n != "phone") own_peers); - }; system.activationScripts.syncthing-home = '' ${pkgs.coreutils}/bin/chmod a+x /home/lass diff --git a/lass/2configs/websites/domsen.nix b/lass/2configs/websites/domsen.nix index 80ed12edc..bd113567f 100644 --- a/lass/2configs/websites/domsen.nix +++ b/lass/2configs/websites/domsen.nix @@ -270,14 +270,14 @@ in { }; boot.kernel.sysctl."fs.inotify.max_user_watches" = "1048576"; - krebs.syncthing.folders = { + services.syncthing.declarative.folders = { domsen-backups = { path = "/backups/domsen"; - peers = [ "domsen-backup" ]; + devices = [ "domsen-backup" ]; }; domsen-backup-srv-http = { path = "/srv/http"; - peers = [ "domsen-backup" ]; + devices = [ "domsen-backup" ]; }; }; -- cgit v1.2.3 From 47b379a4680b21f982bfc0822601baa1c8425540 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 11 Apr 2020 17:29:55 +0200 Subject: l: add more mail addresses --- lass/2configs/exim-smarthost.nix | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lass/2configs') diff --git a/lass/2configs/exim-smarthost.nix b/lass/2configs/exim-smarthost.nix index 565608633..08a226e6d 100644 --- a/lass/2configs/exim-smarthost.nix +++ b/lass/2configs/exim-smarthost.nix @@ -102,6 +102,14 @@ "microsoft@lassul.us" "stickers@lassul.us" "nextbike@lassul.us" + "mytello@lassul.us" + "camp@lassul.us" + "urlwatch@lassul.us" + "lidl@lassul.us" + "geizhals@lassul.us" + "auschein@lassul.us" + "tleech@lassul.us" + "durstexpress@lassul.us" ]; in { -- cgit v1.2.3 From 430cfa251f7e6d7f768b579cb01af9173e2e8bbc Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 11 Apr 2020 17:31:13 +0200 Subject: l mpv: bind subtitle search to key --- lass/2configs/mpv.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lass/2configs') diff --git a/lass/2configs/mpv.nix b/lass/2configs/mpv.nix index 7dc43a9ee..5d7bfed60 100644 --- a/lass/2configs/mpv.nix +++ b/lass/2configs/mpv.nix @@ -12,14 +12,17 @@ let video_filename = sys.argv[1] vid = scan_video(video_filename) - sub = download_best_subtitles([vid], {Language('eng')})[vid][0] + try: + sub = download_best_subtitles([vid], {Language('eng')})[vid][0] - filename = '/tmp/' + vid.title + '.srt' + filename = '/tmp/' + vid.title + '.srt' - with open(filename, 'wb+') as file: - file.write(sub.content) + with open(filename, 'wb+') as file: + file.write(sub.content) - print(filename) + print(filename) + except: # noqa + print("/dev/null") ''; autosub = pkgs.writeText "autosub.lua" '' @@ -70,7 +73,6 @@ let download() end - mp.register_event('file-loaded', control_download) mp.add_key_binding('S', "download_subs", download) ''; @@ -79,7 +81,6 @@ let paths = [ (pkgs.writeDashBin "mpv" '' exec ${pkgs.mpv}/bin/mpv --no-config --script=${autosub} "$@" - # exec ${pkgs.mpv}/bin/mpv --no-config "$@" '') pkgs.mpv ]; -- cgit v1.2.3 From 993a8de856df192a172c25b5e9ededc3ece3e80d Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 15 Apr 2020 17:20:28 +0200 Subject: l radio: listen to more experimental music --- lass/2configs/radio.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lass/2configs') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 74b15a0ab..e8ce66d3e 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -12,7 +12,7 @@ let music_dir = "/home/radio/music"; add_random = pkgs.writeDashBin "add_random" '' - ${pkgs.mpc_cli}/bin/mpc add "$(${pkgs.mpc_cli}/bin/mpc ls the_playlist/music | grep '\.ogg$' | shuf -n1)" + ${pkgs.mpc_cli}/bin/mpc add "$(${pkgs.findutils}/bin/find "${music_dir}/the_playlist" | grep '\.ogg$' | shuf -n1 | sed 's,${music_dir}/,,')" ''; skip_track = pkgs.writeDashBin "skip_track" '' -- cgit v1.2.3 From 07f18d851a974ee594c92e3332f167ef3b1d259f Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 15 Apr 2020 17:21:54 +0200 Subject: l radio: more complex track logic --- lass/2configs/radio.nix | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'lass/2configs') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index e8ce66d3e..c4c4b0abb 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -15,7 +15,7 @@ let ${pkgs.mpc_cli}/bin/mpc add "$(${pkgs.findutils}/bin/find "${music_dir}/the_playlist" | grep '\.ogg$' | shuf -n1 | sed 's,${music_dir}/,,')" ''; - skip_track = pkgs.writeDashBin "skip_track" '' + skip_track = pkgs.writeBashBin "skip_track" '' set -eu ${add_random}/bin/add_random @@ -23,17 +23,32 @@ let current_track=$(${pkgs.mpc_cli}/bin/mpc current -f %file%) track_infos=$(${print_current}/bin/print_current) skip_count=$(${pkgs.attr}/bin/getfattr -n user.skip_count --only-values "$music_dir"/"$current_track" || echo 0) - if [ "$skip_count" -gt 2 ]; then - mv "$music_dir"/"$current_track" "$music_dir"/.graveyard/ - echo killing: "$track_infos" - else + if [[ "$current_track" =~ ^the_playlist/music/.* ]] && [ "$skip_count" -le 2 ]; then skip_count=$((skip_count+1)) ${pkgs.attr}/bin/setfattr -n user.skip_count -v "$skip_count" "$music_dir"/"$current_track" echo skipping: "$track_infos" skip_count: "$skip_count" + else + mkdir -p "$music_dir"/.graveyard/ + mv "$music_dir"/"$current_track" "$music_dir"/.graveyard/ + echo killing: "$track_infos" fi ${pkgs.mpc_cli}/bin/mpc -q next ''; + good_track = pkgs.writeBashBin "good_track" '' + set -eu + + music_dir=${escapeShellArg music_dir} + current_track=$(${pkgs.mpc_cli}/bin/mpc current -f %file%) + track_infos=$(${print_current}/bin/print_current) + if [[ "$current_track" =~ ^the_playlist/music/.* ]]; then + ${pkgs.attr}/bin/setfattr -n user.skip_count -v 0 "$music_dir"/"$current_track" + else + mv "$music_dir"/"$current_track" "$music_dir"/the_playlist/music/ + fi + echo good: "$track_infos" + ''; + print_current = pkgs.writeDashBin "print_current" '' echo "$(${pkgs.mpc_cli}/bin/mpc current -f %file%) \ $(${pkgs.mpc_cli}/bin/mpc current -f %file% \ @@ -63,6 +78,7 @@ in { krebs.per-user.${name}.packages = with pkgs; [ add_random + good_track skip_track print_current ncmpcpp @@ -224,6 +240,13 @@ in { arguments = [2]; commands = { skip.filename = "${skip_track}/bin/skip_track"; + next.filename = "${skip_track}/bin/skip_track"; + bad.filename = "${skip_track}/bin/skip_track"; + + good.filename = "${good_track}/bin/good_track"; + nice.filename = "${good_track}/bin/good_track"; + like.filename = "${good_track}/bin/good_track"; + current.filename = "${print_current}/bin/print_current"; suggest.filename = pkgs.writeDash "suggest" '' echo "$@" >> playlist_suggest -- cgit v1.2.3