Open Songbeamer Files in binary mode to detect the encoding

This commit is contained in:
s.mehrbrodt@gmail.com 2013-09-26 18:18:04 +02:00
parent 9dbb2e12b0
commit c78a2a1103
1 changed files with 7 additions and 2 deletions

View File

@ -29,9 +29,10 @@
"""
The :mod:`songbeamerimport` module provides the functionality for importing SongBeamer songs into the OpenLP database.
"""
import chardet
import codecs
import logging
import os
import io
import re
from openlp.plugins.songs.lib import VerseType
@ -114,7 +115,11 @@ class SongBeamerImport(SongImport):
read_verses = False
file_name = os.path.split(_file)[1]
if os.path.isfile(_file):
infile = io.open(_file, 'r', encoding="Latin-1")
# First open in binary mode to detect the encoding
detect_file = open(_file, 'rb')
details = chardet.detect(detect_file.read())
detect_file.close()
infile = codecs.open(_file, 'r', details['encoding'])
song_data = infile.readlines()
infile.close()
else: