Skip to content

Instantly share code, notes, and snippets.

@Barlog951
Last active September 22, 2016 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Barlog951/69aceea68c38230c57d6658884e2349c to your computer and use it in GitHub Desktop.
Save Barlog951/69aceea68c38230c57d6658884e2349c to your computer and use it in GitHub Desktop.
Automated subtitles convert to UTF-8
#!/bin/bash
LANGUAGE=czech
TO=utf8
CONVERT="enca -L $LANGUAGE -x $TO"
# Find and onvert
find ./ -type f -name "*.srt" | while read fn; do
IS_TARGET=`enca "${fn}" | egrep -ow -m 1 'UTF-8|Unrecognized|KOI8-CS2|7bit ASCII|UCS-2|Macintosh Central European'`
if [ "$IS_TARGET" != "UTF-8" ] &&
[ "$IS_TARGET" != "UCS-2" ] &&
[ "$IS_TARGET" != "Macintosh Central European" ] &&
[ "$IS_TARGET" != "Unrecognized" ] &&
[ "$IS_TARGET" != "7bit ASCII" ] &&
[ "$IS_TARGET" != "KOI8-CS2" ]; then
echo "${fn} ---- Will be converted!"
# optional backup of original srt
# cp "${fn}" "${fn}.bak"
$CONVERT "${fn}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment