#!/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" } } }