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


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.

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

  • song_id
  • filename – The file to copy.

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.

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


Build the book name and song number from a single string


Process the song text from import

Parameters:text – Some text

Process the song verse text from import

Parameters:text – Some text

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

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


Sets the flag for importers to stop their import


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