bzr-revno: 1592
Fixes: https://launchpad.net/bugs/789143
This commit is contained in:
Andreas Preikschat 2011-05-29 17:59:47 +02:00
commit fd4d316097

View File

@ -265,52 +265,57 @@ def clean_song(manager, song):
whitespace = re.compile(r'\W+', re.UNICODE) whitespace = re.compile(r'\W+', re.UNICODE)
song.search_title = (whitespace.sub(u' ', song.title).strip() + u'@' + song.search_title = (whitespace.sub(u' ', song.title).strip() + u'@' +
whitespace.sub(u' ', song.alternate_title).strip()).strip().lower() whitespace.sub(u' ', song.alternate_title).strip()).strip().lower()
# Remove the old "language" attribute from lyrics tag (prior to 1.9.5). This # Only do this, if we the song is a 1.9.4 song (or older).
# is not very important, but this keeps the database clean. This can be if song.lyrics.find(u'<lyrics language="en">') != -1:
# removed when everybody has cleaned his songs. # Remove the old "language" attribute from lyrics tag (prior to 1.9.5).
song.lyrics = song.lyrics.replace(u'<lyrics language="en">', u'<lyrics>') # This is not very important, but this keeps the database clean. This
verses = SongXML().get_verses(song.lyrics) # can be removed when everybody has cleaned his songs.
lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses]) song.lyrics = song.lyrics.replace(
song.search_lyrics = lyrics.lower() u'<lyrics language="en">', u'<lyrics>')
# We need a new and clean SongXML instance. verses = SongXML().get_verses(song.lyrics)
sxml = SongXML() lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses])
# Rebuild the song's verses, to remove any wrong verse names (for example song.search_lyrics = lyrics.lower()
# translated ones), which might have been added prior to 1.9.5. # We need a new and clean SongXML instance.
# List for later comparison. sxml = SongXML()
compare_order = [] # Rebuild the song's verses, to remove any wrong verse names (for
for verse in verses: # example translated ones), which might have been added prior to 1.9.5.
verse_type = VerseType.Tags[VerseType.from_loose_input( # List for later comparison.
verse[0][u'type'])] compare_order = []
sxml.add_verse_to_lyrics( for verse in verses:
verse_type, verse_type = VerseType.Tags[VerseType.from_loose_input(
verse[0][u'label'], verse[0][u'type'])]
verse[1], sxml.add_verse_to_lyrics(
verse[0][u'lang'] if verse[0].has_key(u'lang') else None verse_type,
) verse[0][u'label'],
compare_order.append((u'%s%s' % (verse_type, verse[0][u'label']) verse[1],
).upper()) verse[0][u'lang'] if verse[0].has_key(u'lang') else None
if verse[0][u'label'] == u'1': )
compare_order.append(verse_type.upper()) compare_order.append((u'%s%s' % (verse_type, verse[0][u'label'])
song.lyrics = unicode(sxml.extract_xml(), u'utf-8') ).upper())
# Rebuild the verse order, to convert translated verse tags, which might if verse[0][u'label'] == u'1':
# have been added prior to 1.9.5. compare_order.append(verse_type.upper())
if song.verse_order: song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
order = song.verse_order.strip().split() # Rebuild the verse order, to convert translated verse tags, which might
else: # have been added prior to 1.9.5.
order = [] if song.verse_order:
new_order = [] order = song.verse_order.strip().split()
for verse_def in order:
verse_type = VerseType.Tags[VerseType.from_loose_input(verse_def[0])]
if len(verse_def) > 1:
new_order.append((u'%s%s' % (verse_type, verse_def[1:])).upper())
else: else:
new_order.append(verse_type.upper()) order = []
song.verse_order = u' '.join(new_order) new_order = []
# Check if the verse order contains tags for verses which do not exist. for verse_def in order:
for order in new_order: verse_type = VerseType.Tags[
if order not in compare_order: VerseType.from_loose_input(verse_def[0])]
song.verse_order = u'' if len(verse_def) > 1:
break new_order.append(
(u'%s%s' % (verse_type, verse_def[1:])).upper())
else:
new_order.append(verse_type.upper())
song.verse_order = u' '.join(new_order)
# Check if the verse order contains tags for verses which do not exist.
for order in new_order:
if order not in compare_order:
song.verse_order = u''
break
# The song does not have any author, add one. # The song does not have any author, add one.
if not song.authors: if not song.authors:
name = SongStrings.AuthorUnknown name = SongStrings.AuthorUnknown