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

37 lines
1001 B
Nix

# SPDX-FileCopyrightText: 2021-2023 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{ 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^=vp09]" "bestvideo[vcodec^=avc1]" "bestvideo" ];
zAudioFormat = [ "bestaudio[acodec^=opus]" "bestaudio[acodec^=mp4a]" "bestaudio" ];
})) ++ [ "best" ];
options = {
format = lib.concatStringsSep "/" formats;
};
textConfig = lib.concatStringsSep
"\n"
(lib.mapAttrsToList
(k: v: "--${k} ${v}")
options);
in
{
xdg.configFile = {
"youtube-dl/config".text = textConfig;
"yt-dlp/config".text = textConfig;
};
home.packages = with pkgs; [
youtube-dl
unstable.yt-dlp
];
}