From ad94e7c19f7766375e22bdcbda48ffc0805bad56 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 11 May 2017 21:53:47 +0200 Subject: [PATCH] Added some more comments for songbeamer import and added support for author type. --- openlp/plugins/songs/lib/importers/songbeamer.py | 16 +++++++--------- openlp/plugins/songs/lib/importers/songimport.py | 4 ++-- .../resources/songbeamersongs/Amazing Grace.json | 2 +- .../songbeamersongs/Lobsinget dem Herrn.json | 5 ++++- tests/resources/songbeamersongs/cp1252song.json | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/songbeamer.py b/openlp/plugins/songs/lib/importers/songbeamer.py index 442a2fefd..a48a57e96 100644 --- a/openlp/plugins/songs/lib/importers/songbeamer.py +++ b/openlp/plugins/songs/lib/importers/songbeamer.py @@ -119,7 +119,6 @@ class SongBeamerImport(SongImport): self.current_verse = '' self.current_verse_type = VerseType.tags[VerseType.Verse] self.chord_table = None - self.editor_version = 0 file_name = os.path.split(import_file)[1] if os.path.isfile(import_file): # Detect the encoding @@ -181,12 +180,14 @@ class SongBeamerImport(SongImport): verse_tags_mode = VerseTagMode.ContainsNoTags elif verse_tags_mode != VerseTagMode.ContainsNoTagsRestart: if not verse_mark and verse_tags_mode == VerseTagMode.ContainsTags: - # Restart loop without counting tags as lines + # A verse mark was expected but not found, which means that verse marks has not been + # inserted by songbeamer, but are manually added headings. So restart the loop, and + # count tags as lines. self.set_defaults() self.title = file_name.split('.sng')[0] verse_tags_mode = VerseTagMode.ContainsNoTagsRestart read_verses = False - # The first verse separator doesn't count, but the others does, so line count starts at -1 + # The first verseseparator doesn't count, but the others does, so linecount starts at -1 line_number = -1 first_verse = True idx = -1 @@ -257,7 +258,7 @@ class SongBeamerImport(SongImport): elif tag_val[0] == '#AudioFile': self.parse_audio_file(tag_val[1]) elif tag_val[0] == '#Author': - self.parse_author(tag_val[1]) + self.parse_author(tag_val[1], 'words') elif tag_val[0] == '#BackgroundImage': pass elif tag_val[0] == '#Bible': @@ -278,10 +279,7 @@ class SongBeamerImport(SongImport): except ValueError: self.comments = tag_val[1] elif tag_val[0] == '#Editor': - try: - self.editor_version = float(re.sub('[a-zA-Z ]', '', tag_val[1])) - except ValueError: - self.editor_version = 0 + pass elif tag_val[0] == '#Font': pass elif tag_val[0] == '#FontLang2': @@ -303,7 +301,7 @@ class SongBeamerImport(SongImport): elif tag_val[0] == '#LangCount': pass elif tag_val[0] == '#Melody': - self.parse_author(tag_val[1]) + self.parse_author(tag_val[1], 'music') elif tag_val[0] == '#NatCopyright': pass elif tag_val[0] == '#OTitle': diff --git a/openlp/plugins/songs/lib/importers/songimport.py b/openlp/plugins/songs/lib/importers/songimport.py index 7f5ff99a8..58c124410 100644 --- a/openlp/plugins/songs/lib/importers/songimport.py +++ b/openlp/plugins/songs/lib/importers/songimport.py @@ -242,7 +242,7 @@ class SongImport(QtCore.QObject): self.copyright += ' ' self.copyright += copyright - def parse_author(self, text): + def parse_author(self, text, type=None): """ Add the author. OpenLP stores them individually so split by 'and', '&' and comma. However need to check for 'Mr and Mrs Smith' and turn it to 'Mr Smith' and 'Mrs Smith'. @@ -256,7 +256,7 @@ class SongImport(QtCore.QObject): if author2.endswith('.'): author2 = author2[:-1] if author2: - self.add_author(author2) + self.add_author(author2, type) def add_author(self, author, type=None): """ diff --git a/tests/resources/songbeamersongs/Amazing Grace.json b/tests/resources/songbeamersongs/Amazing Grace.json index a2601cc7d..54258a3a2 100644 --- a/tests/resources/songbeamersongs/Amazing Grace.json +++ b/tests/resources/songbeamersongs/Amazing Grace.json @@ -1,6 +1,6 @@ { "authors": [ - "John Newton" + ["John Newton", "words"] ], "title": "Amazing grace", "verse_order_list": ["v1", "v2", "v3", "v4", "v5"], diff --git a/tests/resources/songbeamersongs/Lobsinget dem Herrn.json b/tests/resources/songbeamersongs/Lobsinget dem Herrn.json index d2069a687..1e210aa4c 100644 --- a/tests/resources/songbeamersongs/Lobsinget dem Herrn.json +++ b/tests/resources/songbeamersongs/Lobsinget dem Herrn.json @@ -8,5 +8,8 @@ ], "song_book_name": "Glaubenslieder I", "song_number": "1", - "authors": ["Carl Brockhaus", "Johann Jakob Vetter"] + "authors": [ + ["Carl Brockhaus", "words"], + ["Johann Jakob Vetter", "music"] + ] } diff --git a/tests/resources/songbeamersongs/cp1252song.json b/tests/resources/songbeamersongs/cp1252song.json index 5e92d7038..20df4a2cc 100644 --- a/tests/resources/songbeamersongs/cp1252song.json +++ b/tests/resources/songbeamersongs/cp1252song.json @@ -1,6 +1,8 @@ { "title": "Some Song", - "authors": ["Author"], + "authors": [ + ["Author", "words"] + ], "verses" : [ ["Here are a couple of \"weird\" chars’’’.\n", "v"], ["Here is another one….\n\n", "v"]