Created
January 2, 2017 10:48
-
-
Save anonymous/330359cc0fbd41a2560abf968fc30664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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