forked from openlp/openlp
started work on OpenLyrics importer
This commit is contained in:
parent
7e5d6d4af1
commit
cfb896e3b1
@ -73,12 +73,12 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard):
|
||||
QtCore.QObject.connect(self.openLP1BrowseButton,
|
||||
QtCore.SIGNAL(u'clicked()'),
|
||||
self.onOpenLP1BrowseButtonClicked)
|
||||
#QtCore.QObject.connect(self.openLyricsAddButton,
|
||||
# QtCore.SIGNAL(u'clicked()'),
|
||||
# self.onOpenLyricsAddButtonClicked)
|
||||
#QtCore.QObject.connect(self.openLyricsRemoveButton,
|
||||
# QtCore.SIGNAL(u'clicked()'),
|
||||
# self.onOpenLyricsRemoveButtonClicked)
|
||||
QtCore.QObject.connect(self.openLyricsAddButton,
|
||||
QtCore.SIGNAL(u'clicked()'),
|
||||
self.onOpenLyricsAddButtonClicked)
|
||||
QtCore.QObject.connect(self.openLyricsRemoveButton,
|
||||
QtCore.SIGNAL(u'clicked()'),
|
||||
self.onOpenLyricsRemoveButtonClicked)
|
||||
QtCore.QObject.connect(self.openSongAddButton,
|
||||
QtCore.SIGNAL(u'clicked()'),
|
||||
self.onOpenSongAddButtonClicked)
|
||||
@ -167,15 +167,14 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard):
|
||||
self.openLP1BrowseButton.setFocus()
|
||||
return False
|
||||
elif source_format == SongFormat.OpenLyrics:
|
||||
# if self.openLyricsFileListWidget.count() == 0:
|
||||
# QtGui.QMessageBox.critical(self,
|
||||
# translate('SongsPlugin.ImportWizardForm',
|
||||
# 'No OpenLyrics Files Selected'),
|
||||
# translate('SongsPlugin.ImportWizardForm',
|
||||
# 'You need to add at least one OpenLyrics '
|
||||
# 'song file to import from.'))
|
||||
# self.openLyricsAddButton.setFocus()
|
||||
# return False
|
||||
if self.openLyricsFileListWidget.count() == 0:
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('SongsPlugin.ImportWizardForm',
|
||||
'No OpenLyrics Files Selected'),
|
||||
translate('SongsPlugin.ImportWizardForm',
|
||||
'You need to add at least one OpenLyrics '
|
||||
'song file to import from.'))
|
||||
self.openLyricsAddButton.setFocus()
|
||||
return False
|
||||
elif source_format == SongFormat.OpenSong:
|
||||
if self.openSongFileListWidget.count() == 0:
|
||||
@ -337,15 +336,15 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard):
|
||||
'openlp.org v1.x Databases')
|
||||
)
|
||||
|
||||
#def onOpenLyricsAddButtonClicked(self):
|
||||
# self.getFiles(
|
||||
# translate('SongsPlugin.ImportWizardForm',
|
||||
# 'Select OpenLyrics Files'),
|
||||
# self.openLyricsFileListWidget
|
||||
# )
|
||||
def onOpenLyricsAddButtonClicked(self):
|
||||
self.getFiles(
|
||||
translate('SongsPlugin.ImportWizardForm',
|
||||
'Select OpenLyrics Files'),
|
||||
self.openLyricsFileListWidget
|
||||
)
|
||||
|
||||
#def onOpenLyricsRemoveButtonClicked(self):
|
||||
# self.removeSelectedItems(self.openLyricsFileListWidget)
|
||||
def onOpenLyricsRemoveButtonClicked(self):
|
||||
self.removeSelectedItems(self.openLyricsFileListWidget)
|
||||
|
||||
def onOpenSongAddButtonClicked(self):
|
||||
self.getFiles(
|
||||
@ -435,7 +434,7 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard):
|
||||
self.formatComboBox.setCurrentIndex(0)
|
||||
self.openLP2FilenameEdit.setText(u'')
|
||||
self.openLP1FilenameEdit.setText(u'')
|
||||
#self.openLyricsFileListWidget.clear()
|
||||
self.openLyricsFileListWidget.clear()
|
||||
self.openSongFileListWidget.clear()
|
||||
self.wordsOfWorshipFileListWidget.clear()
|
||||
self.ccliFileListWidget.clear()
|
||||
|
@ -81,9 +81,6 @@ class Ui_SongImportWizard(object):
|
||||
self.addSingleFileSelectItem(u'openLP1', None, True)
|
||||
# OpenLyrics
|
||||
self.addMultiFileSelectItem(u'openLyrics', u'OpenLyrics', True)
|
||||
# set OpenLyrics to disabled by default
|
||||
self.openLyricsDisabledWidget.setVisible(True)
|
||||
self.openLyricsImportWidget.setVisible(False)
|
||||
# Open Song
|
||||
self.addMultiFileSelectItem(u'openSong', u'OpenSong')
|
||||
# Words of Worship
|
||||
@ -177,10 +174,10 @@ class Ui_SongImportWizard(object):
|
||||
'importer has been disabled due to a missing Python module. If '
|
||||
'you want to use this importer, you will need to install the '
|
||||
'"python-sqlite" module.'))
|
||||
#self.openLyricsAddButton.setText(
|
||||
# translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
|
||||
#self.openLyricsRemoveButton.setText(
|
||||
# translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
|
||||
self.openLyricsAddButton.setText(
|
||||
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
|
||||
self.openLyricsRemoveButton.setText(
|
||||
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
|
||||
self.openLyricsDisabledLabel.setText(
|
||||
translate('SongsPlugin.ImportWizardForm', 'The OpenLyrics '
|
||||
'importer has not yet been developed, but as you can see, we are '
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
from opensongimport import OpenSongImport
|
||||
from olpimport import OpenLPSongImport
|
||||
from openlyricsimport import OpenLyricsImport
|
||||
from wowimport import WowImport
|
||||
from cclifileimport import CCLIFileImport
|
||||
from ewimport import EasyWorshipSongImport
|
||||
@ -77,8 +78,10 @@ class SongFormat(object):
|
||||
"""
|
||||
if format == SongFormat.OpenLP2:
|
||||
return OpenLPSongImport
|
||||
if format == SongFormat.OpenLP1:
|
||||
elif format == SongFormat.OpenLP1:
|
||||
return OpenLP1SongImport
|
||||
elif format == SongFormat.OpenLyrics:
|
||||
return OpenLyricsImport
|
||||
elif format == SongFormat.OpenSong:
|
||||
return OpenSongImport
|
||||
elif format == SongFormat.SongsOfFellowship:
|
||||
@ -93,7 +96,6 @@ class SongFormat(object):
|
||||
return EasyWorshipSongImport
|
||||
elif format == SongFormat.SongBeamer:
|
||||
return SongBeamerImport
|
||||
# else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
|
@ -194,9 +194,7 @@ class LyricsXML(object):
|
||||
text = text.replace('\r\n', '\n')
|
||||
verses = text.split('\n\n')
|
||||
self.languages = [{u'language': u'en', u'verses': []}]
|
||||
counter = 0
|
||||
for verse in verses:
|
||||
counter = counter + 1
|
||||
for counter, verse in enumerate(verses):
|
||||
self.languages[0][u'verses'].append({
|
||||
u'type': u'verse',
|
||||
u'label': unicode(counter),
|
||||
@ -245,14 +243,16 @@ class LyricsXML(object):
|
||||
|
||||
class OpenLyricsParser(object):
|
||||
"""
|
||||
This class represents the converter for Song to/from OpenLyrics XML.
|
||||
This class represents the converter for Song to/from
|
||||
`OpenLyrics <http://openlyrics.info/>`_ XML.
|
||||
"""
|
||||
# TODO: complete OpenLyrics standard implementation!
|
||||
def __init__(self, manager):
|
||||
self.manager = manager
|
||||
|
||||
def song_to_xml(self, song):
|
||||
"""
|
||||
Convert the song to OpenLyrics Format
|
||||
Convert the song to OpenLyrics Format.
|
||||
"""
|
||||
song_xml_parser = SongXMLParser(song.lyrics)
|
||||
verse_list = song_xml_parser.get_verses()
|
||||
@ -286,7 +286,7 @@ class OpenLyricsParser(object):
|
||||
|
||||
def xml_to_song(self, xml):
|
||||
"""
|
||||
Create a Song from OpenLyrics format xml
|
||||
Create and save a Song from OpenLyrics format xml.
|
||||
"""
|
||||
# No xml get out of here
|
||||
if not xml:
|
||||
@ -299,23 +299,15 @@ class OpenLyricsParser(object):
|
||||
song.copyright = unicode(properties.copyright.text)
|
||||
if song.copyright == u'None':
|
||||
song.copyright = u''
|
||||
song.verse_order = unicode(properties.verseOrder.text)
|
||||
if song.verse_order == u'None':
|
||||
song.verse_order = u''
|
||||
song.topics = []
|
||||
song.book = None
|
||||
theme_name = None
|
||||
try:
|
||||
song.ccli_number = unicode(properties.ccliNo.text)
|
||||
except:
|
||||
except AttributeError:
|
||||
song.ccli_number = u''
|
||||
try:
|
||||
theme_name = unicode(properties.themes.theme)
|
||||
except:
|
||||
pass
|
||||
if theme_name:
|
||||
song.theme_name = theme_name
|
||||
else:
|
||||
song.theme_name = unicode(properties.themes.theme)
|
||||
except AttributeError:
|
||||
song.theme_name = u''
|
||||
# Process Titles
|
||||
for title in properties.titles.title:
|
||||
@ -331,6 +323,7 @@ class OpenLyricsParser(object):
|
||||
# Process Lyrics
|
||||
sxml = SongXMLBuilder()
|
||||
search_text = u''
|
||||
song.verse_order = u''
|
||||
for lyrics in song_xml.lyrics:
|
||||
for verse in song_xml.lyrics.verse:
|
||||
text = u''
|
||||
@ -341,17 +334,36 @@ class OpenLyricsParser(object):
|
||||
else:
|
||||
text += u'\n' + line
|
||||
type = VerseType.expand_string(verse.attrib[u'name'][0])
|
||||
# Here we need to create the verse order for the case that the
|
||||
# song does not have a verseOrder property.
|
||||
sxml.add_verse_to_lyrics(type, verse.attrib[u'name'][1], text)
|
||||
search_text = search_text + text
|
||||
song.search_lyrics = search_text.lower()
|
||||
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||
try:
|
||||
song.verse_order = unicode(properties.verseOrder.text)
|
||||
except AttributeError:
|
||||
# TODO: Do not allow empty verse order.
|
||||
# Do not worry!
|
||||
pass
|
||||
if song.verse_order == u'None':
|
||||
song.verse_order = u''
|
||||
# Process Comments
|
||||
song.comments = u''
|
||||
try:
|
||||
for comment in properties.comments.comment:
|
||||
if not song.comments:
|
||||
song.comments = comment
|
||||
else:
|
||||
song.comments += u'\n' + comment
|
||||
except AttributeError:
|
||||
pass
|
||||
song.song_number = u''
|
||||
# Process Authors
|
||||
try:
|
||||
for author in properties.authors.author:
|
||||
self._process_author(author.text, song)
|
||||
except:
|
||||
except AttributeError:
|
||||
# No Author in XML so ignore
|
||||
pass
|
||||
self.manager.save_object(song)
|
||||
|
Loading…
Reference in New Issue
Block a user