Skip to content

Instantly share code, notes, and snippets.

@hisener
Created August 3, 2016 14:47
Show Gist options
  • Save hisener/14f55cdc987d4dcdb878bfcc5b3d3030 to your computer and use it in GitHub Desktop.
Save hisener/14f55cdc987d4dcdb878bfcc5b3d3030 to your computer and use it in GitHub Desktop.
Convert subtitles' encoding to UTF-8
#!/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