jellyfin/Emby.Dlna/PlayTo/uParser.cs

48 lines
1.3 KiB
C#
Raw Normal View History

2016-10-29 15:22:20 -07:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
2016-10-29 15:34:54 -07:00
namespace Emby.Dlna.PlayTo
2016-10-29 15:22:20 -07:00
{
public class uParser
{
public static IList<uBaseObject> ParseBrowseXml(XDocument doc)
{
if (doc == null)
{
throw new ArgumentException("doc");
}
var list = new List<uBaseObject>();
var document = doc.Document;
if (document == null)
return list;
2019-01-07 16:27:46 -07:00
2016-10-29 15:22:20 -07:00
var item = (from result in document.Descendants("Result") select result).FirstOrDefault();
if (item == null)
return list;
var uPnpResponse = XElement.Parse((string)item);
2016-10-29 15:22:20 -07:00
var uObjects = from container in uPnpResponse.Elements(uPnpNamespaces.containers)
select new uParserObject { Element = container };
var uObjects2 = from container in uPnpResponse.Elements(uPnpNamespaces.items)
select new uParserObject { Element = container };
list.AddRange(uObjects.Concat(uObjects2).Select(CreateObjectFromXML).Where(uObject => uObject != null));
return list;
}
public static uBaseObject CreateObjectFromXML(uParserObject uItem)
{
return UpnpContainer.Create(uItem.Element);
}
}
}