diff --git a/devices/nos/default.nix b/devices/nos/default.nix index 74f2509..48a3d08 100644 --- a/devices/nos/default.nix +++ b/devices/nos/default.nix @@ -13,8 +13,8 @@ in { ./modules/mergerfs.nix ./modules/qbittorrent ./modules/snapraid.nix - ./modules/subtitles/sub-clean.nix - ./modules/subtitles/subsync + ./modules/subtitles/cleanup.nix + ./modules/subtitles/syncing ]; vars = { diff --git a/devices/nos/modules/subtitles/sub-clean.nix b/devices/nos/modules/subtitles/cleanup.nix similarity index 100% rename from devices/nos/modules/subtitles/sub-clean.nix rename to devices/nos/modules/subtitles/cleanup.nix diff --git a/devices/nos/modules/subtitles/subsync/default.nix b/devices/nos/modules/subtitles/subsync/default.nix deleted file mode 100644 index 074f1e6..0000000 --- a/devices/nos/modules/subtitles/subsync/default.nix +++ /dev/null @@ -1,53 +0,0 @@ -{ - config, - pkgs, - pocketsphinx-src, - subsync-src, - ... -}: let - inherit (config.vars) mainUser; - - sphinxbase = pkgs.callPackage ./sphinxbase.nix {}; - - pocketsphinx = pkgs.callPackage ./pocketsphinx.nix { - inherit sphinxbase pocketsphinx-src; - }; - - subsync = pkgs.callPackage ./subsync.nix { - inherit sphinxbase pocketsphinx subsync-src; - }; -in { - systemd = { - services.subsync-job = { - serviceConfig = { - Type = "oneshot"; - User = mainUser; - Group = config.users.users.${mainUser}.group; - }; - - path = with pkgs; [ - findutils - subsync - (writeShellApplication { - name = "sync-sub"; - runtimeInputs = [subsync]; - text = '' - # TODO: sync on a specific file - # $1 = file path - ''; - }) - ]; - - script = '' - find /data/anime -name '*.srt' -exec sync-sub "{}" \; - find /data/movies -name '*.srt' -exec sync-sub "{}" \; - find /data/tv -name '*.srt' -exec sync-sub "{}" \; - ''; - }; - timers.subsync-job = { - wantedBy = ["timers.target"]; - partOf = ["subsync-job.service"]; - timerConfig.OnCalendar = ["0:00:00"]; - }; - }; -} diff --git a/devices/nos/modules/subtitles/subsync/subsync.nix b/devices/nos/modules/subtitles/subsync/subsync.nix deleted file mode 100644 index 43b3c60..0000000 --- a/devices/nos/modules/subtitles/subsync/subsync.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ - ffmpeg, - pkg-config, - pocketsphinx, - python3Packages, - sphinxbase, - subsync-src, - ... -}: let - inherit (builtins) concatStringsSep; -in -python3Packages.buildPythonPackage { - pname = "subsync"; - version = subsync-src.shortRev; - - src = subsync-src; - - buildInputs = [ - ffmpeg - pkg-config - pocketsphinx - sphinxbase - ]; - - nativeBuildInputs = with python3Packages; [ - pip - setuptools - wheel - ]; - - propagatedBuildInputs = with python3Packages; [ - certifi - cryptography - pybind11 - pycryptodome - pysubs2 - pyyaml - requests - utils - ]; - - patches = [ - ./patches/cmd_ln.patch - ./patches/cstdint.patch - ]; - - # The tests are for the GUI - doCheck = false; - - # 'pip install .' takes care of building the package - buildPhase = ""; - - installPhase = '' - python -m pip install . ${concatStringsSep " " [ - "--no-index" - "--no-warn-script-location" - "--prefix=\"$out\"" - "--no-cache" - ]} - ''; -} diff --git a/devices/nos/modules/subtitles/syncing/default.nix b/devices/nos/modules/subtitles/syncing/default.nix new file mode 100644 index 0000000..cf67b33 --- /dev/null +++ b/devices/nos/modules/subtitles/syncing/default.nix @@ -0,0 +1,39 @@ +{ + config, + pkgs, + pocketsphinx-src, + subsync-src, + ... +}: let + inherit (config.vars) mainUser; + + subsync = pkgs.callPackage ./subsync { + inherit pocketsphinx-src subsync-src; + }; +in { + systemd = { + services.subsync-job = { + serviceConfig = { + Type = "oneshot"; + User = mainUser; + Group = config.users.users.${mainUser}.group; + }; + + path = with pkgs; [ + findutils + subsync + ]; + + script = '' + find /data/anime -name '*.srt' -exec node-syncsub "{}" \; + find /data/movies -name '*.srt' -exec node-syncsub "{}" \; + find /data/tv -name '*.srt' -exec node-syncsub "{}" \; + ''; + }; + timers.subsync-job = { + wantedBy = ["timers.target"]; + partOf = ["subsync-job.service"]; + timerConfig.OnCalendar = ["0:00:00"]; + }; + }; +} diff --git a/devices/nos/modules/subtitles/syncing/subsync/default.nix b/devices/nos/modules/subtitles/syncing/subsync/default.nix new file mode 100644 index 0000000..f7e45d7 --- /dev/null +++ b/devices/nos/modules/subtitles/syncing/subsync/default.nix @@ -0,0 +1,67 @@ +{ + callPackage, + ffmpeg, + pkg-config, + pocketsphinx-src, + python3Packages, + subsync-src, + ... +} @ pkgs: let + inherit (builtins) concatStringsSep; + + sphinxbase = callPackage ./sphinxbase.nix pkgs; + + pocketsphinx = + callPackage ./pocketsphinx.nix (pkgs + // {inherit pocketsphinx-src sphinxbase;}); +in + python3Packages.buildPythonPackage { + pname = "subsync"; + version = subsync-src.shortRev; + + src = subsync-src; + + buildInputs = [ + ffmpeg + pkg-config + pocketsphinx + sphinxbase + ]; + + nativeBuildInputs = with python3Packages; [ + pip + setuptools + wheel + ]; + + propagatedBuildInputs = with python3Packages; [ + certifi + cryptography + pybind11 + pycryptodome + pysubs2 + pyyaml + requests + utils + ]; + + patches = [ + ./patches/cmd_ln.patch + ./patches/cstdint.patch + ]; + + # The tests are for the GUI + doCheck = false; + + # 'pip install .' takes care of building the package + buildPhase = ""; + + installPhase = '' + python -m pip install . ${concatStringsSep " " [ + "--no-index" + "--no-warn-script-location" + "--prefix=\"$out\"" + "--no-cache" + ]} + ''; + } diff --git a/devices/nos/modules/subtitles/subsync/patches/cmd_ln.patch b/devices/nos/modules/subtitles/syncing/subsync/patches/cmd_ln.patch similarity index 100% rename from devices/nos/modules/subtitles/subsync/patches/cmd_ln.patch rename to devices/nos/modules/subtitles/syncing/subsync/patches/cmd_ln.patch diff --git a/devices/nos/modules/subtitles/subsync/patches/cstdint.patch b/devices/nos/modules/subtitles/syncing/subsync/patches/cstdint.patch similarity index 100% rename from devices/nos/modules/subtitles/subsync/patches/cstdint.patch rename to devices/nos/modules/subtitles/syncing/subsync/patches/cstdint.patch diff --git a/devices/nos/modules/subtitles/subsync/pocketsphinx.nix b/devices/nos/modules/subtitles/syncing/subsync/pocketsphinx.nix similarity index 100% rename from devices/nos/modules/subtitles/subsync/pocketsphinx.nix rename to devices/nos/modules/subtitles/syncing/subsync/pocketsphinx.nix diff --git a/devices/nos/modules/subtitles/subsync/sphinxbase.nix b/devices/nos/modules/subtitles/syncing/subsync/sphinxbase.nix similarity index 100% rename from devices/nos/modules/subtitles/subsync/sphinxbase.nix rename to devices/nos/modules/subtitles/syncing/subsync/sphinxbase.nix