openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #21661
[Merge] lp:~phill-ridout/openlp/1194610-trunk into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/1194610-trunk into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/1194610-trunk/+merge/184447
Fixes bug 1194610 by detecting the encoding rather than assuming that it set (because its not) add fall back to the windows encoding dialog
Tests in separate merge request https://code.launchpad.net/~phill-ridout/openlp/song_helper
--
https://code.launchpad.net/~phill-ridout/openlp/1194610-trunk/+merge/184447
Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/1194610-trunk into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/songshowplusimport.py'
--- openlp/plugins/songs/lib/songshowplusimport.py 2013-08-31 18:17:38 +0000
+++ openlp/plugins/songs/lib/songshowplusimport.py 2013-09-07 17:40:00 +0000
@@ -30,6 +30,7 @@
The :mod:`songshowplusimport` module provides the functionality for importing
SongShow Plus songs into the OpenLP database.
"""
+import chardet
import os
import logging
import re
@@ -134,39 +135,41 @@
log.debug(length_descriptor_size)
data = song_data.read(length_descriptor).decode()
if block_key == TITLE:
- self.title = data
+ 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.parse_author(author)
+ self.parse_author(self.decode(author))
elif block_key == COPYRIGHT:
- self.addCopyright(data)
+ self.addCopyright(self.decode(data))
elif block_key == CCLI_NO:
self.ccliNumber = int(data)
elif block_key == VERSE:
- self.addVerse(data, "%s%s" % (VerseType.tags[VerseType.Verse], verse_no))
+ self.addVerse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Verse], verse_no))
elif block_key == CHORUS:
- self.addVerse(data, "%s%s" % (VerseType.tags[VerseType.Chorus], verse_no))
+ self.addVerse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Chorus], verse_no))
elif block_key == BRIDGE:
- self.addVerse(data, "%s%s" % (VerseType.tags[VerseType.Bridge], verse_no))
+ self.addVerse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Bridge], verse_no))
elif block_key == TOPIC:
- self.topics.append(data)
+ self.topics.append(self.decode(data))
elif block_key == COMMENTS:
- self.comments = data
+ self.comments = self.decode(data)
elif block_key == VERSE_ORDER:
verse_tag = self.to_openlp_verse_tag(data, True)
if verse_tag:
+ if not isinstance(verse_tag, str):
+ verse_tag = self.decode(verse_tag)
self.ssp_verse_order_list.append(verse_tag)
elif block_key == SONG_BOOK:
- self.songBookName = data
+ self.songBookName = self.decode(data)
elif block_key == SONG_NUMBER:
self.songNumber = ord(data)
elif block_key == CUSTOM_VERSE:
verse_tag = self.to_openlp_verse_tag(verse_name)
- self.addVerse(data, verse_tag)
+ self.addVerse(self.decode(data), verse_tag)
else:
log.debug("Unrecognised blockKey: %s, data: %s" % (block_key, data))
song_data.seek(next_block_starts)
@@ -204,3 +207,9 @@
verse_tag = VerseType.tags[VerseType.Other]
verse_number = self.other_list[verse_name]
return verse_tag + verse_number
+
+ def decode(self, data):
+ try:
+ return str(data, chardet.detect(data)['encoding'])
+ except:
+ return str(data, 'cp1252')
\ No newline at end of file
Follow ups