Start opensong importer

This commit is contained in:
Martin Thompson 2010-06-15 21:03:47 +01:00
parent 58f3dc1acb
commit f709c90f0a
3 changed files with 170 additions and 0 deletions

View File

@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import os
import re
# from songimport import SongImport
class opensongimport:
"""
Import songs exported from OpenSong - the format is described loosly here:
http://www.opensong.org/d/manual/song_file_format_specification
However, it doesn't describe the <lyrics> section, so here's an attempt:
Verses can be expressed in one of 2 ways:
<lyrics>
[v1]List of words
Another Line
[v2]Some words for the 2nd verse
etc...
</lyrics>
or:
<lyrics>
1List of words
2Some words for the 2nd Verse
1Another Line
2etc...
</lyrics>
Either or both forms can be used in one song.
The [v1] labels can have either upper or loewr case Vs
Other labels can be used also:
C - Chorus
B - Bridge
Guitar chords can be provided 'above' the lyrics (the line is preceeded by a'.') and _s can be used to signify long-drawn-out words:
. A7 Bm
1 Some____ Words
Chords and _s are removed by this importer.
The verses etc. are imported and tagged appropriately.
The <presentation> tag is used to populate the OpenLP verse
display order field. The Author and Copyright tags are also
imported to the appropriate places.
"""
def __init__(self, songmanager):
"""
Initialise the class. Requires a songmanager class which is passed
to SongImport for writing song to disk
"""
self.songmanager=songmanager
self.song = None
def osimport(self, filename):
"""
Process the OpenSong file
"""
self.new_song()
f=open(filename)
tree=objectify.parse(f)
root=tree.getroot()
print "Title", zroot.title
# data storage while importing
self.verses=[]
# xxx this is common with SOF
def new_song(self):
"""
A change of song. Store the old, create a new
... but only if the last song was complete. If not, stick with it
"""
if self.song:
self.finish_verse()
if not self.song.check_complete():
return
self.song.finish()
self.song = SongImport(self.manager)
self.skip_to_close_bracket = False
self.is_chorus = False
self.italics = False
self.currentverse = u''

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<song>
<title>Martins Test</title>
<author>Martin Thompson</author>
<copyright>2010 Martin Thompson</copyright>
<hymn_number>1</hymn_number>
<presentation>V1 C1 V2 C2 B1 V1</presentation>
<ccli>Blah</ccli>
<capo print="false"></capo>
<key></key>
<aka></aka>
<key_line></key_line>
<user1></user1>
<user2></user2>
<user3></user3>
<theme></theme>
<tempo></tempo>
<time_sig></time_sig>
<lyrics>;Comment
[V]
. A B C
1 v1 Line 1___
2 v2 Line 1___
. A B C7
1 V1 Line 2
2 V1 Line 2
[b1]
Bridge 1
[C1]
Chorus 1
[C2]
Chorus 2
</lyrics>
<style index="default_style">
<title enabled="true" valign="bottom" align="center" include_verse="false" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="26" bold="true" italic="true" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#000000"/>
<subtitle enabled="true" valign="bottom" align="center" descriptive="false" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="18" bold="true" italic="true" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#000000"/>
<song_subtitle>author</song_subtitle>
<body enabled="true" auto_scale="false" valign="middle" align="center" highlight_chorus="true" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="34" bold="true" italic="false" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#FF0000">
<tabs/>
</body>
<background strip_footer="0" color="#408080" position="1"/>
</style></song>

View File

@ -0,0 +1,9 @@
import openlp.plugins.songs.lib.opensongimport
def test():
o=opensongimport.opensongimport(0)# xxx needs a song manager here
o.osimport(u'test.opensong')
pass
if __name__=="__main__":
test()