added possibility to add language to songimporter

This commit is contained in:
Andreas Preikschat 2011-01-19 20:57:08 +01:00
parent da1070468b
commit 6f344bd85a
2 changed files with 22 additions and 14 deletions

View File

@ -197,16 +197,24 @@ class SongImport(QtCore.QObject):
return return
self.media_files.append(filename) self.media_files.append(filename)
def add_verse(self, verse, versetag=u'V'): def add_verse(self, versetext, versetag=u'V', lang=None):
""" """
Add a verse. This is the whole verse, lines split by \n Add a verse. This is the whole verse, lines split by \n. It will also
Verse tag can be V1/C1/B etc, or 'V' and 'C' (will count the verses/ attempt to detect duplicates. In this case it will just add to the verse
choruses itself) or None, where it will assume verse order.
It will also attempt to detect duplicates. In this case it will just
add to the verse order ``versetext``
The text of the verse.
``versetag``
The verse tag can be V1/C1/B etc, or 'V' and 'C' (will count the verses/
choruses itself) or None, where it will assume verse.
``lang``
The language code (ISO-639) of the verse, for example *en* or *de*.
""" """
for (oldversetag, oldverse) in self.verses: for (oldversetag, oldverse, oldlang) in self.verses:
if oldverse.strip() == verse.strip(): if oldverse.strip() == versetext.strip():
self.verse_order_list.append(oldversetag) self.verse_order_list.append(oldversetag)
return return
if versetag[0] in self.versecounts: if versetag[0] in self.versecounts:
@ -217,7 +225,7 @@ class SongImport(QtCore.QObject):
versetag += unicode(self.versecounts[versetag[0]]) versetag += unicode(self.versecounts[versetag[0]])
elif int(versetag[1:]) > self.versecounts[versetag[0]]: elif int(versetag[1:]) > self.versecounts[versetag[0]]:
self.versecounts[versetag[0]] = int(versetag[1:]) self.versecounts[versetag[0]] = int(versetag[1:])
self.verses.append([versetag, verse.rstrip()]) self.verses.append([versetag, versetext.rstrip(), lang])
self.verse_order_list.append(versetag) self.verse_order_list.append(versetag)
if versetag.startswith(u'V') and self.contains_verse(u'C1'): if versetag.startswith(u'V') and self.contains_verse(u'C1'):
self.verse_order_list.append(u'C1') self.verse_order_list.append(u'C1')
@ -266,7 +274,7 @@ class SongImport(QtCore.QObject):
verses_changed_to_other = {} verses_changed_to_other = {}
sxml = SongXML() sxml = SongXML()
other_count = 1 other_count = 1
for (versetag, versetext) in self.verses: for (versetag, versetext, lang) in self.verses:
if versetag[0] == u'C': if versetag[0] == u'C':
versetype = VerseType.to_string(VerseType.Chorus) versetype = VerseType.to_string(VerseType.Chorus)
elif versetag[0] == u'V': elif versetag[0] == u'V':
@ -286,7 +294,7 @@ class SongImport(QtCore.QObject):
versetype = VerseType.to_string(VerseType.Other) versetype = VerseType.to_string(VerseType.Other)
log.info(u'Versetype %s changing to %s' , versetag, newversetag) log.info(u'Versetype %s changing to %s' , versetag, newversetag)
versetag = newversetag versetag = newversetag
sxml.add_verse_to_lyrics(versetype, versetag[1:], versetext) sxml.add_verse_to_lyrics(versetype, versetag[1:], versetext, lang)
song.search_lyrics += u' ' + self.remove_punctuation(versetext) song.search_lyrics += u' ' + self.remove_punctuation(versetext)
song.search_lyrics = song.search_lyrics.lower() song.search_lyrics = song.search_lyrics.lower()
song.lyrics = unicode(sxml.extract_xml(), u'utf-8') song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
@ -338,7 +346,7 @@ class SongImport(QtCore.QObject):
+ u'========================================' + u'========================================'
print u'TITLE: ' + self.title print u'TITLE: ' + self.title
print u'ALT TITLE: ' + self.alternate_title print u'ALT TITLE: ' + self.alternate_title
for (versetag, versetext) in self.verses: for (versetag, versetext, lang) in self.verses:
print u'VERSE ' + versetag + u': ' + versetext print u'VERSE ' + versetag + u': ' + versetext
print u'ORDER: ' + u' '.join(self.verse_order_list) print u'ORDER: ' + u' '.join(self.verse_order_list)
for author in self.authors: for author in self.authors:

View File

@ -99,8 +99,8 @@ class SongXML(object):
The actual text of the verse to be stored. The actual text of the verse to be stored.
``lang`` ``lang``
The verse's language code. This is not required, but should be added The verse's language code (ISO-639). This is not required, but
if available. should be added if available.
""" """
verse = etree.Element(u'verse', type=unicode(type), verse = etree.Element(u'verse', type=unicode(type),
label=unicode(number)) label=unicode(number))