2022-04-03 02:18:22 +00:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.yt-dlp;
|
|
|
|
|
2022-08-11 01:43:17 +00:00
|
|
|
serviceLevelArgs = lib.escapeShellArgs cfg.extraArgs;
|
|
|
|
|
2022-04-03 02:18:22 +00:00
|
|
|
jobType = { name, config, options, ... }: {
|
|
|
|
options = {
|
|
|
|
urls = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
A list of URLs to be downloaded to <command>yt-dlp</command>. Please
|
|
|
|
see the list of extractors with <option>--list-extractors</option>.
|
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
"https://www.youtube.com/c/ronillust"
|
|
|
|
"https://www.youtube.com/c/Jazza"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
startAt = lib.mkOption {
|
|
|
|
type = with lib.types; str;
|
|
|
|
description = ''
|
2022-07-21 01:54:00 +00:00
|
|
|
Indicates how frequent the download will occur. The given schedule
|
|
|
|
should follow the format as described from
|
2022-04-03 02:18:22 +00:00
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>systemd.time</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry>.
|
|
|
|
'';
|
|
|
|
default = "daily";
|
|
|
|
example = "*-*-3/4";
|
|
|
|
};
|
|
|
|
|
2022-07-21 01:54:00 +00:00
|
|
|
persistent = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
description = ''
|
|
|
|
Indicates whether the service will start if timer has missed.
|
|
|
|
Defaults to <literal>true</literal> since this module mainly assumes
|
|
|
|
it is used on the desktop.
|
|
|
|
'';
|
|
|
|
default = true;
|
|
|
|
defaultText = "true";
|
|
|
|
example = "false";
|
|
|
|
};
|
|
|
|
|
2022-04-03 02:18:22 +00:00
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description =
|
|
|
|
"Job-specific extra arguments to be passed to the <command>yt-dlp</command>.";
|
|
|
|
default = [ ];
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
2022-07-30 08:22:24 +00:00
|
|
|
"--date" "today"
|
2022-04-03 02:18:22 +00:00
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.services.yt-dlp = {
|
|
|
|
enable = lib.mkEnableOption "archiving service with yt-dlp";
|
|
|
|
|
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
description =
|
|
|
|
"The derivation that contains <command>yt-dlp</command> binary.";
|
|
|
|
default = pkgs.yt-dlp;
|
|
|
|
defaultText = lib.literalExpression "pkgs.yt-dlp";
|
|
|
|
example = lib.literalExpression
|
|
|
|
"pkgs.yt-dlp.override { phantomjsSupport = true; }";
|
|
|
|
};
|
|
|
|
|
|
|
|
archivePath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The location of the archive to be downloaded. Take note it is assumed
|
|
|
|
to be created at the time of running the service. Must be an absolute
|
|
|
|
path.
|
|
|
|
'';
|
2022-04-06 02:48:29 +00:00
|
|
|
default = "${
|
|
|
|
lib.replaceStrings [ "$HOME" ] [ config.home.homeDirectory ]
|
|
|
|
config.xdg.userDirs.videos
|
|
|
|
}/yt-dlp-service";
|
2022-04-03 02:18:22 +00:00
|
|
|
example = lib.literalExpression
|
|
|
|
"\${config.xdg.userDirs.download}/archiving-service/videos";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description =
|
|
|
|
"List of arguments to be passed to <command>yt-dlp</command>.";
|
|
|
|
default = [ "--download-archive '${cfg.archivePath}/download-list" ];
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
2022-07-30 08:22:24 +00:00
|
|
|
"--download-archive" "''${cfg.archivePath}/download-list"
|
|
|
|
"--concurrent-fragments" "2"
|
|
|
|
"--retries" "20"
|
2022-04-03 02:18:22 +00:00
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
jobs = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule jobType);
|
|
|
|
description = ''
|
|
|
|
A map of jobs for the archiving service.
|
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
arts = {
|
|
|
|
urls = [
|
|
|
|
"https://www.youtube.com/c/Jazza"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
2022-07-30 08:22:24 +00:00
|
|
|
extraArgs = [ "--date" "today" ];
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
compsci = {
|
|
|
|
urls = [
|
|
|
|
"https://www.youtube.com/c/K%C3%A1rolyZsolnai"
|
|
|
|
"https://www.youtube.com/c/TheCodingTrain"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.user.services = lib.mapAttrs' (name: value:
|
|
|
|
lib.nameValuePair "yt-dlp-archive-service-${name}" {
|
|
|
|
Unit = {
|
|
|
|
Description = "yt-dlp archive job for group '${name}'";
|
2022-07-26 12:04:08 +00:00
|
|
|
After = [ "default.target" ];
|
2022-04-03 02:18:22 +00:00
|
|
|
Documentation = "man:yt-dlp(1)";
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStartPre = ''
|
2022-04-06 02:48:29 +00:00
|
|
|
${pkgs.bash}/bin/bash -c "${pkgs.coreutils}/bin/mkdir -p ${
|
|
|
|
lib.escapeShellArg cfg.archivePath
|
|
|
|
}"
|
2022-04-03 02:18:22 +00:00
|
|
|
'';
|
|
|
|
ExecStart = let
|
2022-04-06 02:48:29 +00:00
|
|
|
scriptName =
|
|
|
|
"yt-dlp-archive-service-${config.home.username}-${name}";
|
2022-08-11 01:43:17 +00:00
|
|
|
jobLevelArgs = lib.escapeShellArgs value.extraArgs;
|
|
|
|
urls = lib.escapeShellArgs urls;
|
2022-04-03 02:18:22 +00:00
|
|
|
archiveScript = pkgs.writeShellScriptBin scriptName ''
|
2022-08-11 01:43:17 +00:00
|
|
|
${cfg.package}/bin/yt-dlp ${serviceLevelArgs} ${jobLevelArgs} \
|
|
|
|
${urls} --paths ${lib.escapeShellArg cfg.archivePath}
|
2022-04-03 02:18:22 +00:00
|
|
|
'';
|
|
|
|
in "${archiveScript}/bin/${scriptName}";
|
2022-08-31 06:37:49 +00:00
|
|
|
StandardOutput = "journal";
|
|
|
|
StandardError = "journal";
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
}) cfg.jobs;
|
|
|
|
|
|
|
|
systemd.user.timers = lib.mapAttrs' (name: value:
|
|
|
|
lib.nameValuePair "yt-dlp-archive-service-${name}" {
|
|
|
|
Unit = {
|
|
|
|
Description = "yt-dlp archive job for group '${name}'";
|
|
|
|
Documentation = "man:yt-dlp(1)";
|
|
|
|
};
|
|
|
|
|
|
|
|
Timer = {
|
|
|
|
OnCalendar = value.startAt;
|
2022-07-21 01:54:00 +00:00
|
|
|
RandomizedDelaySec = "2min";
|
|
|
|
Persistent = value.persistent;
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Install.WantedBy = [ "timers.target" ];
|
|
|
|
}) cfg.jobs;
|
|
|
|
};
|
|
|
|
}
|