diff options
Diffstat (limited to 'accounts/gkleen@sif/utils')
| -rw-r--r-- | accounts/gkleen@sif/utils/async-yt-dlp.nix | 57 | ||||
| -rw-r--r-- | accounts/gkleen@sif/utils/ldif2json/conf.patch | 12 | ||||
| -rw-r--r-- | accounts/gkleen@sif/utils/ldif2json/default.nix | 20 | ||||
| -rw-r--r-- | accounts/gkleen@sif/utils/pdf2pdf.nix | 8 | ||||
| -rw-r--r-- | accounts/gkleen@sif/utils/sieve-edit.nix | 24 |
5 files changed, 121 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/utils/async-yt-dlp.nix b/accounts/gkleen@sif/utils/async-yt-dlp.nix new file mode 100644 index 00000000..c3b82ec5 --- /dev/null +++ b/accounts/gkleen@sif/utils/async-yt-dlp.nix | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | { writers, python3Packages, ... }: | ||
| 2 | |||
| 3 | writers.writePython3Bin "async-yt-dlp" { | ||
| 4 | libraries = with python3Packages; [ yt-dlp ]; | ||
| 5 | flakeIgnore = ["E501"]; | ||
| 6 | } '' | ||
| 7 | import sys | ||
| 8 | import os | ||
| 9 | |||
| 10 | import yt_dlp | ||
| 11 | import yt_dlp.options | ||
| 12 | from collections import namedtuple | ||
| 13 | import socket | ||
| 14 | from pathlib import Path | ||
| 15 | import json | ||
| 16 | |||
| 17 | create_parser = yt_dlp.options.create_parser | ||
| 18 | |||
| 19 | |||
| 20 | def parse_patched_options(opts): | ||
| 21 | patched_parser = create_parser() | ||
| 22 | patched_parser.defaults.update({ | ||
| 23 | 'ignoreerrors': False, | ||
| 24 | 'retries': 0, | ||
| 25 | 'fragment_retries': 0, | ||
| 26 | 'extract_flat': False, | ||
| 27 | 'concat_playlist': 'never', | ||
| 28 | }) | ||
| 29 | yt_dlp.options.create_parser = lambda: patched_parser | ||
| 30 | try: | ||
| 31 | return yt_dlp.parse_options(opts) | ||
| 32 | finally: | ||
| 33 | yt_dlp.options.create_parser = create_parser | ||
| 34 | |||
| 35 | |||
| 36 | default_opts = parse_patched_options([]).ydl_opts | ||
| 37 | |||
| 38 | |||
| 39 | def cli_to_api(opts): | ||
| 40 | opts = parse_patched_options(opts) | ||
| 41 | urls = opts.urls | ||
| 42 | opts = opts.ydl_opts | ||
| 43 | |||
| 44 | diff = {k: v for k, v in opts.items() if default_opts[k] != v} | ||
| 45 | if 'postprocessors' in diff: | ||
| 46 | diff['postprocessors'] = [pp for pp in diff['postprocessors'] | ||
| 47 | if pp not in default_opts['postprocessors']] | ||
| 48 | return namedtuple('Options', ('params', 'urls'))(diff, urls) | ||
| 49 | |||
| 50 | |||
| 51 | if __name__ == '__main__': | ||
| 52 | opts = cli_to_api(sys.argv[1:]) | ||
| 53 | with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: | ||
| 54 | sock.connect(str(Path(os.environ["XDG_RUNTIME_DIR"]) / "yt-dlp.sock").encode('utf-8')) | ||
| 55 | with sock.makefile(mode='w', buffering=1, encoding='utf-8') as fh: | ||
| 56 | json.dump(opts._asdict(), fh) | ||
| 57 | '' | ||
diff --git a/accounts/gkleen@sif/utils/ldif2json/conf.patch b/accounts/gkleen@sif/utils/ldif2json/conf.patch new file mode 100644 index 00000000..e253e5f7 --- /dev/null +++ b/accounts/gkleen@sif/utils/ldif2json/conf.patch | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | diff --git i/src/conf.cr w/src/conf.cr | ||
| 2 | index b29ca84..eb7e0b4 100644 | ||
| 3 | --- i/src/conf.cr | ||
| 4 | +++ w/src/conf.cr | ||
| 5 | @@ -89,7 +89,6 @@ module Ldif2json | ||
| 6 | |||
| 7 | end.parse | ||
| 8 | |||
| 9 | - puts "@coercions #{@coercions.inspect} @can_be_coerced #{@can_be_coerced.inspect} @can_be_coerced[\"foobar\"] #{@can_be_coerced["foobar"].inspect} @can_be_flattened #{@can_be_flattened.inspect} @can_be_flattened[\"foobar\"] #{@can_be_flattened["foobar"].inspect}" | ||
| 10 | raise NormalError.new("cannot set types in join mode") if @mode == Mode::Join && @coercions.size > 0 | ||
| 11 | |||
| 12 | end | ||
diff --git a/accounts/gkleen@sif/utils/ldif2json/default.nix b/accounts/gkleen@sif/utils/ldif2json/default.nix new file mode 100644 index 00000000..35aef717 --- /dev/null +++ b/accounts/gkleen@sif/utils/ldif2json/default.nix | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | { crystal, sources }: | ||
| 2 | crystal.buildCrystalPackage { | ||
| 3 | inherit (sources.ldif2json) pname version src; | ||
| 4 | |||
| 5 | patches = [ | ||
| 6 | ./conf.patch | ||
| 7 | ]; | ||
| 8 | |||
| 9 | buildPhase = '' | ||
| 10 | make bin/ldif2json | ||
| 11 | ''; | ||
| 12 | |||
| 13 | installPhase = '' | ||
| 14 | mkdir -p $out/bin $out/share/man/man1 | ||
| 15 | install -m 0555 -t $out/bin bin/ldif2json | ||
| 16 | install -m 0444 -t $out/share/man/man1 doc/ldif2json.1.gz | ||
| 17 | ''; | ||
| 18 | |||
| 19 | doCheck = false; | ||
| 20 | } | ||
diff --git a/accounts/gkleen@sif/utils/pdf2pdf.nix b/accounts/gkleen@sif/utils/pdf2pdf.nix new file mode 100644 index 00000000..9f4cbc3e --- /dev/null +++ b/accounts/gkleen@sif/utils/pdf2pdf.nix | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | pkgs@{ lib, resholve, zsh, ghostscript_headless, ... }: | ||
| 2 | |||
| 3 | resholve.writeScriptBin "pdf2pdf" { | ||
| 4 | inputs = with pkgs; [ghostscript_headless]; | ||
| 5 | interpreter = lib.getExe zsh; | ||
| 6 | } '' | ||
| 7 | exec gs -dPDFSETTINGS=/prepress -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dPreserveAnnots=false "-sOutputFile=''${2}" "''${1}" | ||
| 8 | '' | ||
diff --git a/accounts/gkleen@sif/utils/sieve-edit.nix b/accounts/gkleen@sif/utils/sieve-edit.nix new file mode 100644 index 00000000..f985a3f6 --- /dev/null +++ b/accounts/gkleen@sif/utils/sieve-edit.nix | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | pkgs@{ lib, resholve, zsh, sieve-connect, sops, ... }: | ||
| 2 | |||
| 3 | resholve.writeScriptBin "sieve-edit" { | ||
| 4 | inputs = with pkgs; [sieve-connect sops]; | ||
| 5 | interpreter = lib.getExe zsh; | ||
| 6 | execer = with pkgs; [ | ||
| 7 | "cannot:${lib.getExe sieve-connect}" | ||
| 8 | "cannot:${lib.getExe sops}" | ||
| 9 | ]; | ||
| 10 | } '' | ||
| 11 | host=$1; shift | ||
| 12 | case "$host" in | ||
| 13 | surtr) | ||
| 14 | sieve-connect -s surtr.yggdrasil.li -m EXTERNAL --clientkey <(sops decrypt $HOME/projects/machines/hosts/surtr/email/ca/gkleen@sif.key) --clientcert $HOME/projects/machines/hosts/surtr/email/ca/gkleen@sif.crt --edit --remotesieve sieve | ||
| 15 | ;; | ||
| 16 | ymir) | ||
| 17 | sieve-connect -s ymir.yggdrasil.li -u gkleen --edit --remotesieve sieve | ||
| 18 | ;; | ||
| 19 | *) | ||
| 20 | echo "Unknown host: ‘$host’" >&2 | ||
| 21 | return 2 | ||
| 22 | ;; | ||
| 23 | esac | ||
| 24 | '' | ||
