forked from openlp/openlp
Added support for importing EW songs even if RTF is not escaped as espected, also fixed importing og songs with unicode in metadata.
Fixes: https://launchpad.net/bugs/1299837
This commit is contained in:
parent
0160c583e9
commit
5d63820b17
@ -281,7 +281,7 @@ class EasyWorshipSongImport(SongImport):
|
|||||||
raw_record = db_file.read(record_size)
|
raw_record = db_file.read(record_size)
|
||||||
self.fields = self.record_structure.unpack(raw_record)
|
self.fields = self.record_structure.unpack(raw_record)
|
||||||
self.set_defaults()
|
self.set_defaults()
|
||||||
self.title = self.get_field(fi_title).decode()
|
self.title = self.get_field(fi_title).decode('unicode-escape')
|
||||||
# Get remaining fields.
|
# Get remaining fields.
|
||||||
copy = self.get_field(fi_copy)
|
copy = self.get_field(fi_copy)
|
||||||
admin = self.get_field(fi_admin)
|
admin = self.get_field(fi_admin)
|
||||||
@ -289,16 +289,16 @@ class EasyWorshipSongImport(SongImport):
|
|||||||
authors = self.get_field(fi_author)
|
authors = self.get_field(fi_author)
|
||||||
words = self.get_field(fi_words)
|
words = self.get_field(fi_words)
|
||||||
if copy:
|
if copy:
|
||||||
self.copyright = copy.decode()
|
self.copyright = copy.decode('unicode-escape')
|
||||||
if admin:
|
if admin:
|
||||||
if copy:
|
if copy:
|
||||||
self.copyright += ', '
|
self.copyright += ', '
|
||||||
self.copyright += translate('SongsPlugin.EasyWorshipSongImport',
|
self.copyright += translate('SongsPlugin.EasyWorshipSongImport',
|
||||||
'Administered by %s') % admin.decode()
|
'Administered by %s') % admin.decode('unicode-escape')
|
||||||
if ccli:
|
if ccli:
|
||||||
self.ccli_number = ccli.decode()
|
self.ccli_number = ccli.decode('unicode-escape')
|
||||||
if authors:
|
if authors:
|
||||||
authors = authors.decode()
|
authors = authors.decode('unicode-escape')
|
||||||
else:
|
else:
|
||||||
authors = ''
|
authors = ''
|
||||||
# Set the SongImport object members.
|
# Set the SongImport object members.
|
||||||
@ -328,7 +328,20 @@ class EasyWorshipSongImport(SongImport):
|
|||||||
self.add_author(author_name.strip())
|
self.add_author(author_name.strip())
|
||||||
if words:
|
if words:
|
||||||
# Format the lyrics
|
# Format the lyrics
|
||||||
result = strip_rtf(words.decode(), self.encoding)
|
result = None
|
||||||
|
decoded_words = None
|
||||||
|
try:
|
||||||
|
decoded_words = words.decode()
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
log.debug('The unicode chars in the rtf was not escaped in the expected manor, doing it manually.')
|
||||||
|
newbytes = bytearray()
|
||||||
|
for b in words:
|
||||||
|
if b > 127:
|
||||||
|
newbytes += bytearray(b'\\\'') + bytearray(str(hex(b))[-2:].encode())
|
||||||
|
else:
|
||||||
|
newbytes.append(b)
|
||||||
|
decoded_words = newbytes.decode()
|
||||||
|
result = strip_rtf(decoded_words, self.encoding)
|
||||||
if result is None:
|
if result is None:
|
||||||
return
|
return
|
||||||
words, self.encoding = result
|
words, self.encoding = result
|
||||||
|
@ -67,7 +67,21 @@ SONG_TEST_DATA = [
|
|||||||
'Just to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.', 'v2'),
|
'Just to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.', 'v2'),
|
||||||
('There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n'
|
('There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n'
|
||||||
'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', 'v3')],
|
'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', 'v3')],
|
||||||
'verse_order_list': []}]
|
'verse_order_list': []},
|
||||||
|
{'title': 'Vi pløjed og vi så\'de',
|
||||||
|
'authors': ['Matthias Claudius'],
|
||||||
|
'copyright': 'Public Domain',
|
||||||
|
'ccli_number': 0,
|
||||||
|
'verses':
|
||||||
|
[('Vi pløjed og vi så\'de\nvor sæd i sorten jord,\nså bad vi ham os hjælpe,\nsom højt i Himlen bor,\n'
|
||||||
|
'og han lod snefald hegne\nmod frosten barsk og hård,\nhan lod det tø og regne\nog varme mildt i vår.',
|
||||||
|
'v1'),
|
||||||
|
('Alle gode gaver\nde kommer ovenned,\nså tak da Gud, ja, pris dog Gud\nfor al hans kærlighed!', 'c1'),
|
||||||
|
('Han er jo den, hvis vilje\nopholder alle ting,\nhan klæder markens lilje\nog runder himlens ring,\n'
|
||||||
|
'ham lyder vind og vove,\nham rører ravnes nød,\nhvi skulle ej hans småbørn\nda og få dagligt brød?', 'v2'),
|
||||||
|
('Ja, tak, du kære Fader,\nså mild, så rig, så rund,\nfor korn i hæs og lader,\nfor godt i allen stund!\n'
|
||||||
|
'Vi kan jo intet give,\nsom nogen ting er værd,\nmen tag vort stakkels hjerte,\nså ringe som det er!', 'v3')],
|
||||||
|
'verse_order_list': []}]
|
||||||
|
|
||||||
EWS_SONG_TEST_DATA =\
|
EWS_SONG_TEST_DATA =\
|
||||||
{'title': 'Vi pløjed og vi så\'de',
|
{'title': 'Vi pløjed og vi så\'de',
|
||||||
@ -139,6 +153,14 @@ class TestEasyWorshipSongImport(TestCase):
|
|||||||
"""
|
"""
|
||||||
Test the functions in the :mod:`ewimport` module.
|
Test the functions in the :mod:`ewimport` module.
|
||||||
"""
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
self.songimport_patcher = patch('openlp.plugins.songs.lib.ewimport.EasyWorshipSongImport.__init__')
|
||||||
|
self.mocked_songimport = self.songimport_patcher.start()
|
||||||
|
self.mocked_songimport.return_value = None
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.songimport_patcher.stop()
|
||||||
|
|
||||||
def create_field_desc_entry_test(self):
|
def create_field_desc_entry_test(self):
|
||||||
"""
|
"""
|
||||||
Test creating an instance of the :class`FieldDescEntry` class.
|
Test creating an instance of the :class`FieldDescEntry` class.
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user