From c78a2a110329d28ae457d1a17f96e996f9f8c3f4 Mon Sep 17 00:00:00 2001 From: "s.mehrbrodt@gmail.com" Date: Thu, 26 Sep 2013 18:18:04 +0200 Subject: [PATCH] Open Songbeamer Files in binary mode to detect the encoding --- openlp/plugins/songs/lib/songbeamerimport.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index ab570ba8b..b085b9463 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -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: