forked from openlp/openlp
Fix parsing of partly broken presentation manager files on windows.
This commit is contained in:
parent
46ee502ad6
commit
cf9c91f171
|
@ -25,6 +25,7 @@ Presentationmanager song files into the current database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import chardet
|
import chardet
|
||||||
from lxml import objectify, etree
|
from lxml import objectify, etree
|
||||||
|
|
||||||
|
@ -49,7 +50,11 @@ class PresentationManagerImport(SongImport):
|
||||||
# Try to detect encoding and use it
|
# Try to detect encoding and use it
|
||||||
file = open(file_path, mode='rb')
|
file = open(file_path, mode='rb')
|
||||||
encoding = chardet.detect(file.read())['encoding']
|
encoding = chardet.detect(file.read())['encoding']
|
||||||
tree = etree.parse(file_path, parser=etree.XMLParser(recover=True, encoding=encoding))
|
file.close()
|
||||||
|
# Open file with detected encoding and remove encoding declaration
|
||||||
|
text = open(file_path, mode='r', encoding=encoding).read()
|
||||||
|
text = re.sub('.+\?>\n', '', text)
|
||||||
|
tree = etree.fromstring(text, parser=etree.XMLParser(recover=True))
|
||||||
root = objectify.fromstring(etree.tostring(tree))
|
root = objectify.fromstring(etree.tostring(tree))
|
||||||
self.process_song(root)
|
self.process_song(root)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue