Fix parsing of partly broken presentation manager files on windows.

This commit is contained in:
Tomas Groth 2015-01-30 21:50:36 +00:00
parent 46ee502ad6
commit cf9c91f171
2 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,7 @@ Presentationmanager song files into the current database.
"""
import os
import re
import chardet
from lxml import objectify, etree
@ -49,7 +50,11 @@ class PresentationManagerImport(SongImport):
# Try to detect encoding and use it
file = open(file_path, mode='rb')
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))
self.process_song(root)