| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Xml; |
| | 3 | | using MediaBrowser.Controller.Entities; |
| | 4 | | using MediaBrowser.Controller.Entities.Movies; |
| | 5 | | using MediaBrowser.Controller.Providers; |
| | 6 | | using Microsoft.Extensions.Logging; |
| | 7 | |
|
| | 8 | | namespace MediaBrowser.LocalMetadata.Parsers |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// The box set xml parser. |
| | 12 | | /// </summary> |
| | 13 | | public class BoxSetXmlParser : BaseItemXmlParser<BoxSet> |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Initializes a new instance of the <see cref="BoxSetXmlParser"/> class. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="logger">Instance of the <see cref="ILogger{BoxSetXmlParser}"/> interface.</param> |
| | 19 | | /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param> |
| | 20 | | public BoxSetXmlParser(ILogger<BoxSetXmlParser> logger, IProviderManager providerManager) |
| 0 | 21 | | : base(logger, providerManager) |
| | 22 | | { |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | /// <inheritdoc /> |
| | 26 | | protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<BoxSet> itemResult) |
| | 27 | | { |
| 0 | 28 | | switch (reader.Name) |
| | 29 | | { |
| | 30 | | case "CollectionItems": |
| | 31 | |
|
| 0 | 32 | | if (!reader.IsEmptyElement) |
| | 33 | | { |
| 0 | 34 | | using (var subReader = reader.ReadSubtree()) |
| | 35 | | { |
| 0 | 36 | | FetchFromCollectionItemsNode(subReader, itemResult); |
| 0 | 37 | | } |
| | 38 | | } |
| | 39 | | else |
| | 40 | | { |
| 0 | 41 | | reader.Read(); |
| | 42 | | } |
| | 43 | |
|
| 0 | 44 | | break; |
| | 45 | |
|
| | 46 | | default: |
| 0 | 47 | | base.FetchDataFromXmlNode(reader, itemResult); |
| | 48 | | break; |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | private void FetchFromCollectionItemsNode(XmlReader reader, MetadataResult<BoxSet> item) |
| | 53 | | { |
| 0 | 54 | | var list = new List<LinkedChild>(); |
| | 55 | |
|
| 0 | 56 | | reader.MoveToContent(); |
| 0 | 57 | | reader.Read(); |
| | 58 | |
|
| | 59 | | // Loop through each element |
| 0 | 60 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 61 | | { |
| 0 | 62 | | if (reader.NodeType == XmlNodeType.Element) |
| | 63 | | { |
| 0 | 64 | | switch (reader.Name) |
| | 65 | | { |
| | 66 | | case "CollectionItem": |
| | 67 | | { |
| 0 | 68 | | if (!reader.IsEmptyElement) |
| | 69 | | { |
| 0 | 70 | | using (var subReader = reader.ReadSubtree()) |
| | 71 | | { |
| 0 | 72 | | var child = GetLinkedChild(subReader); |
| | 73 | |
|
| 0 | 74 | | if (child is not null) |
| | 75 | | { |
| 0 | 76 | | list.Add(child); |
| | 77 | | } |
| 0 | 78 | | } |
| | 79 | | } |
| | 80 | | else |
| | 81 | | { |
| 0 | 82 | | reader.Read(); |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | break; |
| | 86 | | } |
| | 87 | |
|
| | 88 | | default: |
| | 89 | | { |
| 0 | 90 | | reader.Skip(); |
| 0 | 91 | | break; |
| | 92 | | } |
| | 93 | | } |
| | 94 | | } |
| | 95 | | else |
| | 96 | | { |
| 0 | 97 | | reader.Read(); |
| | 98 | | } |
| | 99 | | } |
| | 100 | |
|
| 0 | 101 | | item.Item.LinkedChildren = list.ToArray(); |
| 0 | 102 | | } |
| | 103 | | } |
| | 104 | | } |