add youtube downloader script
This commit is contained in:
parent
ccf80a7e91
commit
ab532b1b79
3 changed files with 116 additions and 1 deletions
|
@ -27,6 +27,7 @@
|
|||
./media-audiobookshelf.nix
|
||||
./media-tdarr.nix
|
||||
./media-jellyfin.nix
|
||||
./media-youtube.nix
|
||||
|
||||
# logging
|
||||
./loki.nix
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
internalNode = "false";
|
||||
inContainer = "true";
|
||||
nodeName = "ServerNode";
|
||||
TZ = "Europe/London";
|
||||
TZ = "Europe/Berlin";
|
||||
PUID = toString config.users.users.media.uid;
|
||||
PGID = toString config.users.groups.media.gid;
|
||||
};
|
||||
|
|
114
nixos/machines/chungus/media-youtube.nix
Normal file
114
nixos/machines/chungus/media-youtube.nix
Normal file
|
@ -0,0 +1,114 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
configuration = {
|
||||
druck7 = {
|
||||
url = "https://www.youtube.com/watch?list=PLUQncgYMM1RmN41ni6iDmBRg5Cos_bD--";
|
||||
target = "/media/youtube/series/Druck";
|
||||
output = "Druck S07E%(playlist_index)s %(title)s.%(ext)s";
|
||||
};
|
||||
druck8 = {
|
||||
url = "https://www.youtube.com/watch?list=PLUQncgYMM1RlzMSECHQDOHx2A4l4G-7yX";
|
||||
target = "/media/youtube/series/Druck";
|
||||
output = "Druck S08E%(playlist_index)s %(title)s.%(ext)s";
|
||||
};
|
||||
ordinary_things = {
|
||||
url = "https://www.youtube.com/@OrdinaryThings";
|
||||
target = "/media/youtube/series/Ordinary Things";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
internet_historian = {
|
||||
url = "https://www.youtube.com/@InternetHistorian";
|
||||
target = "/media/youtube/series/Internet Historian";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
bigboss = {
|
||||
url = "https://www.youtube.com/@bigbosstube";
|
||||
target = "/media/youtube/series/Big Boss";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
CGPGrey = {
|
||||
url = "https://www.youtube.com/@CGPGrey";
|
||||
target = "/media/youtube/series/CGP Grey";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
Joeseppi = {
|
||||
url = "https://www.youtube.com/@Joeseppi";
|
||||
target = "/media/youtube/series/Joeseppi";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
HungrigerHugo = {
|
||||
url = "https://www.youtube.com/@HungrigerHugo";
|
||||
target = "/media/youtube/series/HungrigerHugo";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
Kurzgesagt = {
|
||||
url = "https://www.youtube.com/@KurzgesagtDE";
|
||||
target = "/media/youtube/series/Kurzgesagt";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
Simplicissimus = {
|
||||
url = "https://www.youtube.com/@Simplicissimus";
|
||||
target = "/media/youtube/series/Simplicissimus";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
Soosenbinder = {
|
||||
url = "https://www.youtube.com/@Soosenbinder";
|
||||
target = "/media/youtube/series/Soosenbinder";
|
||||
output = "%(channel)s S%(upload_date>%Y)sE%(upload_date>%m%d)s %(title)s.%(ext)s";
|
||||
};
|
||||
};
|
||||
|
||||
downloadScript =
|
||||
name: { url
|
||||
, target
|
||||
, output
|
||||
, sponsorBlockCategories ? [ "default" ]
|
||||
, notOlderThan ? "" # e.g: 1week
|
||||
, breakOnExisting ? true
|
||||
}: pkgs.writers.writeDash "download-script-${name}" ''
|
||||
mkdir -p "${target}"
|
||||
yt-dlp \
|
||||
--no-abort-on-error \
|
||||
--no-mark-watched \
|
||||
--continue \
|
||||
${optionalString (notOlderThan != "") "--dateafter now-${notOlderThan}" } \
|
||||
--playlist-reverse \
|
||||
--download-archive "${target}/.downloaded.txt" \
|
||||
--output "${target}/${output}" \
|
||||
--format "bestvideo[ext=mp4]+bestaudio[ext=m4a]" \
|
||||
--merge-output-format mp4 \
|
||||
--add-metadata \
|
||||
--write-thumbnail \
|
||||
--convert-thumbnail jpg \
|
||||
--sponsorblock-mark "default" \
|
||||
${optionalString (sponsorBlockCategories != []) "--sponsorblock-remove ${concatStringsSep "," sponsorBlockCategories}" } \
|
||||
${optionalString breakOnExisting "--break-on-existing" } \
|
||||
"${url}" || true
|
||||
'';
|
||||
|
||||
in
|
||||
{
|
||||
|
||||
systemd.services.youtube = {
|
||||
after = [ "network.target" ];
|
||||
path = [ pkgs.yt-dlp ];
|
||||
serviceConfig = {
|
||||
User = "media";
|
||||
Group = "media";
|
||||
};
|
||||
script = (concatStringsSep "\n"
|
||||
(mapAttrsToList downloadScript configuration)
|
||||
);
|
||||
};
|
||||
|
||||
systemd.timers.youtube = {
|
||||
enable = true;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = "true";
|
||||
};
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue