瀏覽代碼

Get IndexNumberEnd from nfo

Balázs Váradi 4 年之前
父節點
當前提交
b646787ab6
共有 1 個文件被更改,包括 38 次插入3 次删除
  1. 38 3
      MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs

+ 38 - 3
MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs

@@ -35,14 +35,17 @@ namespace MediaBrowser.XbmcMetadata.Parsers
             {
             {
                 item.ResetPeople();
                 item.ResetPeople();
 
 
-                var xml = streamReader.ReadToEnd();
+                var xmlFile = streamReader.ReadToEnd();
 
 
                 var srch = "</episodedetails>";
                 var srch = "</episodedetails>";
-                var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
+                var index = xmlFile.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
+
+                var xml = xmlFile;
 
 
                 if (index != -1)
                 if (index != -1)
                 {
                 {
-                    xml = xml.Substring(0, index + srch.Length);
+                    xml = xmlFile.Substring(0, index + srch.Length);
+                    xmlFile = xmlFile.Substring(index + srch.Length);
                 }
                 }
 
 
                 // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
                 // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
@@ -73,6 +76,38 @@ namespace MediaBrowser.XbmcMetadata.Parsers
                 catch (XmlException)
                 catch (XmlException)
                 {
                 {
                 }
                 }
+
+                while ((index = xmlFile.IndexOf(srch, StringComparison.OrdinalIgnoreCase)) != -1)
+                {
+                    xml = xmlFile.Substring(0, index + srch.Length);
+                    xmlFile = xmlFile.Substring(index + srch.Length);
+
+                    // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
+                    try
+                    {
+                        using (var stringReader = new StringReader(xml))
+                        using (var reader = XmlReader.Create(stringReader, settings))
+                        {
+                            reader.MoveToContent();
+
+                            if (reader.ReadToDescendant("episode"))
+                            {
+                                var number = reader.ReadElementContentAsString();
+
+                                if (!string.IsNullOrWhiteSpace(number))
+                                {
+                                    if (int.TryParse(number, out var num))
+                                    {
+                                        item.Item.IndexNumberEnd = Math.Max(num, item.Item.IndexNumberEnd ?? num);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    catch (XmlException)
+                    {
+                    }
+                }
             }
             }
         }
         }