- 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:
M2j 2010-11-01 21:48:30 +01:00
parent ed82a6c17e
commit 47e7937baf
2 changed files with 7 additions and 2 deletions

7
openlp/plugins/songs/lib/cclifileimport.py Executable file → Normal file
View 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()

View File

@ -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)