mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-14 12:19:00 +00:00
tasks/multimedia-archive: refactor
This commit is contained in:
parent
4dd2acfe7f
commit
d423e7d692
@ -10,7 +10,7 @@ in
|
|||||||
|
|
||||||
config = lib.mkIf cfg.enable (
|
config = lib.mkIf cfg.enable (
|
||||||
let
|
let
|
||||||
yt-dlp-args = [
|
ytdlpArgs = [
|
||||||
# Make a global list of successfully downloaded videos as a cache for yt-dlp.
|
# Make a global list of successfully downloaded videos as a cache for yt-dlp.
|
||||||
"--download-archive" "${config.services.yt-dlp.archivePath}/videos"
|
"--download-archive" "${config.services.yt-dlp.archivePath}/videos"
|
||||||
|
|
||||||
@ -46,36 +46,39 @@ in
|
|||||||
"--audio-format" "vorbis"
|
"--audio-format" "vorbis"
|
||||||
"--audio-quality" "2"
|
"--audio-quality" "2"
|
||||||
];
|
];
|
||||||
yt-dlp-archive-variant = pkgs.writeScriptBin "yt-dlp-archive-variant" ''
|
ytdlpArchiveVariant = pkgs.writeScriptBin "yt-dlp-archive-variant" ''
|
||||||
${pkgs.yt-dlp}/bin/yt-dlp ${lib.escapeShellArgs yt-dlp-args}
|
${pkgs.yt-dlp}/bin/yt-dlp ${lib.escapeShellArgs ytdlpArgs}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Given an attribute set of URLs, create a yt-dlp service config that does the following.
|
# Given an attribute set of jobs that contains a list of objects with
|
||||||
create-yt-dlp-service-config = newpipe-db:
|
# their names and URL, create an attrset suitable for declaring the
|
||||||
|
# archiving jobs of several services for `services.yt-dlp`,
|
||||||
|
# `services.gallery-dl`, and `services.archivebox`.
|
||||||
|
mkJobs = { extraArgs ? [], db }:
|
||||||
let
|
let
|
||||||
days = [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ];
|
days = [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ];
|
||||||
categories = lib.zipListsWith
|
categories = lib.zipListsWith
|
||||||
(index: category: { inherit index; data = category; })
|
(index: category: { inherit index; data = category; })
|
||||||
(lib.lists.range 1 (lib.length (lib.attrValues newpipe-db)))
|
(lib.lists.range 1 (lib.length (lib.attrValues db)))
|
||||||
(lib.mapAttrsToList (name: value: { inherit name; subscriptions = value; }) newpipe-db);
|
(lib.mapAttrsToList (name: value: { inherit name; subscriptions = value; }) db);
|
||||||
jobsList = builtins.map
|
jobsList = builtins.map
|
||||||
(category: {
|
(category: {
|
||||||
name = category.data.name;
|
name = category.data.name;
|
||||||
value = {
|
value = {
|
||||||
|
inherit extraArgs;
|
||||||
urls = builtins.map (subscription: subscription.url) category.data.subscriptions;
|
urls = builtins.map (subscription: subscription.url) category.data.subscriptions;
|
||||||
startAt = lib.elemAt days (lib.mod category.index (lib.length days));
|
startAt = lib.elemAt days (lib.mod category.index (lib.length days));
|
||||||
extraArgs = [
|
|
||||||
"--playlist-end" "20" # Only check the last 20 videos.
|
|
||||||
];
|
|
||||||
persistent = true;
|
persistent = true;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
categories;
|
categories;
|
||||||
in
|
in
|
||||||
lib.listToAttrs jobsList;
|
lib.listToAttrs jobsList;
|
||||||
|
|
||||||
|
readJSON = jsonFile: builtins.fromJSON (builtins.readFile jsonFile);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
environment.systemPackages = [ yt-dlp-archive-variant ];
|
environment.systemPackages = [ ytdlpArchiveVariant ];
|
||||||
|
|
||||||
sops.secrets =
|
sops.secrets =
|
||||||
let
|
let
|
||||||
@ -119,9 +122,12 @@ in
|
|||||||
|
|
||||||
# This is applied on all jobs. It is best to be minimal as much as
|
# This is applied on all jobs. It is best to be minimal as much as
|
||||||
# possible for this.
|
# possible for this.
|
||||||
extraArgs = yt-dlp-args;
|
extraArgs = ytdlpArgs;
|
||||||
|
|
||||||
jobs = create-yt-dlp-service-config (builtins.fromJSON (builtins.readFile ./newpipe-db.json));
|
jobs = mkJobs {
|
||||||
|
extraArgs = [ "--playlist-end" "20" ];
|
||||||
|
attrs = readJSON ./newpipe-db.json;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.archivebox = {
|
services.archivebox = {
|
||||||
@ -132,15 +138,16 @@ in
|
|||||||
|
|
||||||
jobs = {
|
jobs = {
|
||||||
arts = {
|
arts = {
|
||||||
links = [
|
urls = [
|
||||||
"https://www.davidrevoy.com/feed/rss"
|
"https://www.davidrevoy.com/feed/rss"
|
||||||
"https://librearts.org/index.xml"
|
"https://librearts.org/index.xml"
|
||||||
];
|
];
|
||||||
startAt = "monthly";
|
startAt = "monthly";
|
||||||
|
persistent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
computer = {
|
computer = {
|
||||||
links = [
|
urls = [
|
||||||
"https://blog.mozilla.org/en/feed/"
|
"https://blog.mozilla.org/en/feed/"
|
||||||
"https://distill.pub/rss.xml"
|
"https://distill.pub/rss.xml"
|
||||||
"https://drewdevault.com/blog/index.xml"
|
"https://drewdevault.com/blog/index.xml"
|
||||||
@ -153,10 +160,11 @@ in
|
|||||||
"https://simblob.blogspot.com/feeds/posts/default"
|
"https://simblob.blogspot.com/feeds/posts/default"
|
||||||
];
|
];
|
||||||
startAt = "weekly";
|
startAt = "weekly";
|
||||||
|
persistent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
projects = {
|
projects = {
|
||||||
links = [
|
urls = [
|
||||||
"https://veloren.net/rss.xml"
|
"https://veloren.net/rss.xml"
|
||||||
"https://guix.gnu.org/feeds/blog.atom"
|
"https://guix.gnu.org/feeds/blog.atom"
|
||||||
"https://fedoramagazine.org/feed/"
|
"https://fedoramagazine.org/feed/"
|
||||||
|
Loading…
Reference in New Issue
Block a user