songimport

class openlp.plugins.songs.lib.importers.songimport.SongImport(manager, **kwargs)[source]

Bases: PyQt5.QtCore.QObject

Helper class for import a song from a third party source into OpenLP

This class just takes the raw strings, and will work out for itself whether the authors etc already exist and add them or refer to them as necessary

add_author(author, type=None)[source]

Add an author to the list

add_comment(comment)[source]

Build the comments field

Build the copyright field

add_media_file(filename, weight=0)[source]

Add a media file to the list

add_verse(verse_text, verse_def='v', lang=None)[source]

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.

Parameters:
  • verse_text – The text of the verse.
  • verse_def – 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.
check_complete()[source]

Check the mandatory fields are entered (i.e. title and a verse) Author not checked here, if no author then “Author unknown” is automatically added

copy_media_file(song_id, filename)[source]

This method copies the media file to the correct location and returns the new file location.

Parameters:
  • song_id
  • filename – The file to copy.
finish()[source]

All fields have been set to this song. Write the song to disk.

static is_valid_source(import_source)[source]

Override this method to validate the source prior to import.

log_error(file_path, reason='Title and/or verses not found')[source]

This should be called, when a song could not be imported.

Parameters:
  • file_path – This should be the file path if self.import_source is a list with different files. If it is not a list, but a single file (for instance a database), then this should be the song’s title.
  • reason – The reason why the import failed. The string should be as informative as possible.
parse_author(text, type=None)[source]

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’.

parse_song_book_name_and_number(book_and_number)[source]

Build the book name and song number from a single string

process_song_text(text)[source]

Process the song text from import

Parameters:text – Some text
process_verse_text(text)[source]

Process the song verse text from import

Parameters:text – Some text
register(import_wizard)[source]
repeat_verse(verse_def=None)[source]

Repeat the verse with the given verse_def or default to repeating the previous verse in the verse order

Parameters:verse_def – verse_def of the verse to be repeated
set_defaults()[source]

Create defaults for properties - call this before each song if importing many songs at once to ensure a clean beginning

stop_import()[source]

Sets the flag for importers to stop their import

tidy_text(text)[source]

Get rid of some dodgy unicode and formatting characters we’re not interested in. Some can be converted to ascii.