From afbfc0f4e410a9fefd5aa2f1c818ae8271c77f17 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 19 Feb 2023 16:42:21 +0100 Subject: Improve yt-dlp service - allow configuring odd or even days (useful for future get-iplayer service so they run on alternating days) - auto-update yt-dlp if not using the system package --- tw/services/media.scm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tw/services') diff --git a/tw/services/media.scm b/tw/services/media.scm index 4bff1818..5fd5b2b5 100644 --- a/tw/services/media.scm +++ b/tw/services/media.scm @@ -15,10 +15,10 @@ (define (string-or-gexp? value) (or (string? value) (gexp? value))) -(define random-time-every-second-night +(define (random-time-every-second-night day-predicate) #~(lambda (now) (let* ((even-day - (if (even? (tm:yday (localtime now))) + (if (#$day-predicate (tm:yday (localtime now))) now (next-day-from now))) (deterministic-value @@ -30,13 +30,15 @@ (next-hour-from even-day (list (1+ (string-hash deterministic-value 6)))) (list (string-hash deterministic-value 60)))))) + + (define-configuration/no-serialization yt-dlp-configuration (media-directory string "The directory in which to store downloaded media. The service expects a @code{.yt-dlp} config directory inside this one.") (yt-dlp (package-or-false yt-dlp) "The yt-dlp package to use; or @code{#false} to use the yt-dlp script inside the config directory.") - (schedule (string-or-gexp random-hour-every-second-night) "The mcron -schedule on which to run the download script. By default, picks a random hour + (schedule (string-or-gexp (random-time-every-second-night 'even?)) "The mcron +schedule on which to run the download script. By default, picks a random time between 01:00 and 06:00 every second night.") (user (string "root") "The Unix user name to run the script as.") (group (string "root") "The Unix group name to run the script as.")) @@ -55,6 +57,8 @@ between 01:00 and 06:00 every second night.") ;; `setgid' first while we're still root (setgid (group:gid (getgr #$(yt-dlp-configuration-group config)))) (setuid (passwd:uid (getpw #$(yt-dlp-configuration-user config)))) + #$@(if yt-dlp-package '() + (list #~(system* #$yt-dlp-executable "--ignore-config" "--update"))) (execl #$yt-dlp-executable "yt-dlp" "--ignore-config" "--config-location" ".yt-dlp")) ;; Human-readable string for `herd schedule mcron'. -- cgit v1.2.3