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

37 lines
1001 B
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2021-2023 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
2021-02-08 20:40:54 +01:00
{ 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" ];
2021-02-08 20:40:54 +01:00
options = {
format = lib.concatStringsSep "/" formats;
};
textConfig = lib.concatStringsSep
2021-02-08 20:40:54 +01:00
"\n"
(lib.mapAttrsToList
(k: v: "--${k} ${v}")
options);
in
{
xdg.configFile = {
"youtube-dl/config".text = textConfig;
"yt-dlp/config".text = textConfig;
};
2021-02-08 20:40:54 +01:00
home.packages = with pkgs; [
youtube-dl
unstable.yt-dlp
2021-02-08 20:40:54 +01:00
];
}