forked from openlp/openlp
Fix bug #1194610 by detecting the encoding rather than assuming that it set (because its not) add fall back to the windows encoding dialog
bzr-revno: 2162 Fixes: https://launchpad.net/bugs/1194610
This commit is contained in:
commit
0b6d389f35
@ -30,13 +30,14 @@
|
|||||||
The :mod:`songshowplusimport` module provides the functionality for importing
|
The :mod:`songshowplusimport` module provides the functionality for importing
|
||||||
SongShow Plus songs into the OpenLP database.
|
SongShow Plus songs into the OpenLP database.
|
||||||
"""
|
"""
|
||||||
|
import chardet
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from openlp.core.ui.wizard import WizardStrings
|
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
|
from openlp.plugins.songs.lib.songimport import SongImport
|
||||||
|
|
||||||
TITLE = 1
|
TITLE = 1
|
||||||
@ -142,44 +143,44 @@ class SongShowPlusImport(SongImport):
|
|||||||
log.debug(length_descriptor_size)
|
log.debug(length_descriptor_size)
|
||||||
data = song_data.read(length_descriptor)
|
data = song_data.read(length_descriptor)
|
||||||
if block_key == TITLE:
|
if block_key == TITLE:
|
||||||
self.title = unicode(data, u'cp1252')
|
self.title = self.decode(data)
|
||||||
elif block_key == AUTHOR:
|
elif block_key == AUTHOR:
|
||||||
authors = data.split(" / ")
|
authors = data.split(" / ")
|
||||||
for author in authors:
|
for author in authors:
|
||||||
if author.find(",") !=-1:
|
if author.find(",") !=-1:
|
||||||
authorParts = author.split(", ")
|
authorParts = author.split(", ")
|
||||||
author = authorParts[1] + " " + authorParts[0]
|
author = authorParts[1] + " " + authorParts[0]
|
||||||
self.parseAuthor(unicode(author, u'cp1252'))
|
self.parseAuthor(self.decode(author))
|
||||||
elif block_key == COPYRIGHT:
|
elif block_key == COPYRIGHT:
|
||||||
self.addCopyright(unicode(data, u'cp1252'))
|
self.addCopyright(self.decode(data))
|
||||||
elif block_key == CCLI_NO:
|
elif block_key == CCLI_NO:
|
||||||
self.ccliNumber = int(data)
|
self.ccliNumber = int(data)
|
||||||
elif block_key == VERSE:
|
elif block_key == VERSE:
|
||||||
self.addVerse(unicode(data, u'cp1252'),
|
self.addVerse(self.decode(data),
|
||||||
"%s%s" % (VerseType.Tags[VerseType.Verse], verse_no))
|
"%s%s" % (VerseType.Tags[VerseType.Verse], verse_no))
|
||||||
elif block_key == CHORUS:
|
elif block_key == CHORUS:
|
||||||
self.addVerse(unicode(data, u'cp1252'),
|
self.addVerse(self.decode(data),
|
||||||
"%s%s" % (VerseType.Tags[VerseType.Chorus], verse_no))
|
"%s%s" % (VerseType.Tags[VerseType.Chorus], verse_no))
|
||||||
elif block_key == BRIDGE:
|
elif block_key == BRIDGE:
|
||||||
self.addVerse(unicode(data, u'cp1252'),
|
self.addVerse(self.decode(data),
|
||||||
"%s%s" % (VerseType.Tags[VerseType.Bridge], verse_no))
|
"%s%s" % (VerseType.Tags[VerseType.Bridge], verse_no))
|
||||||
elif block_key == TOPIC:
|
elif block_key == TOPIC:
|
||||||
self.topics.append(unicode(data, u'cp1252'))
|
self.topics.append(self.decode(data))
|
||||||
elif block_key == COMMENTS:
|
elif block_key == COMMENTS:
|
||||||
self.comments = unicode(data, u'cp1252')
|
self.comments = self.decode(data)
|
||||||
elif block_key == VERSE_ORDER:
|
elif block_key == VERSE_ORDER:
|
||||||
verse_tag = self.toOpenLPVerseTag(data, True)
|
verse_tag = self.toOpenLPVerseTag(data, True)
|
||||||
if verse_tag:
|
if verse_tag:
|
||||||
if not isinstance(verse_tag, unicode):
|
if not isinstance(verse_tag, unicode):
|
||||||
verse_tag = unicode(verse_tag, u'cp1252')
|
verse_tag = self.decode(verse_tag)
|
||||||
self.sspVerseOrderList.append(verse_tag)
|
self.sspVerseOrderList.append(verse_tag)
|
||||||
elif block_key == SONG_BOOK:
|
elif block_key == SONG_BOOK:
|
||||||
self.songBookName = unicode(data, u'cp1252')
|
self.songBookName = self.decode(data)
|
||||||
elif block_key == SONG_NUMBER:
|
elif block_key == SONG_NUMBER:
|
||||||
self.songNumber = ord(data)
|
self.songNumber = ord(data)
|
||||||
elif block_key == CUSTOM_VERSE:
|
elif block_key == CUSTOM_VERSE:
|
||||||
verse_tag = self.toOpenLPVerseTag(verse_name)
|
verse_tag = self.toOpenLPVerseTag(verse_name)
|
||||||
self.addVerse(unicode(data, u'cp1252'), verse_tag)
|
self.addVerse(self.decode(data), verse_tag)
|
||||||
else:
|
else:
|
||||||
log.debug("Unrecognised blockKey: %s, data: %s"
|
log.debug("Unrecognised blockKey: %s, data: %s"
|
||||||
% (block_key, data))
|
% (block_key, data))
|
||||||
@ -221,3 +222,9 @@ class SongShowPlusImport(SongImport):
|
|||||||
verse_tag = VerseType.Tags[VerseType.Other]
|
verse_tag = VerseType.Tags[VerseType.Other]
|
||||||
verse_number = self.otherList[verse_name]
|
verse_number = self.otherList[verse_name]
|
||||||
return verse_tag + verse_number
|
return verse_tag + verse_number
|
||||||
|
|
||||||
|
def decode(self, data):
|
||||||
|
try:
|
||||||
|
return unicode(data, chardet.detect(data)['encoding'])
|
||||||
|
except:
|
||||||
|
return unicode(data, retrieve_windows_encoding())
|
||||||
|
Loading…
Reference in New Issue
Block a user