From d39e1fd4a28faf55d2f9727653ea75bd25ca39ac Mon Sep 17 00:00:00 2001 From: Stewart Becker Date: Tue, 22 Apr 2014 22:43:12 +0100 Subject: [PATCH] Added comments to OepnSong files and stricter line-break tests --- openlp/plugins/songs/lib/opensongimport.py | 22 ++++++++++++++----- tests/resources/opensongsongs/Amazing Grace | 5 +++++ .../opensongsongs/Beautiful Garden Of Prayer | 18 +++++++++++---- .../Beautiful Garden Of Prayer.json | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index cafec1cea..b418e1d37 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -45,11 +45,11 @@ class OpenSongImport(SongImport): """ Import songs exported from OpenSong - The format is described loosly on the `OpenSong File Format Specification + The format is described loosely on the `OpenSong File Format Specification `_ page on the OpenSong web site. However, it doesn't describe the section, so here's an attempt: - If the first charachter of a line is a space, then the rest of that line is lyrics. If it is not a space the + If the first character of a line is a space, then the rest of that line is lyrics. If it is not a space the following applies. Verses can be expressed in one of 2 ways, either in complete verses, or by line grouping, i.e. grouping all line 1's @@ -93,12 +93,19 @@ class OpenSongImport(SongImport): All verses are imported and tagged appropriately. - Guitar chords can be provided "above" the lyrics (the line is preceeded by a period "."), and one or more "_" can + Guitar chords can be provided "above" the lyrics (the line is preceded by a period "."), and one or more "_" can be used to signify long-drawn-out words. Chords and "_" are removed by this importer. For example:: . A7 Bm 1 Some____ Words + Lines that contain only whitespace are ignored. + | indicates a blank line, and || a new slide. + + Slide 1 Line 1|Slide 1 Line 2||Slide 2 Line 1|Slide 2 Line 2 + + Lines beginning with ; are comments + The tag is used to populate the OpenLP verse display order field. The Author and Copyright tags are also imported to the appropriate places. """ @@ -193,7 +200,7 @@ class OpenSongImport(SongImport): else: lyrics = '' for this_line in lyrics.split('\n'): - if not this_line: + if not this_line.strip(): continue # skip this line if it is a comment if this_line.startswith(';'): @@ -236,7 +243,12 @@ class OpenSongImport(SongImport): this_line = this_line.replace('_', '') this_line = this_line.replace('||', '\n[---]\n') this_line = this_line.strip() - this_line = this_line.replace('|', '\n') + # If the line consists solely of a '|', then just use the implicit newline + # Otherwise, add a newline for each '|' + if this_line == '|': + this_line = '' + else: + this_line = this_line.replace('|', '\n') verses[verse_tag][verse_num][inst].append(this_line) # done parsing # add verses in original order diff --git a/tests/resources/opensongsongs/Amazing Grace b/tests/resources/opensongsongs/Amazing Grace index 363450ba5..97062dc21 100644 --- a/tests/resources/opensongsongs/Amazing Grace +++ b/tests/resources/opensongsongs/Amazing Grace @@ -13,6 +13,11 @@ [V] +;Test the chords format +;Chords beging with . +;Verses begin with their verse number +;Link words with _ +;Comments begin with ; . D D7 G D 1A______ma________zing grace! How sweet the sound! 2'Twas grace that taught my heart to fear, diff --git a/tests/resources/opensongsongs/Beautiful Garden Of Prayer b/tests/resources/opensongsongs/Beautiful Garden Of Prayer index 95b21f032..33d4943bd 100644 --- a/tests/resources/opensongsongs/Beautiful Garden Of Prayer +++ b/tests/resources/opensongsongs/Beautiful Garden Of Prayer @@ -12,28 +12,38 @@ - [V1] + +;Test breaks and newlines +;A single | on the end of a line adds an extra \n +;Blank lines are ignored, even with a space prefix +[V1] There's a garden where Jesus is waiting, + There's a place that is wondrously fair. For it glows with the light of His presence,| 'Tis the beautiful garden of prayer. +;A double || on the end of a line adds a new slide [V2] There's a garden where Jesus is waiting, And I go with my burden and care. - Just to learn from His lips, words of comfort,| + Just to learn from His lips, words of comfort,|| In the beautiful garden of prayer. +;A single | on a line adds just one line break [V3] There's a garden where Jesus is waiting, And He bids you to come meet Him there, - Just to bow and receive a new blessing,| + Just to bow and receive a new blessing, + | In the beautiful garden of prayer. +;A double || on a line adds a new slide [C] O the beautiful garden, the garden of prayer, O the beautiful garden of prayer. - There my Savior awaits, and He opens the gates|| + There my Savior awaits, and He opens the gates + || To the beautiful garden of prayer. DS0 diff --git a/tests/resources/opensongsongs/Beautiful Garden Of Prayer.json b/tests/resources/opensongsongs/Beautiful Garden Of Prayer.json index d9f4926dd..392bbaa18 100644 --- a/tests/resources/opensongsongs/Beautiful Garden Of Prayer.json +++ b/tests/resources/opensongsongs/Beautiful Garden Of Prayer.json @@ -20,7 +20,7 @@ "v1" ], [ - "There's a garden where Jesus is waiting,\nAnd I go with my burden and care.\nJust to learn from His lips, words of comfort,\n\nIn the beautiful garden of prayer.", + "There's a garden where Jesus is waiting,\nAnd I go with my burden and care.\nJust to learn from His lips, words of comfort,\n[---]\nIn the beautiful garden of prayer.", "v2" ], [