ytptube: added webhook to ntfy

This commit is contained in:
Tigor Hutasuhut 2024-09-19 02:34:46 +07:00
parent a0a1bf837e
commit b786265aa6

View file

@ -15,6 +15,20 @@ let
password = "caddy/basic_auth/password"; password = "caddy/basic_auth/password";
template = "caddy/basic_auth"; template = "caddy/basic_auth";
}; };
webhook = builtins.readFile ((pkgs.formats.json { }).generate "webhooks.json" [
{
name = "NTFY Webhook";
on = [ "added" "completed" "error" "not_live" ];
request = {
url = "https://ntfy.tigor.web.id/ytptube?tpl=1&t=%7B%7B.title%7D%7D&m=%5B%7B%7B%20.folder%20%7D%7D%5D%20Download%20%7B%7B%20.status%20%7D%7D";
type = "json";
method = "POST";
headers = {
Authorization = ''Bearer ${config.sops.placeholder."ntfy/tokens/homeserver"}'';
};
};
}
]);
in in
{ {
config = mkIf (podman.enable && podman.${name}.enable) { config = mkIf (podman.enable && podman.${name}.enable) {
@ -34,20 +48,7 @@ in
YTPTUBE_PASSWORD=${config.sops.placeholder.${basic_auth.password}} YTPTUBE_PASSWORD=${config.sops.placeholder.${basic_auth.password}}
''; '';
"ytptube/webhooks.json" = mkIf config.services.ntfy-sh.enable { "ytptube/webhooks.json" = mkIf config.services.ntfy-sh.enable {
content = builtins.readFile ((pkgs.formats.json { }).generate "webhooks.json" [ content = webhook;
{
name = "NTFY Webhook";
on = [ "added" "completed" "error" "not_live" ];
request = {
url = "https://ntfy.tigor.web.id/ytptube?tpl=1&t=%7B%7B.title%7D%7D&m=%5B%7B%7B%20.folder%20%7D%7D%5D%20Download%20%7B%7B%20.status%20%7D%7D&Click=https%3A%2F%2F%7B%7B.url%7D%7D";
type = "json";
method = "POST";
headers = {
Authorization = ''Bearer ${config.sops.placeholder."ntfy/tokens/homeserver"}'';
};
};
}
]);
path = "/etc/podman/${name}/webhooks.json"; path = "/etc/podman/${name}/webhooks.json";
owner = config.profile.user.name; owner = config.profile.user.name;
}; };
@ -71,6 +72,8 @@ in
EnvironmentFile = [ config.sops.templates.${basic_auth.template}.path ]; EnvironmentFile = [ config.sops.templates.${basic_auth.template}.path ];
}; };
systemd.services."podman-${name}".restartTriggers = [ webhook ];
environment.etc."podman/${name}/ytdlp.json" = { environment.etc."podman/${name}/ytdlp.json" = {
# https://github.com/arabcoders/ytptube?tab=readme-ov-file#ytdlpjson-file # https://github.com/arabcoders/ytptube?tab=readme-ov-file#ytdlpjson-file
source = (pkgs.formats.json { }).generate "config.json" { source = (pkgs.formats.json { }).generate "config.json" {