diff options
Diffstat (limited to 'home-manager/sh/yt.nix')
-rw-r--r-- | home-manager/sh/yt.nix | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/home-manager/sh/yt.nix b/home-manager/sh/yt.nix new file mode 100644 index 0000000..836798a --- /dev/null +++ b/home-manager/sh/yt.nix @@ -0,0 +1,67 @@ +{ pkgs }: + +let + + yt = pkgs.writeShellScriptBin "yt" '' + jq="${pkgs.jq}/bin/jq" + + VIDEO_PATH="$HOME/Videos/Random" + + mkdir -p "$VIDEO_PATH" + + json="$(${pkgs.ytfzf}/bin/ytfzf -t --type=video --thumbnail-quality=medium -I vj)" + + title="$(echo "$json" | jq .[0].title -r)" + channel="$(echo "$json" | jq .[0].channel -r)" + url="$(echo "$json" | jq .[0].url -r)" + + cd "$VIDEO_PATH" || exit 1 + + ${pkgs.yt-dlp}/bin/yt-dlp --write-subs --sub-langs "en.*" --embed-chapters --embed-subs -f "bv*[height<=480]+ba/b[height<=480] / wv*+ba/w" -o "$channel - $title.%(ext)s" "$url" + + ${pkgs.mpv}/bin/mpv "$channel - $title."* + ''; + + yt-hugger = pkgs.writeShellScriptBin "yt-hugger" '' + # + # This script download all videos from youtube channels specified in .channels + # file into path specified in VIDEOS. + # + # Channel File Format: + # <name> <url> + # <name> <url> + # # Comment + # <name> <url> + # ... + # + + VIDEOS="$HOME/Videos/Channel" + + mkdir -p "$VIDEOS" + touch "$VIDEOS/.channels" + + channels="$(cat "$VIDEOS/.channels" | sed "/^#/d")" + + [ -z "$channels" ] && echo "Channels file is empty" && exit 1 + + for entry in "$channels"; do + name="''${entry% *}" + url="''${entry##* }" + + ${pkgs.yt-dlp}/bin/yt-dlp \ + -f 'bv*[height>=720]+ba' \ + --sub-langs "en.*" --embed-subs \ + --embed-chapters --embed-thumbnail --embed-metadata \ + --download-archive "$name/.archive" \ + -o "$name/%(channel)s - %(title)s.%(ext)s" \ + "$url" + done + ''; + +in pkgs.symlinkJoin { + name = "yt"; + paths = [ + yt + yt-hugger + ]; +} |