Skip to content

Instantly share code, notes, and snippets.

@gbonk
Created November 22, 2023 02:52
Show Gist options
  • Save gbonk/600f3a8b1d384007d66700a12a467d79 to your computer and use it in GitHub Desktop.
Save gbonk/600f3a8b1d384007d66700a12a467d79 to your computer and use it in GitHub Desktop.
Find media files that already have subs and delete any sub files.
#!/usr/bin/env bash
OIFS="$IFS"
IFS=$'\n'
for mfile in $(find /mnt/movies -type f -name '*.mkv' -o -name '*.mp4'); do
echo "Checking: " $(basename "$mfile" )
has_subs="$( timeout 60 mediainfo '--Output=Text;%Language/String%, ' $mfile | grep -i 'english,' )"
exit_code="$?"
if [[ $exit_code == 124 ]]; then
echo "TIMEOUT"
has_subs=""
fi
if [[ -n $has_subs ]]; then
echo "Subs!"
dfile="$(dirname $mfile)"
ls -lR "$dfile/"*.srt
rm -f "$dfile/"*.srt
else
echo "NO Subs"
fi
done
IFS="$OIFS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment