#!/bin/sh # references: # https://www.rockyourcode.com/til-how-to-watch-youtube-videos-with-mpv-and-keyboard-shortcuts/ # https://github.com/mpv-player/mpv/issues/7792 fps=30 height=$SCRHEIGHT url="$(xsel -ob)" flag=s notify () { notify-send 'mpvsel failed' } # can improve to make some options mutually exclusive, see curlncm, maybe not # option f and h may do nothing if redownload? since same filename exist. yt-dlp won't download same file even without --auto-file-renameing=false. how improve? pass argument to aria2c? while getopts Aabd:f:h:su: opt; do case $opt in # s: streaming, a: aria2c then mpv, A: aria2c A|a|s) flag=$opt;; b) format='bestvideo+bestaudio/best';; d) download_dir="$OPTARG";; f) fps="$OPTARG";; h) height="$OPTARG";; u) url="$OPTARG";; \?) exit 1;; esac done if [ -z "$format" ]; then vformat="[height<=?$height][fps<=?$fps][vcodec!^=?vp9][vcodec!^=?av01]" # usually get .mp4 video + .webm audio on youtube, yt-dlp needs to merge them to .mkv # it used to cause problem, but I forget format="bestvideo$vformat+bestaudio/best$vformat" fi case $flag in # here if use --write-sub, mpv doesn't recognize subtitles? # --embed-subs is a little bit better, but still worse then direct streaming A) tsp yt-dlp -f "$format" --embed-subs -P "${download_dir:-"$XDG_DOWNLOAD_DIR/mpvy/"}" --sponsorblock-remove all "$url";; a) yt-dlp -f "$format" --embed-subs -P "${download_dir:-/tmp/mpvy/}" --sponsorblock-remove all "$url" --exec 'mpv --fs --speed=2' || notify ;; s) mpv --ytdl-format="$format" --ytdl-raw-options='write-sub=' --fs --speed=2 "$url" || notify;; esac