← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~tomasgroth/openlp/chordpro-fixes into lp:openlp

 

Tomas Groth has proposed merging lp:~tomasgroth/openlp/chordpro-fixes into lp:openlp.

Commit message:
Added support for more directives/tags when importing chord pro files.

Requested reviews:
  Tim Bentley (trb143)
  Raoul Snyman (raoul-snyman)

For more details, see:
https://code.launchpad.net/~tomasgroth/openlp/chordpro-fixes/+merge/372018
-- 
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/importers/chordpro.py'
--- openlp/plugins/songs/lib/importers/chordpro.py	2019-04-13 13:00:22 +0000
+++ openlp/plugins/songs/lib/importers/chordpro.py	2019-08-29 18:52:06 +0000
@@ -28,6 +28,7 @@
 
 from openlp.core.common.settings import Settings
 from openlp.plugins.songs.lib.importers.songimport import SongImport
+from openlp.plugins.songs.lib.db import AuthorType
 
 
 log = logging.getLogger(__name__)
@@ -39,6 +40,7 @@
 
     This importer is based on the information available on these webpages:
 
+    - https://www.chordpro.org
     - http://webchord.sourceforge.net/tech.html
     - http://www.vromans.org/johan/projects/Chordii/chordpro/
     - http://www.tenbyten.com/software/songsgen/help/HtmlHelp/files_reference.htm
@@ -73,6 +75,29 @@
                     self.title = tag_value
                 elif tag_name in ['subtitle', 'su', 'st']:
                     self.alternate_title = tag_value
+                elif tag_name == 'composer':
+                    self.parse_author(tag_value, AuthorType.Music)
+                elif tag_name in ['lyricist', 'artist', 'author']:  # author is not an official directive
+                    self.parse_author(tag_value, AuthorType.Words)
+                elif tag_name == 'meta':
+                    meta_tag_name, meta_tag_value = tag_value.split(' ', 1)
+                    # Skip, if no value
+                    if not meta_tag_value:
+                        continue
+                    # The meta-tag can contain anything. We check for the ones above and a few more
+                    if meta_tag_name in ['title', 't']:
+                        self.title = meta_tag_value
+                    elif meta_tag_name in ['subtitle', 'su', 'st']:
+                        self.alternate_title = meta_tag_value
+                    elif meta_tag_name == 'composer':
+                        self.parse_author(meta_tag_value, AuthorType.Music)
+                    elif meta_tag_name in ['lyricist', 'artist', 'author']:
+                        self.parse_author(meta_tag_value, AuthorType.Words)
+                    elif meta_tag_name in ['topic', 'topics']:
+                        for topic in meta_tag_value.split(','):
+                            self.topics.append(topic.strip())
+                    elif 'ccli' in meta_tag_name:
+                        self.ccli_number = meta_tag_value
                 elif tag_name in ['comment', 'c', 'comment_italic', 'ci', 'comment_box', 'cb']:
                     # Detect if the comment is used as a chorus repeat marker
                     if tag_value.lower().startswith('chorus'):
@@ -156,6 +181,13 @@
                     'songs/disable chords import'):
                 current_verse = re.sub(r'\[.*?\]', '', current_verse)
             self.add_verse(current_verse.rstrip(), current_verse_type)
+        # if no title was in directives, get it from the first line
+        if not self.title:
+            (verse_def, verse_text, lang) = self.verses[0]
+            # strip any chords from the title
+            self.title = re.sub(r'\[.*?\]', '', verse_text.split('\n')[0])
+            # strip the last char if it a punctuation
+            self.title = re.sub(r'[^\w\s]$', '', self.title)
         if not self.finish():
             self.log_error(song_file.name)
 

=== modified file 'tests/resources/songs/chordpro/swing-low.chordpro'
--- tests/resources/songs/chordpro/swing-low.chordpro	2016-09-25 19:27:46 +0000
+++ tests/resources/songs/chordpro/swing-low.chordpro	2019-08-29 18:52:06 +0000
@@ -1,5 +1,7 @@
 {title:Swing Low Sweet Chariot}
 {st:Traditional}
+{lyricist:Wallis Willis}
+{meta:composer Wallis Willis}
 
 {start_of_chorus}
 Swing [D]low, sweet [G]chari[D]ot,

=== modified file 'tests/resources/songs/chordpro/swing-low.json'
--- tests/resources/songs/chordpro/swing-low.json	2016-09-25 19:27:46 +0000
+++ tests/resources/songs/chordpro/swing-low.json	2019-08-29 18:52:06 +0000
@@ -1,6 +1,10 @@
 {
     "title": "Swing Low Sweet Chariot",
     "alternative_title": "Traditional",
+    "authors": [
+        ["Wallis Willis", "words"],
+        ["Wallis Willis", "music"]
+    ],
     "verses": [
         [
             "Swing [D]low, sweet [G]chari[D]ot,\nComin' for to carry me [A7]home.\nSwing [D7]low, sweet [G]chari[D]ot,\nComin' for to [A7]carry me [D]home.",


References