#1 feat: new dmenu script for watching YouTube or Twitch using mpv

Mở
ndpm13 muốn nhập 1 commit từ ndpm13/master vào konpaku/master
2 tập tin đã thay đổi với 49 bổ sung1 xóa
  1. 5 1
      README.md
  2. 44 0
      scripts/mpv_stream.sh

+ 5 - 1
README.md

@@ -5,4 +5,8 @@
 ## [animecopy](https://git.ch-naseem.com/konpaku/Scripts_Collection/raw/master/scripts/animecopy.sh)
 ![](https://git.ch-naseem.com/konpaku/Scripts_Collection/raw/master/asset/animecopybutrenamed.avif)
     a script made for copying all .mp4 and .mkv subfiles on a domain. made for syncplay watch parties.
-    considering adding a recursive feature
+    considering adding a recursive feature
+
+## mpv_stream
+
+a quality of life script for streaming media with mpv. For YouTube videos just copy the URL to the video you wanna watch or download, as for Twitch you might wanna edit the script and add your favorite streamers (must be a correct username to work!).

+ 44 - 0
scripts/mpv_stream.sh

@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# to use a SOCKS proxy run this in the
+# background before excuting the script
+# ssh -D 1080 -C -N user@ip
+
+SOCKS_PROXY_URL="socks5://localhost:1080"
+TWITCH_CHANNELS="christitustech\ntheprimeagen"
+VIDEO_DIR="$HOME/Videos/youtube/"
+
+media=$(echo -e "Video\nStream" | dmenu -p "Media Type: ")
+quality=$(echo -e "480p\n720p\n1080p" | dmenu -p "Quality: ")
+socks=$(echo -e "no\nyes" | dmenu -p "use SOCKS? ")
+
+if [[ $socks == "yes" ]]; then
+  MPV_COMMAND="alacritty -e mpv --http-proxy="$SOCKS_PROXY_URL""
+else
+  MPV_COMMAND="alacritty -e mpv"
+fi
+
+case "$media" in
+  "Video")
+    action=$(echo -e "Stream\nDownload" | dmenu -p "Media Type: ")
+    case "$action" in
+      "Stream")
+        $MPV_COMMAND --save-position-on-quit "--ytdl-format=bestvideo[height<=$quality]+bestaudio" "$(xclip -o -selection clipboard)"
+        ;;
+      "Download")
+        mkdir -p $VIDEO_DIR
+        alacritty -e yt-dlp  -f "[height<=$quality]+bestaudio" "$(xclip -o -selection clipboard)" -o "$VIDEO_DIR/%(uploader)s - %(title)s.%(ext)s"
+        ;;
+    esac
+    ;;
+  "Stream")
+    channel=$(echo -e "$TWITCH_CHANNELS" | dmenu -p "Channel: ")
+    $MPV_COMMAND --no-resume-playback "--ytdl-format=bestvideo[height<=$quality]+bestaudio" "https://www.twitch.tv/$channel"
+    ;;
+esac
+
+# TODO: make this work
+# input=$(echo -n | dmenu -p "YouTube Search: ")
+# [[ -n $input ]] && st ytfzf -ft --preview-side=right "$input"