Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2017 10:48
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 anonymous/330359cc0fbd41a2560abf968fc30664 to your computer and use it in GitHub Desktop.
Save anonymous/330359cc0fbd41a2560abf968fc30664 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# Try to load all available subtitles for mpv not regarding their nesting
# level. Based on https://www.linux.org.ru/news/multimedia/9704338?cid=9715830
# Also autodetect BD/DVD ISO files.
is_bluray() {
# Hacky but I don't know better way.
bd_info $1 >&- 2>&-
}
set -e
setopt EXTENDED_GLOB
setopt NULL_GLOB
local -a args
local -a mediadirs
for arg in $@; do
if [[ ${arg[0]} != '-' && -f $arg ]]; then
mediadirs+=( ${arg:A:h} )
if [[ ${arg[-4,-1]:l} == '.iso' ]]; then
is_bluray $arg && \
args+=( bd:// --bluray-device ) || \
args+=( dvdread:// --dvd-device )
fi
fi
args+=( $arg )
done
# Autoconvert list to string delemited by colons.
local -aT SUBPATHS subpaths
subpaths=( ${^mediadirs}/(#i)*(eng|rus|sub|ass|srt|суб)*{,/**/*}(/) )
if (( ${#subpaths} )); then
args+=( --sub-paths $SUBPATHS )
fi
#echo "Playing with arguments: '$args'" >&2
exec mpv $args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment