2023-03-03 23:12:20 -05:00
|
|
|
{
|
|
|
|
description = "MPV overlay with scripts and configuration for watching anime";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
2023-03-04 00:08:57 -05:00
|
|
|
outputs = { self, nixpkgs, utils }: let
|
|
|
|
packages = utils.lib.eachDefaultSystem (system: let
|
2023-03-03 23:12:20 -05:00
|
|
|
pkgs = import nixpkgs { inherit system; };
|
2023-04-23 02:19:36 -04:00
|
|
|
mpvScript = { owner, repo, rev, sha256, scriptName }: pkgs.stdenvNoCC.mkDerivation {
|
2023-03-03 23:12:20 -05:00
|
|
|
pname = repo;
|
|
|
|
version = builtins.substring 0 6 rev;
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
inherit owner repo rev sha256;
|
|
|
|
};
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
|
|
install -Dm644 ${scriptName} $out/share/mpv/scripts/${scriptName}
|
|
|
|
'';
|
|
|
|
passthru = { inherit scriptName; };
|
|
|
|
};
|
2023-03-04 00:08:57 -05:00
|
|
|
in {
|
|
|
|
packages.sub-select = mpvScript {
|
2023-03-03 23:12:20 -05:00
|
|
|
owner = "CogentRedTester";
|
|
|
|
repo = "mpv-sub-select";
|
|
|
|
rev = "5d2fb7ab73fc0e36d44109e75c9be26bd42084e2";
|
|
|
|
sha256 = "0dyh2kyvivj81lrkyqhc3czmi9hqjkh7xg8dqjnnr3kh3yn62dpi";
|
|
|
|
scriptName = "sub-select.lua";
|
|
|
|
};
|
|
|
|
|
2023-03-04 00:08:57 -05:00
|
|
|
packages.segment-linking = mpvScript {
|
2023-03-03 23:12:20 -05:00
|
|
|
owner = "CogentRedTester";
|
|
|
|
repo = "mpv-segment-linking";
|
|
|
|
rev = "bb0fdb7961859df57c64b42d75dbbd60a4024e97";
|
|
|
|
sha256 = "1ykl24p96wwka4fillrzni6i0xkk4s2l9zg1scqypcbs5w491qsj";
|
|
|
|
scriptName = "segment-linking.lua";
|
|
|
|
};
|
2023-03-04 00:08:57 -05:00
|
|
|
});
|
|
|
|
in
|
|
|
|
packages // rec {
|
|
|
|
overlays.default = final: prev: let
|
|
|
|
newScripts = packages.packages.${prev.system};
|
2023-04-23 02:19:19 -04:00
|
|
|
in {
|
|
|
|
mpv = prev.mpv.override { scripts = builtins.attrValues newScripts; };
|
2023-03-04 00:08:57 -05:00
|
|
|
mpvScripts = prev.mpvScripts // newScripts;
|
|
|
|
};
|
2023-03-03 23:12:20 -05:00
|
|
|
|
2023-03-04 00:08:57 -05:00
|
|
|
nixosModules.default = { pkgs, lib, ... }: {
|
|
|
|
nixpkgs.overlays = [ overlays.default ];
|
2023-03-03 23:12:20 -05:00
|
|
|
|
|
|
|
# needed for mpv segment-linking plugin
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.mkvtoolnix
|
|
|
|
];
|
|
|
|
|
2023-04-23 02:19:36 -04:00
|
|
|
home-manager.sharedModules = [ ({ config, ... }: {
|
|
|
|
config = lib.mkIf config.programs.mpv.enable {
|
2025-01-19 00:08:55 -05:00
|
|
|
xdg.configFile."mpv/script-opts/sub-select.json".text = let
|
|
|
|
signs = [ "sign" "song" "s&s" ];
|
|
|
|
in builtins.toJSON [
|
2023-07-21 21:19:59 -04:00
|
|
|
# English audio:
|
|
|
|
# 1. English signs/songs subs
|
|
|
|
# 2. Forced subs
|
|
|
|
# 3. No subs
|
2023-04-23 02:19:36 -04:00
|
|
|
{
|
|
|
|
alang = "eng?";
|
2023-07-21 21:19:59 -04:00
|
|
|
slang = "eng?";
|
2025-01-19 00:08:55 -05:00
|
|
|
whitelist = signs;
|
2023-04-23 02:19:36 -04:00
|
|
|
}
|
|
|
|
{
|
|
|
|
alang = "eng?";
|
2023-07-21 21:19:59 -04:00
|
|
|
slang = "forced";
|
2023-04-23 02:19:36 -04:00
|
|
|
}
|
|
|
|
{
|
|
|
|
alang = [ "eng?" "no" ];
|
|
|
|
slang = "no";
|
|
|
|
}
|
2023-07-21 21:19:59 -04:00
|
|
|
|
|
|
|
# Non-English audio:
|
2024-02-27 23:18:30 -05:00
|
|
|
# 1. English non-signs non-forced subs, default subs iff default audio
|
|
|
|
# 2. English non-signs non-forced subs
|
|
|
|
# 3. English non-signs forced subs
|
|
|
|
# 4. Undefined non-signs non-forced subs, default subs iff default audio
|
|
|
|
# 5. Undefined non-signs non-forced subs
|
|
|
|
# 6. Undefined non-signs forced subs
|
|
|
|
# 7. English signs/songs subs, I guess
|
|
|
|
# 8. Undefined signs/songs subs, I guess
|
|
|
|
# 9. Forced subs in other languages, I guess
|
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "eng?";
|
2025-01-19 00:08:55 -05:00
|
|
|
blacklist = signs;
|
2024-02-27 23:18:30 -05:00
|
|
|
condition = "not sub.forced and ((audio.default and sub.default) or (not audio.default and not sub.default))";
|
|
|
|
}
|
2023-04-23 02:19:36 -04:00
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "eng?";
|
2025-01-19 00:08:55 -05:00
|
|
|
blacklist = signs;
|
2023-04-23 02:19:36 -04:00
|
|
|
condition = "not sub.forced";
|
|
|
|
}
|
2023-07-21 21:19:59 -04:00
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "eng?";
|
2025-01-19 00:08:55 -05:00
|
|
|
blacklist = signs;
|
2023-07-21 21:19:59 -04:00
|
|
|
}
|
2024-02-27 23:18:30 -05:00
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "und";
|
2025-01-19 00:08:55 -05:00
|
|
|
blacklist = signs;
|
2024-02-27 23:18:30 -05:00
|
|
|
condition = "not sub.forced and ((audio.default and sub.default) or (not audio.default and not sub.default))";
|
|
|
|
}
|
2023-04-23 02:19:36 -04:00
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "und";
|
2025-01-19 00:08:55 -05:00
|
|
|
blacklist = signs;
|
2023-04-23 02:19:36 -04:00
|
|
|
condition = "not sub.forced";
|
|
|
|
}
|
2023-07-21 21:19:59 -04:00
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "und";
|
2025-01-19 00:08:55 -05:00
|
|
|
blacklist = signs;
|
2023-07-21 21:19:59 -04:00
|
|
|
}
|
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "eng?";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "und";
|
|
|
|
}
|
2023-04-23 02:19:36 -04:00
|
|
|
{
|
|
|
|
alang = "*";
|
|
|
|
slang = "forced";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}) ];
|
2023-03-03 23:12:20 -05:00
|
|
|
};
|
2023-03-04 00:08:57 -05:00
|
|
|
};
|
2023-03-03 23:12:20 -05:00
|
|
|
}
|