This commit is contained in:
Jonathan Corwin 2010-04-12 22:49:56 +01:00
parent 578a81236a
commit e4989f422b

View File

@ -68,11 +68,15 @@ class SongImport(object):
@staticmethod @staticmethod
def process_songs_text(manager, text): def process_songs_text(manager, text):
songs = [] songs = []
songtexts = SongImport.tidy_text(text).split(u'\n\n\n') songtexts = SongImport.tidy_text(text).split(u'\f')
for songtext in songtexts:
if songtext.strip() != u'':
song = SongImport(manager) song = SongImport(manager)
for songtext in songtexts:
if songtext.strip():
song.process_song_text(songtext.strip()) song.process_song_text(songtext.strip())
if song.check_complete():
songs.append(song)
song = SongImport(manager)
if song.check_complete():
songs.append(song) songs.append(song)
return songs return songs
@ -83,7 +87,6 @@ class SongImport(object):
interested in. Some can be converted to ascii. interested in. Some can be converted to ascii.
""" """
text = text.replace(u'\t', u' ') text = text.replace(u'\t', u' ')
text = text.replace(u'\f', u'\n\n\n')
text = text.replace(u'\r\n', u'\n') text = text.replace(u'\r\n', u'\n')
text = text.replace(u'\r', u'\n') text = text.replace(u'\r', u'\n')
text = text.replace(u'\u2018', u'\'') text = text.replace(u'\u2018', u'\'')
@ -96,12 +99,13 @@ class SongImport(object):
# Remove surplus blank lines, spaces, trailing/leading spaces # Remove surplus blank lines, spaces, trailing/leading spaces
while text.find(u' ') >= 0: while text.find(u' ') >= 0:
text = text.replace(u' ', u' ') text = text.replace(u' ', u' ')
while text.find(u'\n ') >= 0:
text = text.replace(u'\n ', u'\n') text = text.replace(u'\n ', u'\n')
while text.find(u' \n') >= 0:
text = text.replace(u' \n', u'\n') text = text.replace(u' \n', u'\n')
while text.find(u'\n\n\n\n') >= 0: text = text.replace(u'\n\n\n\n\n', u'\f')
text = text.replace(u'\n\n\n\n', u'\n\n\n') text = text.replace(u'\f ', u'\f')
text = text.replace(u' \f', u'\f')
while text.find(u'\f\f') >= 0:
text = text.replace(u'\f\f', u'\f')
return text return text
def process_song_text(self, text): def process_song_text(self, text):
@ -190,7 +194,6 @@ class SongImport(object):
However need to check for "Mr and Mrs Smith" and turn it to However need to check for "Mr and Mrs Smith" and turn it to
"Mr Smith" and "Mrs Smith". "Mr Smith" and "Mrs Smith".
""" """
text = text.replace(u' and ', u' & ')
for author in text.split(u','): for author in text.split(u','):
authors = author.split(u'&') authors = author.split(u'&')
for i in range(len(authors)): for i in range(len(authors)):