~phill-ridout/openlp/path_edit

« back to all changes in this revision

Viewing changes to openlp/plugins/songs/lib/importers/songbeamer.py

  • Committer: Tim Bentley
  • Author(s): tomasgroth at yahoo
  • Date: 2017-01-20 21:42:01 UTC
  • mfrom: (2714.3.4 sb-vps-import-fixes)
  • Revision ID: tim.bentley@gmail.com-20170120214201-2bvkpns82mi5fdwx
Clean search lyrics for formatting tags. Fixes bug #1655988.
Fix an issue with easyslide import not handling verse order correctly. Fixes bug #1655985.
Improve the songbeamer encoding detection. Fixes bug #1530597.
Handle a few videopsalm quirks. Fixes bug #1652851.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import os
29
29
import re
30
30
 
 
31
from openlp.core.common import get_file_encoding
31
32
from openlp.plugins.songs.lib import VerseType
32
33
from openlp.plugins.songs.lib.importers.songimport import SongImport
33
34
 
113
114
            read_verses = False
114
115
            file_name = os.path.split(import_file)[1]
115
116
            if os.path.isfile(import_file):
116
 
                # First open in binary mode to detect the encoding
117
 
                detect_file = open(import_file, 'rb')
118
 
                details = chardet.detect(detect_file.read())
119
 
                detect_file.close()
120
 
                infile = codecs.open(import_file, 'r', details['encoding'])
 
117
                # Detect the encoding
 
118
                self.input_file_encoding = get_file_encoding(import_file)['encoding']
 
119
                # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode.
 
120
                # So if it doesn't start with 'u' we default to cp1252. See:
 
121
                # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2
 
122
                if self.input_file_encoding.lower().startswith('u'):
 
123
                    self.input_file_encoding = 'cp1252'
 
124
                infile = open(import_file, 'rt', encoding=self.input_file_encoding)
121
125
                song_data = infile.readlines()
122
 
                infile.close()
123
126
            else:
124
127
                continue
125
128
            self.title = file_name.split('.sng')[0]