Merge branch 'main' of ssh://git.laserlesbian.systems:1337/emily/zsh-functions

main
Emily Frost 3 years ago
commit f7ee338f5a

@ -13,9 +13,11 @@ else
fi
function _start_new_ssh_agent () {
ssh_agent_file=$1
killall ssh-agent
# start a new ssh-agent and write its output to the env file.
ssh-agent | grep -v echo >&"$ssh_agent_env_file"
ssh-agent | grep -v echo >& "$ssh_agent_file"
source "$ssh_agent_file"
echo "New ssh-agent started."
ssh-add
}
@ -27,9 +29,9 @@ if [[ -e "$ssh_agent_env_file" ]]; then
echo "Existing ssh-agent environment configured with pid ${SSH_AGENT_PID}."
else
echo "Existing ssh-agent appears to be dead."
_start_new_ssh_agent
_start_new_ssh_agent "$ssh_agent_env_file"
fi
else
echo "No existing ssh-agent found."
_start_new_ssh_agent
_start_new_ssh_agent "$ssh_agent_env_file"
fi

@ -6,6 +6,11 @@ DEFAULT_LANGUAGE_CODE="eng"
# TODO: This needs to be used in the glob, but I don't know how.
VIDEO_EXTENSIONS="mkv,mp4,avi"
typeset -A LANGUAGE_NAMES
LANGUAGE_NAMES=( \
'english' 'en' \
)
_mkvmerge_add_subtitles_mkvmerge () {
original_file="$1"
results_directory="$2"
@ -26,21 +31,61 @@ _mkvmerge_add_subtitles_mkvmerge () {
# TODO: Support the other patterns listed in the above comment.
video_basename="$1"
# Include subtitles without language codes, assuming $DEFAULT_LANGUAGE_CODE is correct.
# For example: [basename].srt
uncoded_subtitle_name="${original_file:r}.srt"
if [[ -f "$uncoded_subtitle_name" ]]; then
subtitle_options_array+=("--language" "0:${DEFAULT_LANGUAGE_CODE}" "$uncoded_subtitle_name")
echo "Found uncoded subtitle file ${uncoded_subtitle_name}, assuming \
${DEFAULT_LANGUAGE_CODE}."
fi
# Include subtitles with language codes in their filenames.
# For example [basename].[language code].srt
coded_subtitle_files=(${original_file:r}.*.srt(N))
if [[ ! -z $coded_subtitle_files ]]; then
for fname in "$coded_subtitle_files"; do
for fname in $coded_subtitle_files; do
language_code="${${fname:r}:e}"
subtitle_options_array+=("--language" "0:${language_code}" "$fname")
echo "Found coded subtitle file ${fname} for language ${language_code}."
done
fi
# Include subtitles without language codes, assuming $DEFAULT_LANGUAGE_CODE is correct.
# For example: [basename].srt
uncoded_subtitle_name="${original_file:r}.srt"
if [[ -f "$uncoded_subtitle_name" ]]; then
subtitle_options_array+=("--language" "0:${DEFAULT_LANGUAGE_CODE}" "$uncoded_subtitle_name")
# Include subtitles in the Subs directory
named_subtitle_files=(${original_file:h}/Subs/*.srt)
if [[ ! -z $named_subtitle_files ]]; then
existing_language_codes=()
for fname in $named_subtitle_files; do
file_basename=${fname:t}
# determine language code from filenames like 2_English.srt
# This character soup does three things
# * #[0-9]*_ removes the preceding track number, such as 2_ or 13_
# * :r removes the file extension
# * :l makes it all lowercase
language_name="${${file_basename#[0-9]*_}:r:l}"
echo "Found subtitle file ${fname}."
if [[ $LANGUAGE_NAMES[$language_name] ]]; then
language_code=$LANGUAGE_NAMES[$language_name]
echo "Checking if subtitle file ${fname} is usable."
# TODO: This is absolutely an ugly way to do this, but this is what works.
if $(echo ${existing_language_codes} > grep ${language_code}); then
subtitle_options_array+=("--language" "0:${language_code}" "$fname")
existing_language_codes+=$language_code
echo "Found ${language_code} subtitles at ${fname}."
else
echo "Duplicate subtitle files for ${language_code}."
exit 1
fi
else
echo "Unknown language name ${language_name}."
exit 1
fi
done
fi
# Finally, actually mux all the subtitles in if there are any.

Loading…
Cancel
Save