diff options
| author | Autumn <git@autumnfo.rest> | 2026-05-08 08:19:50 +0100 |
|---|---|---|
| committer | Autumn <git@autumnfo.rest> | 2026-05-08 08:19:50 +0100 |
| commit | 34dbdaf0d0ab0c3221cc8c2e6bb7e76f04ae8adc (patch) | |
| tree | 328d5e3d6190d528ee7b5ce9a08a2328d48ad8e9 /src/nushell | |
| parent | c0d3ad9427409d74238e450db9fe7f7e6e08aa99 (diff) | |
[conf/nushell] added youtube helper script
Diffstat (limited to 'src/nushell')
| -rw-r--r-- | src/nushell/020_config.nu | 6 | ||||
| -rw-r--r-- | src/nushell/scripts/youtube.nu | 63 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/nushell/020_config.nu b/src/nushell/020_config.nu index 10fddd6..7ac7b2e 100644 --- a/src/nushell/020_config.nu +++ b/src/nushell/020_config.nu @@ -7,6 +7,12 @@ use environment.nu # +# ~~~ custom commands + +# youtube +use scripts/youtube.nu * + +# # ~~~ theming # hide banner 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" + + } + } +} |
