Created
August 3, 2016 14:47
-
-
Save hisener/14f55cdc987d4dcdb878bfcc5b3d3030 to your computer and use it in GitHub Desktop.
Convert subtitles' encoding to UTF-8
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
#!/bin/bash | |
OIFS="$IFS" | |
IFS=$'\n' | |
find ./ -name "*.srt" -type f | | |
while read file | |
do | |
if ! [[ `file -bi "$file"` =~ utf-8$ ]] | |
then | |
charset="$(file -bi "$file")" | |
charset="$(sed -r 's/.*charset=([^"]*).*/\1/' <<< $charset)" | |
charset="$(sed -r 's/iso-8859-1/iso-8859-9/' <<< $charset)" | |
charset="$(sed -r 's/unknown.*/iso-8859-9/' <<< $charset)" | |
echo "$file" | |
mv $file $file.icv | |
iconv -f $charset -t UTF-8 $file.icv > $file | |
rm -f $file.icv | |
fi | |
done | |
IFS="$OIFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment