From 34dbdaf0d0ab0c3221cc8c2e6bb7e76f04ae8adc Mon Sep 17 00:00:00 2001 From: Autumn Date: Fri, 8 May 2026 08:19:50 +0100 Subject: [conf/nushell] added youtube helper script --- src/nushell/scripts/youtube.nu | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/nushell/scripts/youtube.nu (limited to 'src/nushell/scripts') diff --git a/src/nushell/scripts/youtube.nu b/src/nushell/scripts/youtube.nu new file mode 100644 index 0000000..5423b9d --- /dev/null +++ b/src/nushell/scripts/youtube.nu @@ -0,0 +1,63 @@ +#!/usr/bin/env nu + +# +# ~~~ nushell youtube downloader +# + +# +# ~~~ help command + +# A YouTube helper program +export def yt []: nothing -> nothing { + help yt +} + +# +# ~~~ download a video + +# Download a YouTube video with x265 +export def "yt video" [ + video: string, # A YouTube video URL + title: string # The filename of the video +]: nothing -> nothing { + + # download video + yt-dlp --config-location $"($env.HOME)/.config/yt-dlp/video.conf" -o $"($title)-original" $video + + # convert video + ffmpeg -i $"($title)-original.mp4" -vcodec libx265 -crf 28 $"($title).mp4" + + # remove original + rm $"($title)-original.mp4" +} + +# +# ~~~ download thumbnail + +# Download a YouTube video's thumbnail +export def "yt thumbnail" [ + video: string # A YouTube video ID +]: nothing -> nothing { + + let URL = $"https://i.ytumg.com/vi/($video)/maxresdefault." + + # try .webp + try { + + http get $"($URL).webp" | save $"($video).webp" + + } catch { + + # try .png + try { + + http get $"($URL).png" | save $"($video).png" + + # try .jpg + } catch { + + http get $"($URL).jpg" | save $"($video).jpg" + + } + } +} -- cgit v1.3