diff options
author | Xiao Pan <xyz@flylightning.xyz> | 2024-08-22 16:12:11 -0700 |
---|---|---|
committer | Xiao Pan <xyz@flylightning.xyz> | 2024-08-22 16:12:22 -0700 |
commit | 0077740996c5fb8fa459f16ae16a9af388f8de84 (patch) | |
tree | 6928c8811670492e25548d2870a16ba2830e065d /sh | |
parent | 96fd0d52cf46afb5a481b7f775f5a269e51eb79c (diff) |
mpvy consider yt-dlp using cookies
Diffstat (limited to 'sh')
-rwxr-xr-x | sh/mpvy | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -3,17 +3,24 @@ # references: # https://www.rockyourcode.com/til-how-to-watch-youtube-videos-with-mpv-and-keyboard-shortcuts/ +flag=s +format= +cookie= +download_dir= fps=30 height=$SCR_HEIGHT url="$(xsel -ob)" -flag=s + +cookie_ytdl= +cookie_mpv= # 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 +while getopts Aabcd: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';; + c) cookie=1;; d) download_dir="$OPTARG";; f) fps="$OPTARG";; h) height="$OPTARG";; @@ -30,14 +37,19 @@ if [ -z "$format" ]; then format="bestvideo$vformat+bestaudio/best$vformat" fi +if [ "$cookie" ] || case "$url" in *bilibili.com/*);; *) false;; esac; then + cookie_ytdl="--cookies-from-browser $BROWSER" + cookie_mpv="cookies-from-browser=$BROWSER" +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 # --sponsorblock-remove will make audio/video goes out of sync, need --force-keyframes-at-cuts which need re-encode which is slow, more see comments at the bottom of https://github.com/yt-dlp/yt-dlp/issues/871 # another way is using mpv-sponsorblock-minimal-git for streaming and sponsorblock-mpv-local for local videos - A) yt-dlp -f "$format" --embed-subs -P "${download_dir:-"$XDG_DOWNLOAD_DIR/mpvy/"}" --sponsorblock-remove default --sponsorblock-mark default "$url";; - a) yt-dlp -f "$format" --embed-subs -P "${download_dir:-"$XDG_DOWNLOAD_DIR/mpvy/"}" --sponsorblock-remove default --sponsorblock-mark default "$url" --exec 'mpv --fs --speed=2';; - s) mpv --ytdl-format="$format" --ytdl-raw-options='write-sub=' --fs --speed=2 "$url";; + A) yt-dlp -f "$format" --embed-subs -P "${download_dir:-"$XDG_DOWNLOAD_DIR/mpvy/"}" --sponsorblock-remove default --sponsorblock-mark default $cookie_ytdl "$url";; + a) yt-dlp -f "$format" --embed-subs -P "${download_dir:-"$XDG_DOWNLOAD_DIR/mpvy/"}" --sponsorblock-remove default --sponsorblock-mark default $cookie_ytdl "$url" --exec 'mpv --fs --speed=2';; + s) mpv --ytdl-format="$format" --ytdl-raw-options="write-sub=,$cookie_mpv" --fs --speed=2 "$url";; esac # not sure if this is the best practice, but it seems working ;) status=$? |