aboutsummaryrefslogtreecommitdiff
path: root/src/nushell/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/nushell/scripts')
-rw-r--r--src/nushell/scripts/youtube.nu63
1 files changed, 63 insertions, 0 deletions
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"
+
+ }
+ }
+}