nixos-config/users/simon/modules/youtube-dl.nix

27 lines
784 B
Nix

{ lib, pkgs, ... }:
let
# zAudioFormat because a better video format is preferred and
# cartesianProductOfSets cycles through the attributes in lexicographic order
formats = (map
({ videoFormat, zAudioFormat }: "${videoFormat}+${zAudioFormat}")
(lib.cartesianProductOfSets {
videoFormat = [ "bestvideo[vcodec^=av01]" "bestvideo[vcodec^=vp9]" "bestvideo[vcodec^=avc1]" "bestvideo" ];
zAudioFormat = [ "bestaudio[acodec^=opus]" "bestaudio[acodec^=mp4a]" "bestaudio" ];
})) ++ [ "best" ];
options = {
format = lib.concatStringsSep "/" formats;
};
in
{
xdg.configFile."youtube-dl/config".text = lib.concatStringsSep
"\n"
(lib.mapAttrsToList
(k: v: "--${k} ${v}")
options);
home.packages = with pkgs; [
youtube-dl
];
}