From d83f14f8fb1e92a3ee96787ce1f4b26856a7ff16 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat <googol@lavabit.com> Date: Sat, 26 Mar 2011 21:07:19 +0100 Subject: [PATCH 1/5] import topics from usr files, clean ups --- openlp/plugins/songs/lib/cclifileimport.py | 98 ++++++++++++---------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index f9e2963d1..2cbaa000d 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -30,6 +30,7 @@ import chardet import codecs from openlp.core.lib import translate +from openlp.plugins.songs.lib import VerseType from songimport import SongImport log = logging.getLogger(__name__) @@ -67,6 +68,7 @@ class CCLIFileImport(SongImport): (song_count, song_total)) filename = unicode(filename) log.debug(u'Importing CCLI File: %s', filename) + self.set_defaults() lines = [] if os.path.isfile(filename): detect_file = open(filename, u'r') @@ -108,35 +110,46 @@ class CCLIFileImport(SongImport): ``[File]`` USR file format first line + ``Type=`` Indicates the file type e.g. *Type=SongSelect Import File* + ``Version=3.0`` File format version + ``[S A2672885]`` Contains the CCLI Song number e.g. *2672885* + ``Title=`` Contains the song title (e.g. *Title=Above All*) + ``Author=`` Contains a | delimited list of the song authors e.g. *Author=LeBlanc, Lenny | Baloche, Paul* + ``Copyright=`` Contains a | delimited list of the song copyrights e.g. Copyright=1999 Integrity's Hosanna! Music | LenSongs Publishing (Verwaltet von Gerth Medien Musikverlag) + ``Admin=`` Contains the song administrator e.g. *Admin=Gerth Medien Musikverlag* + ``Themes=`` Contains a /t delimited list of the song themes e.g. *Themes=Cross/tKingship/tMajesty/tRedeemer* + ``Keys=`` Contains the keys in which the music is played?? e.g. *Keys=A* + ``Fields=`` Contains a list of the songs fields in order /t delimited e.g. *Fields=Vers 1/tVers 2/tChorus 1/tAndere 1* + ``Words=`` Contains the songs various lyrics in order as shown by the *Fields* description @@ -144,57 +157,60 @@ class CCLIFileImport(SongImport): """ log.debug(u'USR file text: %s', textList) - self.set_defaults() + song_author = u'' + song_topics = u'' for line in textList: if line.startswith(u'Title='): - song_name = line[6:].strip() + self.title = line[6:].strip() elif line.startswith(u'Author='): song_author = line[7:].strip() elif line.startswith(u'Copyright='): - song_copyright = line[10:].strip() + self.copyright = line[10:].strip() + elif line.startswith(u'Themes='): + song_topics = line[7:].strip() elif line.startswith(u'[S A'): - song_ccli = line[4:-3].strip() + self.ccli_number = line[4:-3].strip() elif line.startswith(u'Fields='): - #Fields contain single line indicating verse, chorus, etc, - #/t delimited, same as with words field. store seperately - #and process at end. + #Fields contain single line indicating verse, chorus, etc, + #/t delimited, same as with words field. store seperately + #and process at end. song_fields = line[7:].strip() elif line.startswith(u'Words='): song_words = line[6:].strip() - #Unhandled usr keywords:Type,Version,Admin,Themes,Keys - #Process Fields and words sections + # Unhandled usr keywords: Type, Version, Admin, Keys + # Process Fields and words sections. check_first_verse_line = False field_list = song_fields.split(u'/t') words_list = song_words.split(u'/t') for counter in range(0, len(field_list)): if field_list[counter].startswith(u'Ver'): - verse_type = u'V' + verse_type = VerseType.Tags[VerseType.Verse] elif field_list[counter].startswith(u'Ch'): - verse_type = u'C' + verse_type = VerseType.Tags[VerseType.Chorus] elif field_list[counter].startswith(u'Br'): - verse_type = u'B' - else: #Other - verse_type = u'O' + verse_type = VerseType.Tags[VerseType.Bridge] + else: + verse_type = VerseType.Tags[VerseType.Other] check_first_verse_line = True verse_text = unicode(words_list[counter]) verse_text = verse_text.replace(u'/n', u'\n') verse_lines = verse_text.split(u'\n', 1) if check_first_verse_line: if verse_lines[0].startswith(u'(PRE-CHORUS'): - verse_type = u'P' + verse_type = VerseType.Tags[VerseType.PreChorus] log.debug(u'USR verse PRE-CHORUS: %s', verse_lines[0]) verse_text = verse_lines[1] elif verse_lines[0].startswith(u'(BRIDGE'): - verse_type = u'B' + verse_type = VerseType.Tags[VerseType.Bridge] log.debug(u'USR verse BRIDGE') verse_text = verse_lines[1] elif verse_lines[0].startswith(u'('): - verse_type = u'O' + verse_type = VerseType.Tags[VerseType.Other] verse_text = verse_lines[1] if len(verse_text) > 0: self.add_verse(verse_text, verse_type) check_first_verse_line = False - #Handle multiple authors + # Handle multiple authors author_list = song_author.split(u'/') if len(author_list) < 2: author_list = song_author.split(u'|') @@ -204,9 +220,7 @@ class CCLIFileImport(SongImport): self.add_author(u' '.join(reversed(separated))) else: self.add_author(author) - self.title = song_name - self.copyright = song_copyright - self.ccli_number = song_ccli + self.topics = [topic.strip() for topic in song_topics.split(u'/t')] self.finish() def do_import_txt_file(self, textList): @@ -243,12 +257,11 @@ class CCLIFileImport(SongImport): """ log.debug(u'TXT file text: %s', textList) - self.set_defaults() line_number = 0 check_first_verse_line = False verse_text = u'' - song_comments = u'' - song_copyright = u'' + song_author = u'' + song_topics = u'' verse_start = False for line in textList: clean_line = line.strip() @@ -258,12 +271,12 @@ class CCLIFileImport(SongImport): elif verse_start: if verse_text: self.add_verse(verse_text, verse_type) - verse_text = '' + verse_text = u'' verse_start = False else: #line_number=0, song title if line_number == 0: - song_name = clean_line + self.title = clean_line line_number += 1 #line_number=1, verses elif line_number == 1: @@ -271,37 +284,37 @@ class CCLIFileImport(SongImport): if clean_line.startswith(u'CCLI'): line_number += 1 ccli_parts = clean_line.split(' ') - song_ccli = ccli_parts[len(ccli_parts)-1] + self.ccli_number = ccli_parts[len(ccli_parts)-1] elif not verse_start: # We have the verse descriptor - verse_desc_parts = clean_line.split(' ') + verse_desc_parts = clean_line.split(u' ') if len(verse_desc_parts) == 2: if verse_desc_parts[0].startswith(u'Ver'): - verse_type = u'V' + verse_type = VerseType.Tags[VerseType.Verse] elif verse_desc_parts[0].startswith(u'Ch'): - verse_type = u'C' + verse_type = VerseType.Tags[VerseType.Chorus] elif verse_desc_parts[0].startswith(u'Br'): - verse_type = u'B' + verse_type = VerseType.Tags[VerseType.Bridge] else: #we need to analyse the next line for #verse type, so set flag - verse_type = u'O' + verse_type = VerseType.Tags[VerseType.Other] check_first_verse_line = True verse_number = verse_desc_parts[1] else: - verse_type = u'O' + verse_type = VerseType.Tags[VerseType.Other] verse_number = 1 verse_start = True else: #check first line for verse type if check_first_verse_line: if line.startswith(u'(PRE-CHORUS'): - verse_type = u'P' + verse_type = VerseType.Tags[VerseType.PreChorus] elif line.startswith(u'(BRIDGE'): - verse_type = u'B' + verse_type = VerseType.Tags[VerseType.Bridge] # Handle all other misc types elif line.startswith(u'('): - verse_type = u'O' + verse_type = VerseType.Tags[VerseType.Other] else: verse_text = verse_text + line check_first_verse_line = False @@ -313,24 +326,19 @@ class CCLIFileImport(SongImport): #line_number=2, copyright if line_number == 2: line_number += 1 - song_copyright = clean_line + self.copyright = clean_line #n=3, authors elif line_number == 3: line_number += 1 song_author = clean_line #line_number=4, comments lines before last line - elif (line_number == 4) and \ - (not clean_line.startswith(u'CCL')): - song_comments = song_comments + clean_line + elif line_number == 4 and not clean_line.startswith(u'CCL'): + self.comments += clean_line # split on known separators author_list = song_author.split(u'/') if len(author_list) < 2: author_list = song_author.split(u'|') - #Clean spaces before and after author names + # Clean spaces before and after author names. for author_name in author_list: self.add_author(author_name.strip()) - self.title = song_name - self.copyright = song_copyright - self.ccli_number = song_ccli - self.comments = song_comments self.finish() From 41f0be38fbe4d1c05e424ca8c98abea6772d51f6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat <googol@lavabit.com> Date: Sat, 26 Mar 2011 21:45:11 +0100 Subject: [PATCH 2/5] clean ups --- openlp/plugins/songs/lib/cclifileimport.py | 31 +++++++++------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index 2cbaa000d..0f1c5c063 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -37,9 +37,9 @@ log = logging.getLogger(__name__) class CCLIFileImport(SongImport): """ - The :class:`CCLIFileImport` class provides OpenLP with the ability to - import CCLI SongSelect song files in both .txt and .usr formats. - See http://www.ccli.com/ for more details. + The :class:`CCLIFileImport` class provides OpenLP with the ability to import + CCLI SongSelect song files in both .txt and .usr formats. See + `<http://www.ccli.com/>`_ for more details. """ def __init__(self, manager, **kwargs): @@ -56,7 +56,7 @@ class CCLIFileImport(SongImport): def do_import(self): """ - Import either a .usr or a .txt SongSelect file + Import either a ``.usr`` or a ``.txt`` SongSelect file. """ log.debug(u'Starting CCLI File Import') song_total = len(self.import_source) @@ -83,12 +83,10 @@ class CCLIFileImport(SongImport): lines = infile.readlines() ext = os.path.splitext(filename)[1] if ext.lower() == u'.usr': - log.info(u'SongSelect .usr format file found %s: ', - filename) + log.info(u'SongSelect .usr format file found: %s', filename) self.do_import_usr_file(lines) elif ext.lower() == u'.txt': - log.info(u'SongSelect .txt format file found %s: ', - filename) + log.info(u'SongSelect .txt format file found: %s', filename) self.do_import_txt_file(lines) else: log.info(u'Extension %s is not valid', filename) @@ -99,9 +97,8 @@ class CCLIFileImport(SongImport): def do_import_usr_file(self, textList): """ - The :func:`do_import_usr_file` method provides OpenLP - with the ability to import CCLI SongSelect songs in - *USR* file format + The :func:`do_import_usr_file` method provides OpenLP with the ability + to import CCLI SongSelect songs in *USR* file format. ``textList`` An array of strings containing the usr file content. @@ -225,9 +222,8 @@ class CCLIFileImport(SongImport): def do_import_txt_file(self, textList): """ - The :func:`do_import_txt_file` method provides OpenLP - with the ability to import CCLI SongSelect songs in - *TXT* file format + The :func:`do_import_txt_file` method provides OpenLP with the ability + to import CCLI SongSelect songs in *TXT* file format. ``textList`` An array of strings containing the txt file content. @@ -261,7 +257,6 @@ class CCLIFileImport(SongImport): check_first_verse_line = False verse_text = u'' song_author = u'' - song_topics = u'' verse_start = False for line in textList: clean_line = line.strip() @@ -296,8 +291,8 @@ class CCLIFileImport(SongImport): elif verse_desc_parts[0].startswith(u'Br'): verse_type = VerseType.Tags[VerseType.Bridge] else: - #we need to analyse the next line for - #verse type, so set flag + # we need to analyse the next line for + # verse type, so set flag verse_type = VerseType.Tags[VerseType.Other] check_first_verse_line = True verse_number = verse_desc_parts[1] @@ -306,7 +301,7 @@ class CCLIFileImport(SongImport): verse_number = 1 verse_start = True else: - #check first line for verse type + # check first line for verse type if check_first_verse_line: if line.startswith(u'(PRE-CHORUS'): verse_type = VerseType.Tags[VerseType.PreChorus] From 252f316e0e6362a4faed2657d440b57417f7b75a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat <googol@lavabit.com> Date: Sat, 26 Mar 2011 21:51:41 +0100 Subject: [PATCH 3/5] missing spaces --- openlp/plugins/songs/lib/cclifileimport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index 0f1c5c063..3f66a6855 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -279,7 +279,7 @@ class CCLIFileImport(SongImport): if clean_line.startswith(u'CCLI'): line_number += 1 ccli_parts = clean_line.split(' ') - self.ccli_number = ccli_parts[len(ccli_parts)-1] + self.ccli_number = ccli_parts[len(ccli_parts) - 1] elif not verse_start: # We have the verse descriptor verse_desc_parts = clean_line.split(u' ') From f2acce4a77a261fcfef4bb9f228a7a220c93abee Mon Sep 17 00:00:00 2001 From: Andreas Preikschat <googol@lavabit.com> Date: Sat, 26 Mar 2011 21:59:44 +0100 Subject: [PATCH 4/5] missing spaces --- openlp/plugins/songs/lib/cclifileimport.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index 3f66a6855..dcfab0942 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -27,7 +27,7 @@ import logging import os import chardet -import codecs +import codecsu from openlp.core.lib import translate from openlp.plugins.songs.lib import VerseType @@ -168,9 +168,9 @@ class CCLIFileImport(SongImport): elif line.startswith(u'[S A'): self.ccli_number = line[4:-3].strip() elif line.startswith(u'Fields='): - #Fields contain single line indicating verse, chorus, etc, - #/t delimited, same as with words field. store seperately - #and process at end. + # Fields contain single line indicating verse, chorus, etc, + # /t delimited, same as with words field. store seperately + # and process at end. song_fields = line[7:].strip() elif line.startswith(u'Words='): song_words = line[6:].strip() From dbefa29054e0dfa69c49283bcb021ab4a29cdfd8 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat <googol@lavabit.com> Date: Sat, 26 Mar 2011 22:03:28 +0100 Subject: [PATCH 5/5] fixed mistake --- openlp/plugins/songs/lib/cclifileimport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index dcfab0942..03a86c455 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -27,7 +27,7 @@ import logging import os import chardet -import codecsu +import codecs from openlp.core.lib import translate from openlp.plugins.songs.lib import VerseType