aboutsummaryrefslogtreecommitdiff
path: root/tw/services/media.scm
diff options
context:
space:
mode:
authorTimo Wilken2023-02-19 16:42:21 +0100
committerTimo Wilken2023-02-19 16:42:21 +0100
commitafbfc0f4e410a9fefd5aa2f1c818ae8271c77f17 (patch)
tree6c3712634b9dce1a0ce995321ce58c7f7fd3506d /tw/services/media.scm
parent1e9051ac4b608b35b7a47536e03ba677871f7409 (diff)
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
Diffstat (limited to 'tw/services/media.scm')
-rw-r--r--tw/services/media.scm12
1 files changed, 8 insertions, 4 deletions
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'.