← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/OpenLyrics into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/OpenLyrics into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/OpenLyrics/+merge/46817

Hello!

- The reindex tool removes the language attribute from the lyrics field as there was always only "en" added (and it is not needed anyway). So this makes sure that the database stays as clean as possible).
- The OpenLyrics importer adds now the language of a verse to the database. So, we can theoretical distinguish V1 (en) and V1 (de). Theoretical because we don't use this right now.
- Added the possibility to add the language of a verse to the database to the songimporter.

Cheers
-- 
https://code.launchpad.net/~googol-hush/openlp/OpenLyrics/+merge/46817
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/OpenLyrics into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/songimportform.py'
--- openlp/plugins/songs/forms/songimportform.py	2011-01-18 18:53:09 +0000
+++ openlp/plugins/songs/forms/songimportform.py	2011-01-19 20:06:27 +0000
@@ -654,7 +654,7 @@
             'Select EasiSlides songfile'),
             self.easiSlidesFilenameEdit
         )
-  
+
     def onEWBrowseButtonClicked(self):
         """
         Get EasyWorship song database files

=== modified file 'openlp/plugins/songs/lib/easislidesimport.py'
--- openlp/plugins/songs/lib/easislidesimport.py	2011-01-18 18:53:09 +0000
+++ openlp/plugins/songs/lib/easislidesimport.py	2011-01-19 20:06:27 +0000
@@ -313,7 +313,7 @@
                     tag = SeqTypes[tag.lower()]
                 else:
                     continue
- 
+
                 if tag in versetags:
                     self.verse_order_list.append(tag)
                 else:

=== modified file 'openlp/plugins/songs/lib/openlyricsimport.py'
--- openlp/plugins/songs/lib/openlyricsimport.py	2011-01-13 17:55:29 +0000
+++ openlp/plugins/songs/lib/openlyricsimport.py	2011-01-19 20:06:27 +0000
@@ -61,14 +61,17 @@
         Imports the songs.
         """
         self.import_wizard.progressBar.setMaximum(len(self.import_source))
+        parser = etree.XMLParser(remove_blank_text=True)
         for file_path in self.import_source:
             if self.stop_import_flag:
                 return False
             self.import_wizard.incrementProgressBar(unicode(translate(
                 'SongsPlugin.OpenLyricsImport', 'Importing %s...')) %
                 os.path.basename(file_path))
-            parser = etree.XMLParser(remove_blank_text=True)
-            parsed_file = etree.parse(file_path, parser)
+            try:
+                parsed_file = etree.parse(file_path, parser)
+            except etree.XMLSyntaxError:
+                return False
             xml = unicode(etree.tostring(parsed_file))
             if self.openLyrics.xml_to_song(xml) is None:
                 log.debug(u'File could not be imported: %s' % file_path)

=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py	2011-01-18 17:26:57 +0000
+++ openlp/plugins/songs/lib/songimport.py	2011-01-19 20:06:27 +0000
@@ -197,16 +197,24 @@
             return
         self.media_files.append(filename)
 
-    def add_verse(self, verse, versetag=u'V'):
-        """
-        Add a verse. This is the whole verse, lines split by \n
-        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
-        It will also attempt to detect duplicates. In this case it will just
-        add to the verse order
-        """
-        for (oldversetag, oldverse) in self.verses:
-            if oldverse.strip() == verse.strip():
+    def add_verse(self, versetext, versetag=u'V', lang=None):
+        """
+        Add a verse. This is the whole verse, lines split by \n. 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, oldlang) in self.verses:
+            if oldverse.strip() == versetext.strip():
                 self.verse_order_list.append(oldversetag)
                 return
         if versetag[0] in self.versecounts:
@@ -217,7 +225,7 @@
             versetag += unicode(self.versecounts[versetag[0]])
         elif int(versetag[1:]) > self.versecounts[versetag[0]]:
             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)
         if versetag.startswith(u'V') and self.contains_verse(u'C1'):
             self.verse_order_list.append(u'C1')
@@ -266,7 +274,7 @@
         verses_changed_to_other = {}
         sxml = SongXML()
         other_count = 1
-        for (versetag, versetext) in self.verses:
+        for (versetag, versetext, lang) in self.verses:
             if versetag[0] == u'C':
                 versetype = VerseType.to_string(VerseType.Chorus)
             elif versetag[0] == u'V':
@@ -286,7 +294,7 @@
                 versetype = VerseType.to_string(VerseType.Other)
                 log.info(u'Versetype %s changing to %s' , 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 = song.search_lyrics.lower()
         song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
@@ -338,7 +346,7 @@
             + u'========================================'
         print u'TITLE: ' + self.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'ORDER: ' + u' '.join(self.verse_order_list)
         for author in self.authors:

=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py	2011-01-18 04:32:24 +0000
+++ openlp/plugins/songs/lib/xml.py	2011-01-19 20:06:27 +0000
@@ -31,7 +31,7 @@
     <?xml version="1.0" encoding="UTF-8"?>
     <song version="1.0">
         <lyrics>
-            <verse type="chorus" label="1">
+            <verse type="Chorus" label="1" lang="en">
                 <![CDATA[ ... ]]>
             </verse>
         </lyrics>
@@ -84,7 +84,7 @@
         self.song_xml = objectify.fromstring(u'<song version="1.0" />')
         self.lyrics = etree.SubElement(self.song_xml, u'lyrics')
 
-    def add_verse_to_lyrics(self, type, number, content):
+    def add_verse_to_lyrics(self, type, number, content, lang=None):
         """
         Add a verse to the *<lyrics>* tag.
 
