Skip to content

Instantly share code, notes, and snippets.

@dardo82
Last active November 28, 2022 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dardo82/c2660f2db16e2fc8f5d6159c735e98e0 to your computer and use it in GitHub Desktop.
Save dardo82/c2660f2db16e2fc8f5d6159c735e98e0 to your computer and use it in GitHub Desktop.
Play last YouTube history video in MPV.
#!/bin/zsh
# Play the last video watched on YouTube in MPV with subtitles.
L="${2-${${LANG%.*}%_*}}"; SIZE="${3-48}"; EXT="${4-vtt}"; FMT="${5-135+140}" # Set variables.
ID=$(yt-dlp -v --get-id --playlist-items ${1-1} \
--cookies-from-browser chrome+gnomekeyring :ythistory) # Set the video's ID.
SUB=$(yt-dlp youtu.be/$ID --write-subs --sub-format vtt --sub-langs $L \
--print '%(requested_subtitles)j' | jq -M -r '.[]|.url') # Set the subtitles' URL.
mpv --ytdl-format="$FMT" --sub-file="$SUB" --sub-font-size="$SIZE" "ytdl://$ID" # Play the video.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment