EasyWorship importer: some work to create more reasonable verse numbers if EW tags are missing or without numbers

This commit is contained in:
Benny 2011-07-05 00:55:57 +02:00
parent 4bf45ad2de
commit 3c0c9c5b78
1 changed files with 11 additions and 7 deletions

View File

@ -267,18 +267,18 @@ 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
words = strip_rtf(words, self.encoding) # TODO: convert rtf instead of stripping? words = strip_rtf(words, self.encoding) # TODO: convert rtf to display tags?
p = re.compile(r'\n *?\n[\n ]*') # at least two newlines, with zero or more space characters between them # regex: at least two newlines, with zero or more space characters between them
verse_type = VerseType.Tags[VerseType.Verse] # TODO!!!: use previous verse type.... p = re.compile(r'\n *?\n[\n ]*')
verse_type = VerseType.Tags[VerseType.Verse]
for verse in p.split(words): for verse in p.split(words):
#for verse in words.split(u'\n\n'):
# ew tags: verse, chorus, pre-chorus, bridge, tag, intro, ending, slide
verse = verse.strip() verse = verse.strip()
if len(verse) == 0: if len(verse) == 0:
continue continue
verse_split = verse.split(u'\n', 1) verse_split = verse.split(u'\n', 1)
first_line_is_tag = False first_line_is_tag = False
for type in VerseType.Names+['tag', 'slide']: # doesnt cover tag, slide # ew tags: verse, chorus, pre-chorus, bridge, tag, intro, ending, slide
for type in VerseType.Names+['tag', 'slide']:
type = type.lower() type = type.lower()
ew_tag = verse_split[0].strip().lower() ew_tag = verse_split[0].strip().lower()
if ew_tag.startswith(type): if ew_tag.startswith(type):
@ -286,20 +286,24 @@ class EasyWorshipSongImport(SongImport):
if type == 'tag' or type == 'slide': if type == 'tag' or type == 'slide':
verse_type = VerseType.Tags[VerseType.Other] verse_type = VerseType.Tags[VerseType.Other]
first_line_is_tag = True first_line_is_tag = True
number_found = False
if len(ew_tag) > len(type): # tag is followed by number and/or note if len(ew_tag) > len(type): # tag is followed by number and/or note
p = re.compile(r'[0-9]+') p = re.compile(r'[0-9]+')
m = re.search(p, ew_tag) m = re.search(p, ew_tag)
if m: if m:
number = m.group() number = m.group()
verse_type +=number verse_type +=number
number_found = True
p = re.compile(r'\(.*?\)') p = re.compile(r'\(.*?\)')
m = re.search(p, ew_tag) m = re.search(p, ew_tag)
if m: if m:
self.comments += ew_tag+'\n' self.comments += ew_tag+'\n'
if not number_found:
verse_type += '1'
break break
self.add_verse( self.add_verse(
verse_split[-1].strip() if first_line_is_tag else verse, # TODO: hacky: -1 verse_split[-1].strip() if first_line_is_tag else verse,
verse_type) verse_type)
if len(self.comments) > 5: if len(self.comments) > 5:
self.comments += unicode(translate('SongsPlugin.EasyWorshipSongImport', self.comments += unicode(translate('SongsPlugin.EasyWorshipSongImport',