m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/yt-dl-choose
diff options
context:
space:
mode:
Diffstat (limited to 'yt-dl-choose')
-rwxr-xr-xyt-dl-choose36
1 files changed, 36 insertions, 0 deletions
diff --git a/yt-dl-choose b/yt-dl-choose
new file mode 100755
index 0000000..7d33588
--- /dev/null
+++ b/yt-dl-choose
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Wrapper for mpv playing an internet video with yt-dlp that lets you select the
+# video format to download. Useful when launching e.g. YouTube videos, which
+# often have a very high resolution default format that would buffer a lot.
+# USAGE: yt-dl-choose <url>
+# Opens a dmenu menu with available audio+video formats.
+# NOTE: only displays formats that have both audio and video, which have limited
+# quality. For highest resolution, we'd also need to provide options for
+# combined formats with separate audio and video streams.
+# NOTE: when given a video in a YouTube playlist, will only play that video.
+
+NO_PLAYLIST=1
+
+if [[ $# -ne 1 ]]; then
+ echo "USAGE: yt-dl-choose <url>"
+fi
+
+URL="$1"
+
+if [[ $NO_PLAYLIST ]]; then
+ URL=`echo "$URL" | sed -e 's/&list=.*&/\&/'`
+fi
+
+formats=`yt-dlp --list-formats $URL \
+ | grep -v "audio only" \
+ | grep -v "video only" \
+ | grep -v mhtml \
+ | sed '0,/---------/d' `
+format=`echo "$formats" | dmenu | cut -d' ' -f1`
+
+if [ -z "$format" ]; then
+ exit 0;
+fi
+
+mpv --ytdl-format=$format $1