jellyfin/MediaBrowser.Dlna/PlayTo/uParser.cs

53 lines
1.5 KiB
C#
Raw Normal View History

2014-02-26 14:31:47 -07:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace MediaBrowser.Dlna.PlayTo
{
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;
var item = (from result in document.Descendants("Result") select result).FirstOrDefault();
if (item == null)
return list;
var uPnpResponse = XElement.Parse((String)item);
var uObjects = from container in uPnpResponse.Elements(uPnpNamespaces.containers)
2014-04-22 10:25:54 -07:00
select new uParserObject { Element = container };
2014-02-26 14:31:47 -07:00
var uObjects2 = from container in uPnpResponse.Elements(uPnpNamespaces.items)
2014-04-22 10:25:54 -07:00
select new uParserObject { Element = container };
2014-02-26 14:31:47 -07:00
list.AddRange(uObjects.Concat(uObjects2).Select(CreateObjectFromXML).Where(uObject => uObject != null));
return list;
}
public static uBaseObject CreateObjectFromXML(uParserObject uItem)
{
2014-04-22 10:25:54 -07:00
return UpnpContainer.Create(uItem.Element);
2014-02-26 14:31:47 -07:00
}
}
public class uParserObject
{
public XElement Element { get; set; }
}
}