openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #10670
[Merge] lp:~karan85/openlp/ewimport-fix into lp:openlp
Karan has proposed merging lp:~karan85/openlp/ewimport-fix into lp:openlp.
Requested reviews:
Tim Bentley (trb143)
Karan (karan85)
For more details, see:
https://code.launchpad.net/~karan85/openlp/ewimport-fix/+merge/66885
- added conversion of EW Song Tags (Verse, Chorus, Bridge etc)
- improved slide break detection
- fixed bug in rtf stripping code that caused lyrics to be stripped as well
Tested with my 700 song EW database.
Don't be too hard on me - I haven't used Bazaar before and didn't write any Python for 5 years :)
--
https://code.launchpad.net/~karan85/openlp/ewimport-fix/+merge/66885
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/ewimport.py'
--- openlp/plugins/songs/lib/ewimport.py 2011-06-12 16:02:52 +0000
+++ openlp/plugins/songs/lib/ewimport.py 2011-07-05 11:16:33 +0000
@@ -31,6 +31,7 @@
import os
import struct
+import re
from openlp.core.lib import translate
from openlp.core.ui.wizard import WizardStrings
@@ -38,11 +39,26 @@
from openlp.plugins.songs.lib import retrieve_windows_encoding
from songimport import SongImport
+RTF_STRIPPING_REGEX = re.compile(r'\{\\tx[^}]*\}')
+# regex: at least two newlines, can have spaces between them
+SLIDE_BREAK_REGEX = re.compile(r'\n *?\n[\n ]*')
+NUMBER_REGEX = re.compile(r'[0-9]+')
+NOTE_REGEX = re.compile(r'\(.*?\)')
+
def strip_rtf(blob, encoding):
depth = 0
control = False
clear_text = []
control_word = []
+
+ # workaround for \tx bug: remove one pair of curly braces
+ # if \tx is encountered
+ match = RTF_STRIPPING_REGEX.search(blob)
+ if match:
+ # start and end indices of match are curly braces - filter them out
+ blob = ''.join([blob[i] for i in xrange(len(blob))
+ if i != match.start() and i !=match.end()])
+
for c in blob:
if control:
# for delimiters, set control to False
@@ -259,9 +275,45 @@
if words:
# Format the lyrics
words = strip_rtf(words, self.encoding)
- for verse in words.split(u'\n\n'):
+ verse_type = VerseType.Tags[VerseType.Verse]
+ for verse in SLIDE_BREAK_REGEX.split(words):
+ verse = verse.strip()
+ if len(verse) == 0:
+ continue
+ verse_split = verse.split(u'\n', 1)
+ first_line_is_tag = False
+ # EW tags: verse, chorus, pre-chorus, bridge, tag,
+ # intro, ending, slide
+ for type in VerseType.Names+['tag', 'slide']:
+ type = type.lower()
+ ew_tag = verse_split[0].strip().lower()
+ if ew_tag.startswith(type):
+ verse_type = type[0]
+ if type == 'tag' or type == 'slide':
+ verse_type = VerseType.Tags[VerseType.Other]
+ first_line_is_tag = True
+ number_found = False
+ # check if tag is followed by number and/or note
+ if len(ew_tag) > len(type):
+ match = NUMBER_REGEX.search(ew_tag)
+ if match:
+ number = match.group()
+ verse_type +=number
+ number_found = True
+ match = NOTE_REGEX.search(ew_tag)
+ if match:
+ self.comments += ew_tag + u'\n'
+ if not number_found:
+ verse_type += u'1'
+ break
self.add_verse(
- verse.strip(), VerseType.Tags[VerseType.Verse])
+ verse_split[-1].strip() if first_line_is_tag else verse,
+ verse_type)
+ if len(self.comments) > 5:
+ self.comments += unicode(
+ translate('SongsPlugin.EasyWorshipSongImport',
+ '\n[above are Song Tags with notes imported from \
+ EasyWorship]'))
if self.stop_import_flag:
break
if not self.finish():
Follow ups