From d624d33b01aeca52ef4b610d342cec35fd856484 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Tue, 28 Jan 2025 00:08:00 -0500 Subject: [PATCH] feat(nos): reenable subtitle management --- apps/config/package-lock.json | Bin 98088 -> 98088 bytes apps/extract-subs/src/app.ts | 8 +++-- configurations/nos/modules/default.nix | 4 +-- .../nos/modules/subtitles/cleanup.nix | 30 ------------------ .../nos/modules/subtitles/convert.nix | 17 +++++----- .../nos/modules/subtitles/default.nix | 26 +++++++-------- .../nos/modules/subtitles/syncing.nix | 11 ++++--- flake.lock | Bin 57847 -> 59122 bytes flake.nix | Bin 12949 -> 13430 bytes inputs/default.nix | 10 ++++++ packages/default.nix | 4 +++ packages/subscleaner/default.nix | 12 +++++++ 12 files changed, 59 insertions(+), 63 deletions(-) delete mode 100644 configurations/nos/modules/subtitles/cleanup.nix create mode 100644 packages/subscleaner/default.nix diff --git a/apps/config/package-lock.json b/apps/config/package-lock.json index 8daf39c689db69e742471ceb0d79a50871f5def6..dbe8b7bc30c055a3de699498d9124e6f82af6b03 100644 GIT binary patch delta 3302 zcmd5;J&fCA7?uO4p448iw16rB?X~=rVzqG`C+D=ia!%qnKaLY8u^qb=#ZJyi?D#i7 zb}S^W=w<}dAM*FjsUQaJ&e!f$k9}Ar2C|Qw|3OOfBA%e>^YD@n4y@g;kp-f@nU)G$g8l^ zX7o(lwh;xR<%FU))QuXQl9B_%CEacom+DbdE?12rnU!-@imkQniN!GmHVPAhmo4Um z>4#T=qW>|8_`hB$2Sq<)FZkEimcr9{|GVVj2t2<$?;mqd%;5pg&;D5ZYmPL4H(hA~ zXF_bzzQeK*!*^6=)v4AU$UvFeB*_<&2(7g$Z6`k>MlM(2J-w1_BMH0)IZZ}V2X@Nj z+iVXrWRuBIMK?OcJZhwN#-iBsWA`pkAJl_dEA**dL?Mh>%w7iqZeH-$ODCr5ZD7$q zm3=9AadYc>@ST$d)sZqHiIit1W3cC#S%k0jHmY&fa4J}>Q-X1oiV|r(mFSw29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}@$DoXxy8L$LsU&98tP zcb*}+F<~WVxp|4Kd9XT$wKIIz_QvE?$*5-$LFUCIO^8Y^W8yek3b1Wb@c0##_E&wm z3eju?v~Z$Hh7g1gcszn=sf@?X!jwV_;M~+1+)su85-wpR9GHCirF*Am0CTZ6&DsPf{HVXIKrDnuz zpczh-Iu&2VO4^AOpYK|O&)$I&;1TuFc>dMFdL3FEe`2HcfcvRG9(;cbJS=R_C~}mu zGGJTKgr2di^#{w~;RmOuEa3`8Cv`C&(A%1=AXKAIdNPd0QO#Ubc9+6#U1)V=G){%e z`5qBdHoEdg)n89A0?dUeUW!;Y+~Q2FZZ%jz+GHDbA?usK^uBpvN)-mZ4!-&N%QSs1Y;#7TYZ;qTFvPO#MiBE$;FO;PBP{o}P7l@vXc?TP zC!{^k-(SGhFgRzXa&NmDn8qdvOYW_q_R3rw&j*wv?)@h;jolx z8E!)rX;S2yIV7qXPBNvUSzp+VXDBp6s#s$1tpII188^!RQ4>r{VTVA6H`VKNR_Le( zUUXQv0`6|FLGU3n|63XCw|_bk`M>R&QE}1P(9+;!bC$SAq!F|)kD8-?|79YV6L+9X zQv-FZ2w5!p3p8o61uLl}5jSRGVj&>M6BsKe%0$Ey)l-6Ccnr%#s0tiVT4u;6s9sAU z8XTfT%2Z9Mg^W7arF#-zMAOsCoaVn%i_1&rudSa)u1+qi6FT2Er1tYqBa1=sbA38^ zs6(Gmnqx(t$=s>Zd9=bZG+1dlPMhcb_30smqj7w-Tw_2-(Rd^2JQ?eJ{-@XFv2@m) O4tv4%mDGd2Tlx>>!dw~v 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 ae0a7aa98e1c6fd9af67c9f3ff7225aecbabb368..8d4c06f1bb9cc4eda9af46a2cf2c0729a55f3034 100644 GIT binary patch delta 431 zcmex0FrWonzqS8I&2BZK@xY5tUz6o@b(O?wxDt93GOCY-s9SrX3bx zI@wWEd~(5LMfQSxuqBfpWQwVqo2D3;8k!m#8zq@1CmNYqrkSOfCnlw(7$uvSB%7Eg znkOeECz?;5P?-zYXMe_cbL5hGK{1$Hm8=w$poRinzWLPFlZ;BGNyW)Isfl^1MY_dB z$siTQXhM@0dWdeGv%Qg@3n4N2V3s$#v5Ap|p|Kgrd)mduW(AH}X+D7^W!|poC6R6c z9)>>U`RPs`0X~_gZWeA;1|~k9`TE)>CX*Rwi8JS?7f*KFEy@8ia&iN&sG7M^s!^J0 zVp>XCYD#K~c}lW@X{t$zVVZ%ZMOw14rJ;eDX=<|ZWW$G&li$qZnY>}C21^l!K?e;% MvXYx+j^CC70BC5MX8-^I delta 33 rcmV++0N(%d%>(zt1F&19vrMOb5wq>My8)A}NC~swx`7X~7|hxlH82rx diff --git a/flake.nix b/flake.nix index bd0632413d300f1ff2d41699a76c0fd4be13758e..b2960ea8903176c959790f1287a6ff0ac833d7be 100644 GIT binary patch delta 116 zcmbQ5`YmHasv1XXNl~RyUS`GQL{7QMVj|j;uSq3ME>KmT?5|)y`JA#GXF)zx$z%gI zwav+D|5!OnlZumbQWNtge^AwzE6PtVRVH@_JL#FQ0RT`w2bBN- 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; + }