summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xyt-dlp-best52
1 files changed, 31 insertions, 21 deletions
diff --git a/yt-dlp-best b/yt-dlp-best
index c6ab860..9610e7a 100755
--- a/yt-dlp-best
+++ b/yt-dlp-best
@@ -3,32 +3,44 @@
USAGE="./yt-dlp-best [options] \"URL\"
Fetches the best format of a YT video (ideally in mp4)
Options:
- -y skips the format check normally requiring user action to continue with download"
+ -y skips the format check normally requiring user action to continue with download
+ -s fetches subtitles"
+
+
+
+SKIP_CHECK=1
+SUBS=1
+
+while getopts "hys" opt; do
+ case "$opt" in
+ h) echo "$USAGE"
+ exit 1
+ ;;
+ y) SKIP_CHECK=0
+ ;;
+ s) SUBS=0
+ ;;
+ esac
+done
-SKIP_CHECK=0
-if [ $# -eq 1 ]; then
- URL=$1
-else
- if [ $# -eq 2 ]; then
- if [ "$1" == "-y" ]; then
- SKIP_CHECK=1
- URL=$2
- fi
- else
- echo "$USAGE"
- exit 1
- fi
-fi
+
+URL=${@:$OPTIND:1}
DESIRED_FMT="mp4"
+DESIRED_SUBFMT="srt"
+DESIRED_SUBLANG="en"
FMT_LINE=$(yt-dlp -F "${URL}" | grep "${DESIRED_FMT}" | tail -n 1)
FMT=$(echo ${FMT_LINE} | cut -d" " -f1)
-
+if [ $SUBS -eq 0 ]; then
+ substr="--write-subs --sub-langs=${DESIRED_SUBLANG} --sub-format=${DESIRED_SUBFMT}"
+else
+ substr=""
+fi
echo "${FMT_LINE}"
-echo "yt-dlp -f ${FMT}+m4a \"${URL}\""
+echo "yt-dlp ${substr} -f ${FMT}+m4a \"${URL}\""
-if [ $SKIP_CHECK -eq 0 ]; then
+if [ $SKIP_CHECK -eq 1 ]; then
read -p "proceed (Y/N): " answer
else
# basically force a "yes" answer
@@ -36,11 +48,9 @@ else
fi
if [[ "$answer" =~ ^[yY][eE]{0,1}[sS]{0,1}$ ]]; then
- yt-dlp -f ${FMT}+m4a "${URL}"
+ yt-dlp ${substr} -f ${FMT}+m4a "${URL}"
exit 0
else
echo "Okay, cancelling"
exit 1
fi
-
-