From 5bb88492c2da0d99894337d6dbfdd0b809e5e621 Mon Sep 17 00:00:00 2001 From: clerie Date: Wed, 18 Jan 2023 20:40:45 +0100 Subject: [PATCH] hosts/storage-2: optimize music scraper --- hosts/storage-2/mixcloud.nix | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hosts/storage-2/mixcloud.nix b/hosts/storage-2/mixcloud.nix index 02a534c..9967765 100644 --- a/hosts/storage-2/mixcloud.nix +++ b/hosts/storage-2/mixcloud.nix @@ -25,11 +25,13 @@ let Group = "data-mixcloud"; Restart="on-failure"; }; + wants = [ "youtube-dl-prepare.service" ]; + after = [ "youtube-dl-prepare.service" ]; path = [ pkgs.youtube-dl ]; script = '' mkdir -p /data/mixcloud/${source}/ cd /data/mixcloud/${source}/ - youtube-dl --ignore-errors --playlist-random --newline ${url} + youtube-dl --ignore-errors --playlist-random --newline -x --audio-format mp3 ${url} ''; startAt = "*-*-* 05:05:00"; } @@ -67,6 +69,17 @@ in { }; users.groups.data-mixcloud = {}; - systemd.services = (mapAttrs' generateYoutubedlMixcloudUnits mixcloudSources); + systemd.services = { + "youtube-dl-prepare" = { + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = "true"; + }; + script = '' + mkdir -p /data/mixcloud + chown -R data-mixcloud:data-mixcloud /data/mixcloud + ''; + }; + } // (mapAttrs' generateYoutubedlMixcloudUnits mixcloudSources); systemd.timers = (mapAttrs' generateYoutubedlMixcloudTimers mixcloudSources); }