@@ -97,9 +97,15 @@
 
         ``content``
             The actual text of the verse to be stored.
+
+        ``lang``
+            The verse's language code (ISO-639). This is not required, but
+            should be added if available.
         """
         verse = etree.Element(u'verse', type=unicode(type),
             label=unicode(number))
+        if lang:
+            verse.set(u'lang', lang)
         verse.text = etree.CDATA(content)
         self.lyrics.append(verse)
 
@@ -117,6 +123,11 @@
 
         ``xml``
             The XML of the song to be parsed.
+
+        The returned list has the following format::
+
+            [[{'lang': 'en', 'type': 'V', 'label': '1'}, u"The English verse."],
+            [{'lang': 'en', 'type': 'C', 'label': '1'}, u"The English chorus."]]
         """
         self.song_xml = None
         if xml[:5] == u'<?xml':
@@ -196,7 +207,7 @@
         This property is not supported.
 
     *<verse name="v1a" lang="he" translit="en">*
-        The attribute *translit* and *lang* are not supported.
+        The attribute *translit* is not supported.
 
     *<verseOrder>*
         OpenLP supports this property.
@@ -442,7 +453,10 @@
             if not verse_number:
                 verse_number = u'1'
             temp_verse_order.append((verse_type, verse_number, verse_part))
-            sxml.add_verse_to_lyrics(verse_type, verse_number, text)
+            lang = None
+            if self._get(verse, u'lang'):
+                lang = self._get(verse, u'lang')
+            sxml.add_verse_to_lyrics(verse_type, verse_number, text, lang)
             search_text = search_text + text
         song.search_lyrics = search_text.lower()
         song.lyrics = unicode(sxml.extract_xml(), u'utf-8')

=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py	2011-01-09 16:52:31 +0000
+++ openlp/plugins/songs/songsplugin.py	2011-01-19 20:06:27 +0000
@@ -134,7 +134,7 @@
 
     def onToolsReindexItemTriggered(self):
         """
-        Rebuild the search title of each song.
+        Rebuild each song.
         """
         maxSongs = self.manager.get_object_count(Song)
         progressDialog = QtGui.QProgressDialog(
@@ -150,8 +150,13 @@
                 song.title = u''
             if song.alternate_title is None:
                 song.alternate_title = u''
-            song.search_title = self.whitespace.sub(u' ', song.title.lower() + \
+            song.search_title = self.whitespace.sub(u' ', song.title.lower() +
                 u' ' + song.alternate_title.lower())
+            # Remove the "language" attribute from lyrics tag. This is not very
+            # important, but this keeps the database clean. This can be removed
+            # when everybody has run the reindex tool once.
+            song.lyrics = song.lyrics.replace(
+                u'<lyrics language="en">', u'<lyrics>')
             lyrics = u''
             verses = SongXML().get_verses(song.lyrics)
             for verse in verses:
@@ -159,8 +164,7 @@
             song.search_lyrics = lyrics.lower()
             progressDialog.setValue(counter)
         self.manager.save_objects(songs)
-        counter += 1
-        progressDialog.setValue(counter)
+        progressDialog.setValue(counter + 1)
         self.mediaItem.displayResultsSong(
             self.manager.get_all_objects(Song, order_by_ref=Song.search_title))
 


Follow ups