forked from openlp/openlp
added option to select windows encoding
This commit is contained in:
parent
c3b703ec8a
commit
711fa05dc1
@ -37,7 +37,7 @@ import re
|
||||
import struct
|
||||
|
||||
from openlp.core.ui.wizard import WizardStrings
|
||||
from openlp.plugins.songs.lib import VerseType
|
||||
from openlp.plugins.songs.lib import VerseType, retrieve_windows_encoding
|
||||
from openlp.plugins.songs.lib.songimport import SongImport
|
||||
|
||||
TITLE = 1
|
||||
@ -143,44 +143,44 @@ class SongShowPlusImport(SongImport):
|
||||
log.debug(length_descriptor_size)
|
||||
data = song_data.read(length_descriptor)
|
||||
if block_key == TITLE:
|
||||
self.title = unicode(data, chardet.detect(data)['encoding'])
|
||||
self.title = self.decode(data)
|
||||
elif block_key == AUTHOR:
|
||||
authors = data.split(" / ")
|
||||
for author in authors:
|
||||
if author.find(",") !=-1:
|
||||
authorParts = author.split(", ")
|
||||
author = authorParts[1] + " " + authorParts[0]
|
||||
self.parseAuthor(unicode(author, chardet.detect(data)['encoding']))
|
||||
self.parseAuthor(self.decode(author))
|
||||
elif block_key == COPYRIGHT:
|
||||
self.addCopyright(unicode(data, chardet.detect(data)['encoding']))
|
||||
self.addCopyright(self.decode(data))
|
||||
elif block_key == CCLI_NO:
|
||||
self.ccliNumber = int(data)
|
||||
elif block_key == VERSE:
|
||||
self.addVerse(unicode(data, chardet.detect(data)['encoding']),
|
||||
self.addVerse(self.decode(data),
|
||||
"%s%s" % (VerseType.Tags[VerseType.Verse], verse_no))
|
||||
elif block_key == CHORUS:
|
||||
self.addVerse(unicode(data, chardet.detect(data)['encoding']),
|
||||
self.addVerse(self.decode(data),
|
||||
"%s%s" % (VerseType.Tags[VerseType.Chorus], verse_no))
|
||||
elif block_key == BRIDGE:
|
||||
self.addVerse(unicode(data, chardet.detect(data)['encoding']),
|
||||
self.addVerse(self.decode(data),
|
||||
"%s%s" % (VerseType.Tags[VerseType.Bridge], verse_no))
|
||||
elif block_key == TOPIC:
|
||||
self.topics.append(unicode(data, chardet.detect(data)['encoding']))
|
||||
self.topics.append(self.decode(data))
|
||||
elif block_key == COMMENTS:
|
||||
self.comments = unicode(data, chardet.detect(data)['encoding'])
|
||||
self.comments = self.decode(data)
|
||||
elif block_key == VERSE_ORDER:
|
||||
verse_tag = self.toOpenLPVerseTag(data, True)
|
||||
if verse_tag:
|
||||
if not isinstance(verse_tag, unicode):
|
||||
verse_tag = unicode(verse_tag, chardet.detect(data)['encoding'])
|
||||
verse_tag = self.decode(verse_tag)
|
||||
self.sspVerseOrderList.append(verse_tag)
|
||||
elif block_key == SONG_BOOK:
|
||||
self.songBookName = unicode(data, chardet.detect(data)['encoding'])
|
||||
self.songBookName = self.decode(data)
|
||||
elif block_key == SONG_NUMBER:
|
||||
self.songNumber = ord(data)
|
||||
elif block_key == CUSTOM_VERSE:
|
||||
verse_tag = self.toOpenLPVerseTag(verse_name)
|
||||
self.addVerse(unicode(data, chardet.detect(data)['encoding']), verse_tag)
|
||||
self.addVerse(self.decode(data), verse_tag)
|
||||
else:
|
||||
log.debug("Unrecognised blockKey: %s, data: %s"
|
||||
% (block_key, data))
|
||||
@ -222,3 +222,13 @@ class SongShowPlusImport(SongImport):
|
||||
verse_tag = VerseType.Tags[VerseType.Other]
|
||||
verse_number = self.otherList[verse_name]
|
||||
return verse_tag + verse_number
|
||||
|
||||
def decode(self, data):
|
||||
try:
|
||||
return unicode(data, chardet.detect(data)['encoding'])
|
||||
except:
|
||||
while True:
|
||||
try:
|
||||
return unicode(data, self.encoding)
|
||||
except:
|
||||
self.encoding = retrieve_windows_encoding()
|
Loading…
Reference in New Issue
Block a user