forked from openlp/openlp
- recognize openlp.org 1.x import char encoding by title, lyrics and copyright
- prefere utf-8 encoding for CCLI imports
This commit is contained in:
parent
ed82a6c17e
commit
47e7937baf
7
openlp/plugins/songs/lib/cclifileimport.py
Executable file → Normal file
7
openlp/plugins/songs/lib/cclifileimport.py
Executable file → Normal file
@ -76,7 +76,12 @@ class CCLIFileImport(SongImport):
|
||||
lines = []
|
||||
if os.path.isfile(filename):
|
||||
detect_file = open(filename, u'r')
|
||||
details = chardet.detect(detect_file.read(2048))
|
||||
detect_content = detect_file.read(2048)
|
||||
try:
|
||||
unicode(detect_content, u'utf-8')
|
||||
details = {'confidence': 1, 'encoding': 'utf-8'}
|
||||
except UnicodeDecodeError:
|
||||
details = chardet.detect(detect_content)
|
||||
detect_file.close()
|
||||
infile = codecs.open(filename, u'r', details['encoding'])
|
||||
lines = infile.readlines()
|
||||
|
@ -118,7 +118,7 @@ class OpenLP1SongImport(SongImport):
|
||||
success = False
|
||||
break
|
||||
song_id = song[0]
|
||||
guess = chardet.detect(song[2])
|
||||
guess = chardet.detect(song[1] + song[2] + song[3])
|
||||
title = self.decode_string(song[1], guess)
|
||||
lyrics = self.decode_string(song[2], guess).replace(u'\r', u'')
|
||||
copyright = self.decode_string(song[3], guess)
|
||||
|
Loading…
Reference in New Issue
Block a user