Well, yes it is intentional to escape the didl content because it is an XML document inside an XML document. It would be an invalid xml document, if you have a second header line (<xml version...>). Have you ever tried other UPnP or DLNA servers than this one?
You may switch it off by simply commenting out the following line:
I try to find the bug with the trailing ~. I hope it is a minor bug.
I am currently adding your patches. Thank you very much.