openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #10667
[Merge] lp:~karan85/openlp/ewimport-fix into lp:openlp
Karan has proposed merging lp:~karan85/openlp/ewimport-fix into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~karan85/openlp/ewimport-fix/+merge/66842
- 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/66842
Your team OpenLP Core is requested to review the proposed merge of lp:~karan85/openlp/ewimport-fix into 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-04 23:11:23 +0000
@@ -31,6 +31,7 @@
import os
import struct
+import re
from openlp.core.lib import translate
from openlp.core.ui.wizard import WizardStrings
@@ -43,6 +44,14 @@
control = False
clear_text = []
control_word = []
+
+ # workaround for \tx bug: remove one pair of curly braces if \tx is encountered
+ p = re.compile(r'\{\\tx[^}]*\}')
+ m = p.search(blob)
+ if m:
+ # start and end indices of match are curly braces - filter them out
+ blob = ''.join([blob[i] for i in xrange(len(blob)) if i != m.start() and i !=m.end()])
+
for c in blob:
if control:
# for delimiters, set control to False
@@ -258,10 +267,47 @@
self.add_author(author_name.strip())
if words:
# Format the lyrics
- words = strip_rtf(words, self.encoding)
- for verse in words.split(u'\n\n'):
+ words = strip_rtf(words, self.encoding) # TODO: convert rtf to display tags?
+ # regex: at least two newlines, with zero or more space characters between them
+ p = re.compile(r'\n *?\n[\n ]*')
+ verse_type = VerseType.Tags[VerseType.Verse]
+ for verse in p.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
+ if len(ew_tag) > len(type): # tag is followed by number and/or note
+ p = re.compile(r'[0-9]+')
+ m = re.search(p, ew_tag)
+ if m:
+ number = m.group()
+ verse_type +=number
+ number_found = True
+
+ p = re.compile(r'\(.*?\)')
+ m = re.search(p, ew_tag)
+ if m:
+ self.comments += ew_tag+'\n'
+ if not number_found:
+ verse_type += '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