This commit is contained in:
Bond-009 2020-01-28 13:19:25 +01:00
parent 6b68521bae
commit 36d62c3093

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
@ -253,21 +254,31 @@ namespace Emby.Dlna.ContentDirectory
start = startVal;
}
xmlWriter.WriteStartElement("Result");
int totalCount;
xmlWriter.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
var settings = new XmlWriterSettings()
{
Encoding = Encoding.UTF8,
CloseOutput = false,
OmitXmlDeclaration = true,
ConformanceLevel = ConformanceLevel.Fragment
};
xmlWriter.WriteAttributeString("xmlns", "dc", null, NS_DC);
xmlWriter.WriteAttributeString("xmlns", "dlna", null, NS_DLNA);
xmlWriter.WriteAttributeString("xmlns", "upnp", null, NS_UPNP);
//didl.SetAttribute("xmlns:sec", NS_SEC);
using (StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8))
using (var writer = XmlWriter.Create(builder, settings))
{
writer.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
DidlBuilder.WriteXmlRootAttributes(_profile, xmlWriter);
writer.WriteAttributeString("xmlns", "dc", null, NS_DC);
writer.WriteAttributeString("xmlns", "dlna", null, NS_DLNA);
writer.WriteAttributeString("xmlns", "upnp", null, NS_UPNP);
DidlBuilder.WriteXmlRootAttributes(_profile, writer);
var serverItem = GetItemFromObjectId(id, _user);
var item = serverItem.Item;
int totalCount;
if (string.Equals(flag, "BrowseMetadata", StringComparison.Ordinal))
{
totalCount = 1;
@ -276,12 +287,12 @@ namespace Emby.Dlna.ContentDirectory
{
var childrenResult = GetUserItems(item, serverItem.StubType, _user, sortCriteria, start, requestedCount);
_didlBuilder.WriteFolderElement(xmlWriter, item, serverItem.StubType, null, childrenResult.TotalRecordCount, filter, id);
_didlBuilder.WriteFolderElement(writer, item, serverItem.StubType, null, childrenResult.TotalRecordCount, filter, id);
}
else
{
var dlnaOptions = _config.GetDlnaConfiguration();
_didlBuilder.WriteItemElement(dlnaOptions, xmlWriter, item, _user, null, null, deviceId, filter);
_didlBuilder.WriteItemElement(dlnaOptions, writer, item, _user, null, null, deviceId, filter);
}
provided++;
@ -304,17 +315,19 @@ namespace Emby.Dlna.ContentDirectory
var childCount = GetUserItems(childItem, displayStubType, _user, sortCriteria, null, 0)
.TotalRecordCount;
_didlBuilder.WriteFolderElement(xmlWriter, childItem, displayStubType, item, childCount, filter);
_didlBuilder.WriteFolderElement(writer, childItem, displayStubType, item, childCount, filter);
}
else
{
_didlBuilder.WriteItemElement(dlnaOptions, xmlWriter, childItem, _user, item, serverItem.StubType, deviceId, filter);
_didlBuilder.WriteItemElement(dlnaOptions, writer, childItem, _user, item, serverItem.StubType, deviceId, filter);
}
}
}
xmlWriter.WriteFullEndElement();
xmlWriter.WriteFullEndElement();
writer.WriteFullEndElement();
xmlWriter.WriteElementString("Result", builder.ToString());
}
xmlWriter.WriteElementString("NumberReturned", provided.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteElementString("TotalMatches", totalCount.ToString(CultureInfo.InvariantCulture));
@ -350,22 +363,32 @@ namespace Emby.Dlna.ContentDirectory
start = startVal;
}
xmlWriter.WriteStartElement("Result");
QueryResult<BaseItem> childrenResult;
xmlWriter.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
var settings = new XmlWriterSettings()
{
Encoding = Encoding.UTF8,
CloseOutput = false,
OmitXmlDeclaration = true,
ConformanceLevel = ConformanceLevel.Fragment
};
xmlWriter.WriteAttributeString("xmlns", "dc", null, NS_DC);
xmlWriter.WriteAttributeString("xmlns", "dlna", null, NS_DLNA);
xmlWriter.WriteAttributeString("xmlns", "upnp", null, NS_UPNP);
//didl.SetAttribute("xmlns:sec", NS_SEC);
using (StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8))
using (var writer = XmlWriter.Create(builder, settings))
{
writer.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
DidlBuilder.WriteXmlRootAttributes(_profile, xmlWriter);
writer.WriteAttributeString("xmlns", "dc", null, NS_DC);
writer.WriteAttributeString("xmlns", "dlna", null, NS_DLNA);
writer.WriteAttributeString("xmlns", "upnp", null, NS_UPNP);
DidlBuilder.WriteXmlRootAttributes(_profile, writer);
var serverItem = GetItemFromObjectId(sparams["ContainerID"], _user);
var item = serverItem.Item;
var childrenResult = GetChildrenSorted(item, _user, searchCriteria, sortCriteria, start, requestedCount);
childrenResult = GetChildrenSorted(item, _user, searchCriteria, sortCriteria, start, requestedCount);
var dlnaOptions = _config.GetDlnaConfiguration();
@ -376,16 +399,18 @@ namespace Emby.Dlna.ContentDirectory
var childCount = GetChildrenSorted(i, _user, searchCriteria, sortCriteria, null, 0)
.TotalRecordCount;
_didlBuilder.WriteFolderElement(xmlWriter, i, null, item, childCount, filter);
_didlBuilder.WriteFolderElement(writer, i, null, item, childCount, filter);
}
else
{
_didlBuilder.WriteItemElement(dlnaOptions, xmlWriter, i, _user, item, serverItem.StubType, deviceId, filter);
_didlBuilder.WriteItemElement(dlnaOptions, writer, i, _user, item, serverItem.StubType, deviceId, filter);
}
}
xmlWriter.WriteFullEndElement();
xmlWriter.WriteFullEndElement();
writer.WriteFullEndElement();
xmlWriter.WriteElementString("Result", builder.ToString());
}
xmlWriter.WriteElementString("NumberReturned", childrenResult.Items.Count.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteElementString("TotalMatches", childrenResult.TotalRecordCount.ToString(CultureInfo.InvariantCulture));