From 97da1a281a44d7784dc49a08d794a82d24d289c6 Mon Sep 17 00:00:00 2001 From: xyz Date: Mon, 20 Sep 2021 14:20:33 -0700 Subject: mpvsel rename to mpvy, mpvy now can download only --- .config/sxhkd/sxhkdrc | 7 +++++-- .local/bin/mpvsel | 37 ------------------------------------- .local/bin/mpvy | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 39 deletions(-) delete mode 100755 .local/bin/mpvsel create mode 100755 .local/bin/mpvy diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 5774b55e..82045dad 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -13,10 +13,13 @@ alt + XF86AudioMute kill -RTMIN "$(cat ~/.cache/pidofbar)" alt + y - mpvsel -s + mpvy -s alt + Y - mpvsel -a + mpvy -a + +alt + ctrl + y + mpvy -A alt + w firefox diff --git a/.local/bin/mpvsel b/.local/bin/mpvsel deleted file mode 100755 index e1047a23..00000000 --- a/.local/bin/mpvsel +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 -download_dir='/tmp/mpvsel/' -url="$(xsel -ob)" -flag=s - -# can improve to make s and d mutually exclusive, see curlncm, maybe not, not necessary -# option f and h may do nothing if redownload? since same filename exist, haven't tested. yt-dlp won't download same file even without --auto-file-renameing=false. how improve? -while getopts ad:f:h:su: opt; do - case $opt in - # streaming, or aria2c - a|s) flag=$opt;; - d) download_dir="$OPTARG"; flag=a;; - f) fps="$OPTARG";; - h) height="$OPTARG";; - u) url="$OPTARG";; - \?) exit 1;; - esac -done -mkdir -p "$download_dir" - -vformat="[height<=?$height][fps<=?$fps][vcodec!^=?vp9][vcodec!^=?av01]" -# usually with my vformat, video is .mp4, bestaudio is .webm, seems not a good idea to combine those, create problems when use yt-dlp to merge them, not sure about streaming -#format="bestvideo$vformat+bestaudio/best$vformat" -format="best$vformat" - -case $flag in - # here if use --write-sub, mpv doesn't recognize subtitles? - # --embed-subs is a little bit better - a) yt-dlp -f "$format" --embed-subs -P "$download_dir" --sponsorblock-remove all "$url" --exec "mpv --fs --speed=2" || notify-send "mpvsel failed";; - s) mpv --ytdl-format="$format" --ytdl-raw-options='write-sub=' --fs --speed=2 "$url" || notify-send "mpvsel failed";; -esac diff --git a/.local/bin/mpvy b/.local/bin/mpvy new file mode 100755 index 00000000..31433522 --- /dev/null +++ b/.local/bin/mpvy @@ -0,0 +1,46 @@ +#!/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 + +notify () +{ + notify-send "mpvsel failed" +} + +fps=30 +height=$SCRHEIGHT +url="$(xsel -ob)" +flag=s + +# can improve to make s and d mutually exclusive, see curlncm, maybe not, not necessary +# option f and h may do nothing if redownload? since same filename exist, haven't tested. yt-dlp won't download same file even without --auto-file-renameing=false. how improve? +# how to simplify notify-send +while getopts Aad:f:h:su: opt; do + case $opt in + # s: streaming, a: aria2c then mpv, A: aria2c + A|a|s) flag=$opt;; + d) download_dir="$OPTARG";; + f) fps="$OPTARG";; + h) height="$OPTARG";; + u) url="$OPTARG";; + \?) exit 1;; + esac +done +case $flag in + A) [ -z "$download_dir" ] && download_dir="$XDG_DOWNLOAD_DIR/mpvsel/";; + a) [ -z "$download_dir" ] && download_dir="/tmp/mpvsel/";; +esac +mkdir -p "$download_dir" +vformat="[height<=?$height][fps<=?$fps][vcodec!^=?vp9][vcodec!^=?av01]" +# usually with my vformat, video is .mp4, bestaudio is .webm, seems not a good idea to combine those, create problems when use yt-dlp to merge them, not sure about streaming +#format="bestvideo$vformat+bestaudio/best$vformat" +format="best$vformat" + +case $flag in + # here if use --write-sub, mpv doesn't recognize subtitles? + # --embed-subs is a little bit better + A) yt-dlp -f "$format" --embed-subs -P "$download_dir" --sponsorblock-remove all "$url" || notify;; + a) yt-dlp -f "$format" --embed-subs -P "$download_dir" --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 -- cgit v1.2.3-70-g09d2