diff --git a/apps/config/package-lock.json b/apps/config/package-lock.json index 8daf39c6..dbe8b7bc 100644 Binary files a/apps/config/package-lock.json and b/apps/config/package-lock.json differ diff --git a/apps/extract-subs/src/app.ts b/apps/extract-subs/src/app.ts index 21b7a716..028485ad 100644 --- a/apps/extract-subs/src/app.ts +++ b/apps/extract-subs/src/app.ts @@ -98,8 +98,8 @@ const findSubs = ( streams: FfprobeStream[], ): FfprobeStream[] => { const subs = streams.filter((s) => s.tags?.language && - s.tags.language === lang && - s.codec_type === 'subtitle'); + s.tags.language === lang && + s.codec_type === 'subtitle'); const pgs = subs.filter((s) => s.codec_name === 'hdmv_pgs_subtitle'); @@ -139,7 +139,9 @@ const main = async(): Promise => { } // Extract all subs - subs.forEach((sub) => { extractSub(sub); }); + subs.forEach((sub) => { + extractSub(sub); + }); }); removeContainerSubs(); diff --git a/configurations/nos/modules/default.nix b/configurations/nos/modules/default.nix index d00944b2..753c855d 100644 --- a/configurations/nos/modules/default.nix +++ b/configurations/nos/modules/default.nix @@ -8,8 +8,6 @@ ./obsidian-livesync ./qbittorrent ./snapraid - - # TODO: I need to actually do this properly before unleashing it on my library - # ./subtitles + ./subtitles ]; } diff --git a/configurations/nos/modules/subtitles/cleanup.nix b/configurations/nos/modules/subtitles/cleanup.nix deleted file mode 100644 index eeafcf22..00000000 --- a/configurations/nos/modules/subtitles/cleanup.nix +++ /dev/null @@ -1,30 +0,0 @@ -{pkgs, ...}: let - scriptSrc = pkgs.fetchFromGitHub { - owner = "brianspilner01"; - repo = "media-server-scripts"; - rev = "00d9efcd37bb2667d23d7747240b59291cde64d3"; - hash = "sha256-Qql6Z+smU8vEJaai0POjdMnYpET9ak4NddNQevEQ8Ds="; - }; - - script = pkgs.concatTextFile { - name = "sub-clean.sh"; - files = ["${scriptSrc}/sub-clean.sh"]; - executable = true; - }; -in - pkgs.writeShellApplication { - name = "sub-clean"; - - runtimeInputs = builtins.attrValues { - inherit - (pkgs) - findutils - gnugrep - gawk - ; - }; - - text = '' - exec ${script} "$@" - ''; - } diff --git a/configurations/nos/modules/subtitles/convert.nix b/configurations/nos/modules/subtitles/convert.nix index 4193c993..31f0496e 100644 --- a/configurations/nos/modules/subtitles/convert.nix +++ b/configurations/nos/modules/subtitles/convert.nix @@ -1,13 +1,12 @@ -{pkgs, ...}: -pkgs.writeShellApplication { - name = "convertMkv"; +{ + writeShellApplication, + ffmpeg-full, + ... +}: +writeShellApplication { + name = "convert-mkv"; - runtimeInputs = builtins.attrValues { - inherit - (pkgs) - ffmpeg-full - ; - }; + runtimeInputs = [ffmpeg-full]; text = '' extension="$1" diff --git a/configurations/nos/modules/subtitles/default.nix b/configurations/nos/modules/subtitles/default.nix index eec86d86..2fe49688 100644 --- a/configurations/nos/modules/subtitles/default.nix +++ b/configurations/nos/modules/subtitles/default.nix @@ -2,17 +2,15 @@ config, mainUser, pkgs, + self, ... -} @ inputs: let - convertMkv = pkgs.callPackage ./convert.nix {inherit pkgs;}; - extractSubs = pkgs.callPackage ./extract-subs {inherit pkgs;}; - sub-clean = pkgs.callPackage ./cleanup.nix {inherit pkgs;}; - bazarr-bulk = pkgs.callPackage ./syncing.nix inputs; -in { - # TODO: - # - Improve cleanup - # - figure out bazarr postprocessing with syncing subs +} @ extraArgs: let + inherit (self.appsPackages.${pkgs.system}) extract-subs; + inherit (self.packages.${pkgs.system}) subscleaner; + convert-mkv = pkgs.callPackage ./convert.nix {}; + bazarr-bulk = pkgs.callPackage ./syncing.nix ({} // extraArgs); +in { environment.systemPackages = [ bazarr-bulk ]; @@ -25,22 +23,22 @@ in { }; path = [ - convertMkv - extractSubs - sub-clean bazarr-bulk + convert-mkv + extract-subs + subscleaner ]; script = '' # Make sure every video file is a mkv - find /data/{anime,history,movies,tv} -name '*.mp4' -exec convertMkv "mp4" "{}" \; + find /data/{anime,history,movies,tv} -name '*.mp4' -exec convert-mkv "mp4" "{}" \; # Export subs from mkv files find /data/{anime,history,movies,tv} -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' extract-subs '{}' "eng,fre" # Remove ads and stuff in subs - find /data/{anime,history,movies,tv} -name '*.srt' -exec sub-clean "{}" \; + find /data/{anime,history,movies,tv} -name '*.srt' | subscleaner # Bulk sync everything bb movies sync diff --git a/configurations/nos/modules/subtitles/syncing.nix b/configurations/nos/modules/subtitles/syncing.nix index 0e023c25..6e0b8438 100644 --- a/configurations/nos/modules/subtitles/syncing.nix +++ b/configurations/nos/modules/subtitles/syncing.nix @@ -2,14 +2,17 @@ bazarr-bulk, config, lib, - pkgs, + system, + writeShellApplication, ... }: let - bbPkg = bazarr-bulk.packages.${pkgs.system}.default; + inherit (lib) getExe; + + bbPkg = bazarr-bulk.packages.${system}.default; in - pkgs.writeShellApplication { + writeShellApplication { name = "bb"; text = '' - exec ${lib.getExe bbPkg} --config ${config.sops.secrets.bazarr-bulk.path} "$@" + exec ${getExe bbPkg} --config ${config.sops.secrets.bazarr-bulk.path} "$@" ''; } diff --git a/flake.lock b/flake.lock index ae0a7aa9..8d4c06f1 100644 Binary files a/flake.lock and b/flake.lock differ diff --git a/flake.nix b/flake.nix index bd063241..b2960ea8 100644 Binary files a/flake.nix and b/flake.nix differ diff --git a/inputs/default.nix b/inputs/default.nix index dc57d049..e6ffab55 100644 --- a/inputs/default.nix +++ b/inputs/default.nix @@ -67,6 +67,11 @@ let repo = "nurl"; }; + poetry2nix = mkInput { + owner = "nix-community"; + repo = "poetry2nix"; + }; + # These are here to make sure all 'systems' and popular inputs are the same flake-compat = mkInput { owner = "edolstra"; @@ -336,6 +341,11 @@ let owner = "rushsteve1"; repo = "trash-d"; } + { + type = "gitlab"; + owner = "rogs"; + repo = "subscleaner"; + } { type = "gitlab"; owner = "mishakmak"; diff --git a/packages/default.nix b/packages/default.nix index 018b6928..bffce819 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -45,6 +45,10 @@ some-sass-language-server = pkgs.callPackage ./some-sass-language-server {}; + subscleaner = pkgs.callPackage ./subscleaner { + inherit (inputs) poetry2nix subscleaner-src; + }; + trash-d = pkgs.callPackage ./trash-d { inherit (inputs) trash-d-src; }; diff --git a/packages/subscleaner/default.nix b/packages/subscleaner/default.nix new file mode 100644 index 00000000..366fbceb --- /dev/null +++ b/packages/subscleaner/default.nix @@ -0,0 +1,12 @@ +{ + pkgs, + poetry2nix, + subscleaner-src, + ... +}: let + inherit (poetry2nix.lib.mkPoetry2Nix {inherit pkgs;}) mkPoetryApplication; +in + mkPoetryApplication { + projectDir = subscleaner-src; + preferWheels = true; + }