2022-07-17 01:37:24 +00:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.tasks.multimedia-archive;
|
|
|
|
mountName = "/mnt/archives";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.tasks.multimedia-archive.enable =
|
|
|
|
lib.mkEnableOption "multimedia archiving setup";
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable (
|
|
|
|
let
|
2022-07-31 06:43:14 +00:00
|
|
|
ytdlpArgs = [
|
2022-07-17 01:37:24 +00:00
|
|
|
# Make a global list of successfully downloaded videos as a cache for yt-dlp.
|
2022-07-20 09:00:03 +00:00
|
|
|
"--download-archive" "${config.services.yt-dlp.archivePath}/videos"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# No overwriting of videos and related files.
|
|
|
|
"--no-force-overwrites"
|
|
|
|
|
|
|
|
# Embed metadata in the file.
|
|
|
|
"--write-info-json"
|
|
|
|
|
|
|
|
# Embed chapter markers, if possible.
|
|
|
|
"--embed-chapters"
|
|
|
|
|
2022-07-20 09:00:03 +00:00
|
|
|
# Write the subtitle file with the preferred languages.
|
2022-07-17 01:37:24 +00:00
|
|
|
"--write-subs"
|
2022-07-20 09:00:03 +00:00
|
|
|
"--sub-langs" "en.*,ja,ko,zh.*,fr,pt.*"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# Write the description in a separate file.
|
|
|
|
"--write-description"
|
|
|
|
|
|
|
|
# The global output for all of the jobs.
|
2022-07-20 09:00:03 +00:00
|
|
|
"--output" "%(uploader,artist,creator|Unknown)s/%(release_date>%F,upload_date>%F|Unknown)s-%(title)s.%(ext)s"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# Select only the most optimal format for my usecases.
|
2022-07-20 09:00:03 +00:00
|
|
|
"--format" "(webm,mkv,mp4)[height<=?1280]"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# Prefer MKV whenever possible for video formats.
|
2022-07-20 09:00:03 +00:00
|
|
|
"--merge-output-format" "mkv"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# Don't download any videos that are originally live streams.
|
2022-07-20 09:00:03 +00:00
|
|
|
"--match-filters" "!was_live"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# Prefer Vorbis when audio-only downloads are used.
|
2022-07-20 09:00:03 +00:00
|
|
|
"--audio-format" "vorbis"
|
|
|
|
"--audio-quality" "2"
|
2022-07-17 01:37:24 +00:00
|
|
|
];
|
2022-07-31 06:43:14 +00:00
|
|
|
ytdlpArchiveVariant = pkgs.writeScriptBin "yt-dlp-archive-variant" ''
|
|
|
|
${pkgs.yt-dlp}/bin/yt-dlp ${lib.escapeShellArgs ytdlpArgs}
|
2022-07-17 01:37:24 +00:00
|
|
|
'';
|
|
|
|
|
2022-07-31 06:43:14 +00:00
|
|
|
# Given an attribute set of jobs that contains a list of objects with
|
|
|
|
# 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 }:
|
2022-07-17 01:37:24 +00:00
|
|
|
let
|
|
|
|
days = [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ];
|
|
|
|
categories = lib.zipListsWith
|
|
|
|
(index: category: { inherit index; data = category; })
|
2022-07-31 06:43:14 +00:00
|
|
|
(lib.lists.range 1 (lib.length (lib.attrValues db)))
|
|
|
|
(lib.mapAttrsToList (name: value: { inherit name; subscriptions = value; }) db);
|
2022-07-17 01:37:24 +00:00
|
|
|
jobsList = builtins.map
|
|
|
|
(category: {
|
|
|
|
name = category.data.name;
|
|
|
|
value = {
|
2022-07-31 06:43:14 +00:00
|
|
|
inherit extraArgs;
|
2022-07-17 01:37:24 +00:00
|
|
|
urls = builtins.map (subscription: subscription.url) category.data.subscriptions;
|
|
|
|
startAt = lib.elemAt days (lib.mod category.index (lib.length days));
|
2022-07-22 11:05:08 +00:00
|
|
|
persistent = true;
|
2022-07-17 01:37:24 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
categories;
|
|
|
|
in
|
|
|
|
lib.listToAttrs jobsList;
|
2022-07-31 06:43:14 +00:00
|
|
|
|
|
|
|
readJSON = jsonFile: builtins.fromJSON (builtins.readFile jsonFile);
|
2022-07-17 01:37:24 +00:00
|
|
|
in
|
|
|
|
{
|
2022-07-31 06:43:14 +00:00
|
|
|
environment.systemPackages = [ ytdlpArchiveVariant ];
|
2022-07-20 09:00:03 +00:00
|
|
|
|
|
|
|
sops.secrets =
|
|
|
|
let
|
|
|
|
getKey = key: {
|
|
|
|
inherit key;
|
|
|
|
sopsFile = lib.getSecret "multimedia-archive.yaml";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"multimedia-archive/secrets-config" = getKey "secrets-config";
|
|
|
|
};
|
|
|
|
|
2022-07-17 01:37:24 +00:00
|
|
|
fileSystems."${mountName}" = {
|
|
|
|
device = "/dev/disk/by-uuid/6ba86a30-5fa4-41d9-8354-fa8af0f57f49";
|
|
|
|
fsType = "btrfs";
|
|
|
|
noCheck = true;
|
|
|
|
options = [
|
|
|
|
# These are btrfs-specific mount options which can found in btrfs.5
|
|
|
|
# manual page.
|
|
|
|
"subvol=@"
|
|
|
|
"noatime"
|
|
|
|
"compress=zstd:9"
|
|
|
|
"space_cache=v2"
|
|
|
|
|
|
|
|
# General mount options from mount.5 manual page.
|
|
|
|
"noauto"
|
|
|
|
"nofail"
|
|
|
|
"user"
|
|
|
|
|
|
|
|
# See systemd.mount.5 and systemd.automount.5 manual page for more
|
|
|
|
# details.
|
|
|
|
"x-systemd.automount"
|
|
|
|
"x-systemd.idle-timeout=2"
|
|
|
|
"x-systemd.device-timeout=2"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.yt-dlp = {
|
|
|
|
enable = true;
|
|
|
|
archivePath = "${mountName}/yt-dlp-service";
|
|
|
|
|
|
|
|
# This is applied on all jobs. It is best to be minimal as much as
|
|
|
|
# possible for this.
|
2022-07-31 06:43:14 +00:00
|
|
|
extraArgs = ytdlpArgs;
|
2022-07-17 01:37:24 +00:00
|
|
|
|
2022-07-31 06:43:14 +00:00
|
|
|
jobs = mkJobs {
|
|
|
|
extraArgs = [ "--playlist-end" "20" ];
|
2022-08-01 12:08:30 +00:00
|
|
|
db = readJSON ./newpipe-db.json;
|
2022-07-31 06:43:14 +00:00
|
|
|
};
|
2022-07-17 01:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.archivebox = {
|
|
|
|
enable = true;
|
|
|
|
archivePath = "${mountName}/archivebox-service";
|
|
|
|
withDependencies = true;
|
|
|
|
webserver.enable = true;
|
|
|
|
|
|
|
|
jobs = {
|
|
|
|
arts = {
|
2022-07-31 06:43:14 +00:00
|
|
|
urls = [
|
2022-07-17 01:37:24 +00:00
|
|
|
"https://www.davidrevoy.com/feed/rss"
|
|
|
|
"https://librearts.org/index.xml"
|
|
|
|
];
|
|
|
|
startAt = "monthly";
|
2022-07-31 06:43:14 +00:00
|
|
|
persistent = true;
|
2022-07-17 01:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
computer = {
|
2022-07-31 06:43:14 +00:00
|
|
|
urls = [
|
2022-07-17 01:37:24 +00:00
|
|
|
"https://blog.mozilla.org/en/feed/"
|
|
|
|
"https://distill.pub/rss.xml"
|
|
|
|
"https://drewdevault.com/blog/index.xml"
|
|
|
|
"https://fasterthanli.me/index.xml"
|
|
|
|
"https://jvns.ca/atom.xml"
|
|
|
|
"https://www.bytelab.codes/rss/"
|
|
|
|
"https://www.collabora.com/feed"
|
|
|
|
"https://www.jntrnr.com/atom.xml"
|
|
|
|
"https://yosoygames.com.ar/wp/?feed=rss"
|
|
|
|
"https://simblob.blogspot.com/feeds/posts/default"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
2022-07-31 06:43:14 +00:00
|
|
|
persistent = true;
|
2022-07-17 01:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
projects = {
|
2022-07-31 06:43:14 +00:00
|
|
|
urls = [
|
2022-07-17 01:37:24 +00:00
|
|
|
"https://veloren.net/rss.xml"
|
|
|
|
"https://guix.gnu.org/feeds/blog.atom"
|
|
|
|
"https://fedoramagazine.org/feed/"
|
|
|
|
"https://nixos.org/blog/announcements-rss.xml"
|
|
|
|
];
|
|
|
|
# Practically every 14 days.
|
|
|
|
startAt = "Mon *-*-1/14";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.gallery-dl = {
|
|
|
|
enable = true;
|
|
|
|
archivePath = "${mountName}/gallery-dl-service";
|
|
|
|
|
|
|
|
extraArgs = [
|
|
|
|
# Record all downloaded files in an archive file.
|
2022-07-20 08:55:23 +00:00
|
|
|
"--download-archive" "${config.services.gallery-dl.archivePath}/photos"
|
2022-07-17 01:37:24 +00:00
|
|
|
|
|
|
|
# Write metadata to separate JSON files.
|
|
|
|
"--write-metadata"
|
2022-07-20 09:00:03 +00:00
|
|
|
|
|
|
|
# The config file that contains the secrets for various services.
|
|
|
|
# We're putting as a separate config file instead of configuring it
|
|
|
|
# in the service properly since secrets decrypted by sops-nix cannot
|
|
|
|
# be read in Nix.
|
|
|
|
"--config" "${config.sops.secrets."multimedia-archive/secrets-config".path}"
|
2022-07-17 01:37:24 +00:00
|
|
|
];
|
|
|
|
|
2022-07-20 09:00:03 +00:00
|
|
|
settings.extractor = {
|
|
|
|
filename = "{date:%F}-{title}.{extension}";
|
|
|
|
};
|
|
|
|
|
2022-07-17 01:37:24 +00:00
|
|
|
jobs = {
|
|
|
|
arts = {
|
|
|
|
urls = [
|
|
|
|
"https://www.deviantart.com/xezeno" # Xezeno
|
|
|
|
#"https://www.pixiv.net/en/users/60562229" # Ravioli
|
|
|
|
"https://www.artstation.com/kuvshinov_ilya" # Ilya Kuvshinov
|
|
|
|
"https://www.artstation.com/meiipng" # Meiiart
|
|
|
|
"https://www.artstation.com/bassem_wageeh" # Bassem wageeh
|
|
|
|
"https://hyperjerk.newgrounds.com" # HyperJerk
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
2022-07-22 11:05:08 +00:00
|
|
|
persistent = true;
|
2022-07-17 01:37:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|