Skip to content

Instantly share code, notes, and snippets.

@shvchk
Last active June 27, 2023 15:42
Show Gist options
  • Select an option

  • Save shvchk/1f258aa660eb42d9297c85444674b777 to your computer and use it in GitHub Desktop.

Select an option

Save shvchk/1f258aa660eb42d9297c85444674b777 to your computer and use it in GitHub Desktop.
Quickly open YouTube video with mpv and youtubedr
#! /usr/bin/env bash
DEPS=( "youtubedr" "mpv" )
for i in "${DEPS[@]}"; do
command -v "$i" >/dev/null 2>&1 || {
echo >&2 "$i required, but it's not installed. Aborting.";
exit 1
}
done
_help() {
echo "Usage: $(basename -- "$0") url [video filter] [audio filter]"
exit
}
[ $# -eq 0 ] && _help
case $1 in
-h|--help|help) _help ;;
esac
info="$(youtubedr info "$1")"
title="$(echo "$info" | grep '^Title:' | awk '{$1=""; print substr($0,2)}')"
video_tag="$(echo "$info" | grep "^|.*video.*${2:-}" | head -1 | awk '{print $2}')"
audio_tag="$(echo "$info" | grep "^|.*audio.*${3:-}" | head -1 | awk '{print $2}')"
#echo "Video tag: $video_tag"
#echo "Audio tag: $audio_tag"
mpv --title="$title" --audio-file="$(youtubedr url -q "$audio_tag" "$1")" "$(youtubedr url -q "$video_tag" "$1")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment