From 83ad945015541aefbe2a0cd2a00ed6e0c151f72c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 3 Dec 2016 16:46:06 -0500 Subject: [PATCH 1/2] update xml readers --- Emby.Dlna/Service/BaseControlHandler.cs | 6 +- .../Library/Resolvers/BaseVideoResolver.cs | 28 ++- .../Library/Resolvers/Movies/MovieResolver.cs | 9 +- .../News/NewsEntryPoint.cs | 6 +- .../Parsers/BaseItemXmlParser.cs | 183 +++++++++--------- .../Parsers/BoxSetXmlParser.cs | 2 +- .../Parsers/PlaylistXmlParser.cs | 4 +- .../Savers/BaseXmlSaver.cs | 2 +- .../Probing/ProbeResultNormalizer.cs | 8 +- .../Music/MusicBrainzAlbumProvider.cs | 10 +- .../Music/MusicBrainzArtistProvider.cs | 6 +- .../People/TvdbPersonImageProvider.cs | 4 +- .../TV/MissingEpisodeProvider.cs | 2 +- .../TV/TheTVDB/TvdbEpisodeImageProvider.cs | 2 +- .../TV/TheTVDB/TvdbEpisodeProvider.cs | 8 +- .../TV/TheTVDB/TvdbPrescanTask.cs | 4 +- .../TV/TheTVDB/TvdbSeasonImageProvider.cs | 4 +- .../TV/TheTVDB/TvdbSeriesImageProvider.cs | 4 +- .../TV/TheTVDB/TvdbSeriesProvider.cs | 22 +-- .../Parsers/BaseNfoParser.cs | 20 +- .../Savers/BaseNfoSaver.cs | 2 +- 21 files changed, 168 insertions(+), 168 deletions(-) diff --git a/Emby.Dlna/Service/BaseControlHandler.cs b/Emby.Dlna/Service/BaseControlHandler.cs index 35203edae..8f91626d4 100644 --- a/Emby.Dlna/Service/BaseControlHandler.cs +++ b/Emby.Dlna/Service/BaseControlHandler.cs @@ -129,7 +129,7 @@ namespace Emby.Dlna.Service reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -166,7 +166,7 @@ namespace Emby.Dlna.Service reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -197,7 +197,7 @@ namespace Emby.Dlna.Service reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs index d9c3ac5ab..b337e1b9e 100644 --- a/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -4,6 +4,8 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Naming.Video; using System; using System.IO; +using System.Linq; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Logging; namespace Emby.Server.Implementations.Library.Resolvers @@ -59,7 +61,7 @@ namespace Emby.Server.Implementations.Library.Resolvers if (child.IsDirectory) { - if (IsDvdDirectory(filename)) + if (IsDvdDirectory(child.FullName, filename, args.DirectoryService)) { videoInfo = parser.ResolveDirectory(args.Path); @@ -76,7 +78,7 @@ namespace Emby.Server.Implementations.Library.Resolvers }; break; } - if (IsBluRayDirectory(filename)) + if (IsBluRayDirectory(child.FullName, filename, args.DirectoryService)) { videoInfo = parser.ResolveDirectory(args.Path); @@ -267,11 +269,14 @@ namespace Emby.Server.Implementations.Library.Resolvers /// /// Determines whether [is DVD directory] [the specified directory name]. /// - /// Name of the directory. - /// true if [is DVD directory] [the specified directory name]; otherwise, false. - protected bool IsDvdDirectory(string directoryName) + protected bool IsDvdDirectory(string fullPath, string directoryName, IDirectoryService directoryService) { - return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase); + if (!string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + return directoryService.GetFiles(fullPath).Any(i => string.Equals(i.Extension, ".vob", StringComparison.OrdinalIgnoreCase)); } /// @@ -287,11 +292,14 @@ namespace Emby.Server.Implementations.Library.Resolvers /// /// Determines whether [is blu ray directory] [the specified directory name]. /// - /// Name of the directory. - /// true if [is blu ray directory] [the specified directory name]; otherwise, false. - protected bool IsBluRayDirectory(string directoryName) + protected bool IsBluRayDirectory(string fullPath, string directoryName, IDirectoryService directoryService) { - return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase); + if (!string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + return directoryService.GetFiles(fullPath).Any(i => string.Equals(i.Extension, ".m2ts", StringComparison.OrdinalIgnoreCase)); } } } diff --git a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 002505b56..55a63b4e5 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -366,7 +366,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies if (child.IsDirectory) { - if (IsDvdDirectory(filename)) + if (IsDvdDirectory(child.FullName, filename, directoryService)) { var movie = new T { @@ -376,7 +376,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies Set3DFormat(movie); return movie; } - if (IsBluRayDirectory(filename)) + if (IsBluRayDirectory(child.FullName, filename, directoryService)) { var movie = new T { @@ -446,15 +446,14 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies var subfolders = subFileEntries .Where(e => e.IsDirectory) - .Select(d => d.Name) .ToList(); - if (subfolders.Any(IsDvdDirectory)) + if (subfolders.Any(s => IsDvdDirectory(s.FullName, s.Name, directoryService))) { videoTypes.Add(VideoType.Dvd); return true; } - if (subfolders.Any(IsBluRayDirectory)) + if (subfolders.Any(s => IsBluRayDirectory(s.FullName, s.Name, directoryService))) { videoTypes.Add(VideoType.BluRay); return true; diff --git a/Emby.Server.Implementations/News/NewsEntryPoint.cs b/Emby.Server.Implementations/News/NewsEntryPoint.cs index 1497d066f..51016f288 100644 --- a/Emby.Server.Implementations/News/NewsEntryPoint.cs +++ b/Emby.Server.Implementations/News/NewsEntryPoint.cs @@ -126,7 +126,7 @@ namespace Emby.Server.Implementations.News reader.MoveToContent(); reader.Read(); - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -162,7 +162,7 @@ namespace Emby.Server.Implementations.News reader.MoveToContent(); reader.Read(); - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -199,7 +199,7 @@ namespace Emby.Server.Implementations.News reader.MoveToContent(); reader.Read(); - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs index 31b13056c..43a078316 100644 --- a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs @@ -110,9 +110,10 @@ namespace MediaBrowser.LocalMetadata.Parsers using (var reader = XmlReader.Create(streamReader, settings)) { reader.MoveToContent(); + reader.Read(); // Loop through each element - while (reader.Read()) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -120,6 +121,10 @@ namespace MediaBrowser.LocalMetadata.Parsers { FetchDataFromXmlNode(reader, item); } + else + { + reader.Read(); + } } } } @@ -752,12 +757,12 @@ namespace MediaBrowser.LocalMetadata.Parsers case "Format3D": { + var val = reader.ReadElementContentAsString(); + var video = item as Video; if (video != null) { - var val = reader.ReadElementContentAsString(); - if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase)) { video.Video3DFormat = Video3DFormat.HalfSideBySide; @@ -808,8 +813,10 @@ namespace MediaBrowser.LocalMetadata.Parsers private void FetchFromSharesNode(XmlReader reader, IHasShares item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -833,6 +840,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } @@ -841,8 +852,10 @@ namespace MediaBrowser.LocalMetadata.Parsers var share = new Share(); reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -865,6 +878,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } return share; @@ -873,8 +890,10 @@ namespace MediaBrowser.LocalMetadata.Parsers private void FetchFromCountriesNode(XmlReader reader, T item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -895,6 +914,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } @@ -909,7 +932,7 @@ namespace MediaBrowser.LocalMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -945,8 +968,10 @@ namespace MediaBrowser.LocalMetadata.Parsers private void FetchFromGenresNode(XmlReader reader, T item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -968,14 +993,20 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } private void FetchFromTagsNode(XmlReader reader, BaseItem item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -997,14 +1028,20 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } private void FetchFromKeywordsNode(XmlReader reader, BaseItem item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1026,6 +1063,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } @@ -1037,8 +1078,10 @@ namespace MediaBrowser.LocalMetadata.Parsers private void FetchDataFromPersonsNode(XmlReader reader, MetadataResult item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1066,14 +1109,20 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } private void FetchDataFromTrailersNode(XmlReader reader, IHasTrailers item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1095,87 +1144,11 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } - } - } - - protected List FetchChaptersFromXmlNode(BaseItem item, XmlReader reader) - { - using (reader) - { - return GetChaptersFromXmlNode(reader) - .Where(i => i.StartPositionTicks >= 0) - .ToList(); - } - } - - private IEnumerable GetChaptersFromXmlNode(XmlReader reader) - { - var chapters = new List(); - - reader.MoveToContent(); - - while (reader.Read()) - { - if (reader.NodeType == XmlNodeType.Element) + else { - switch (reader.Name) - { - case "Chapter": - { - using (var subtree = reader.ReadSubtree()) - { - chapters.Add(GetChapterInfoFromXmlNode(subtree)); - } - break; - } - - default: - reader.Skip(); - break; - } + reader.Read(); } } - - return chapters; - } - - private ChapterInfo GetChapterInfoFromXmlNode(XmlReader reader) - { - var chapter = new ChapterInfo(); - - reader.MoveToContent(); - - while (reader.Read()) - { - if (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "StartPositionMs": - { - var val = reader.ReadElementContentAsString(); - - var ms = long.Parse(val, _usCulture); - - chapter.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks; - - break; - } - - case "Name": - { - chapter.Name = reader.ReadElementContentAsString(); - break; - } - - default: - reader.Skip(); - break; - } - } - } - - return chapter; } /// @@ -1186,8 +1159,10 @@ namespace MediaBrowser.LocalMetadata.Parsers private void FetchFromStudiosNode(XmlReader reader, T item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1209,6 +1184,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } } @@ -1225,8 +1204,10 @@ namespace MediaBrowser.LocalMetadata.Parsers int? sortOrder = null; reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1277,6 +1258,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } var personInfo = new PersonInfo @@ -1292,14 +1277,16 @@ namespace MediaBrowser.LocalMetadata.Parsers protected LinkedChild GetLinkedChild(XmlReader reader) { - reader.MoveToContent(); - var linkedItem = new LinkedChild { Type = LinkedChildType.Manual }; - while (reader.Read()) + reader.MoveToContent(); + reader.Read(); + + // Loop through each element + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1316,6 +1303,10 @@ namespace MediaBrowser.LocalMetadata.Parsers break; } } + else + { + reader.Read(); + } } // This is valid @@ -1335,7 +1326,7 @@ namespace MediaBrowser.LocalMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs index c42b44f9e..9dcfa2f76 100644 --- a/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.LocalMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs index ee986ae2d..d4334bf62 100644 --- a/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs @@ -71,7 +71,7 @@ namespace MediaBrowser.LocalMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -115,7 +115,7 @@ namespace MediaBrowser.LocalMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs index 02c34320b..b52bae2ce 100644 --- a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs @@ -724,7 +724,7 @@ namespace MediaBrowser.LocalMetadata.Savers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 9804bc1db..2b3479b76 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -211,7 +211,7 @@ namespace MediaBrowser.MediaEncoding.Probing reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -253,7 +253,7 @@ namespace MediaBrowser.MediaEncoding.Probing reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -308,7 +308,7 @@ namespace MediaBrowser.MediaEncoding.Probing reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -397,7 +397,7 @@ namespace MediaBrowser.MediaEncoding.Probing reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index db5a1b18c..36371e301 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -266,7 +266,7 @@ namespace MediaBrowser.Providers.Music reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -303,7 +303,7 @@ namespace MediaBrowser.Providers.Music reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -352,7 +352,7 @@ namespace MediaBrowser.Providers.Music // http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -427,7 +427,7 @@ namespace MediaBrowser.Providers.Music reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -464,7 +464,7 @@ namespace MediaBrowser.Providers.Music reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs index 031207c33..c50de1065 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs @@ -89,7 +89,7 @@ namespace MediaBrowser.Providers.Music reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -128,7 +128,7 @@ namespace MediaBrowser.Providers.Music reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -174,7 +174,7 @@ namespace MediaBrowser.Providers.Music // http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs index 9335fca9f..dc24e3484 100644 --- a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs @@ -117,7 +117,7 @@ namespace MediaBrowser.Providers.People reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -170,7 +170,7 @@ namespace MediaBrowser.Providers.People reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index 873834bf6..05ca7c7d9 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -524,7 +524,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs index 5bbcc9d15..791f56beb 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs @@ -86,7 +86,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index ecc0f6cee..99136cd85 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -343,7 +343,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -398,7 +398,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -452,7 +452,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -825,7 +825,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs index ab40cdff5..8488c5669 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs @@ -198,7 +198,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -274,7 +274,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs index 9454277df..9951a2519 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs @@ -129,7 +129,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -204,7 +204,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs index 5ad96300d..6d4be31ac 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs @@ -116,7 +116,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -190,7 +190,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs index 41f19a5b5..112b17f4e 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs @@ -306,7 +306,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -342,7 +342,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -549,7 +549,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -607,7 +607,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -789,7 +789,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -849,7 +849,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -934,7 +934,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -978,7 +978,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1056,7 +1056,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -1315,7 +1315,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1366,7 +1366,7 @@ namespace MediaBrowser.Providers.TV reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 548403347..4bee8c3ca 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -123,7 +123,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -203,7 +203,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { cancellationToken.ThrowIfCancellationRequested(); @@ -607,7 +607,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "director": { - foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director })) + var val = reader.ReadElementContentAsString(); + foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director })) { if (string.IsNullOrWhiteSpace(p.Name)) { @@ -640,7 +641,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "writer": { - foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer })) + var val = reader.ReadElementContentAsString(); + foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer })) { if (string.IsNullOrWhiteSpace(p.Name)) { @@ -957,7 +959,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -996,7 +998,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1029,7 +1031,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1062,7 +1064,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { @@ -1128,7 +1130,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs index 125ac5291..18936df01 100644 --- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs +++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs @@ -1066,7 +1066,7 @@ namespace MediaBrowser.XbmcMetadata.Savers reader.Read(); // Loop through each element - while (!reader.EOF) + while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { From 7ed6c67db0f28c5776d972668a438369c3b96aef Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 3 Dec 2016 18:57:34 -0500 Subject: [PATCH 2/2] update xml parsing --- Emby.Dlna/Service/BaseControlHandler.cs | 33 +++-- .../News/NewsEntryPoint.cs | 23 +++- .../Parsers/BaseItemXmlParser.cs | 117 ++++++++++++++---- .../Parsers/PlaylistXmlParser.cs | 34 ++++- .../Probing/ProbeResultNormalizer.cs | 20 ++- .../Music/MusicBrainzAlbumProvider.cs | 15 +++ .../Music/MusicBrainzArtistProvider.cs | 10 ++ .../People/TvdbPersonImageProvider.cs | 5 + .../TV/TheTVDB/TvdbSeasonImageProvider.cs | 5 + .../TV/TheTVDB/TvdbSeriesImageProvider.cs | 5 + .../TV/TheTVDB/TvdbSeriesProvider.cs | 25 ++++ .../Parsers/BaseNfoParser.cs | 53 ++++++-- 12 files changed, 293 insertions(+), 52 deletions(-) diff --git a/Emby.Dlna/Service/BaseControlHandler.cs b/Emby.Dlna/Service/BaseControlHandler.cs index 8f91626d4..4ce047172 100644 --- a/Emby.Dlna/Service/BaseControlHandler.cs +++ b/Emby.Dlna/Service/BaseControlHandler.cs @@ -16,7 +16,7 @@ namespace Emby.Dlna.Service public abstract class BaseControlHandler { private const string NS_SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/"; - + protected readonly IServerConfigurationManager Config; protected readonly ILogger Logger; protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory; @@ -109,7 +109,7 @@ namespace Emby.Dlna.Service } var xml = builder.ToString().Replace("xmlns:m=", "xmlns:u="); - + var controlResponse = new ControlResponse { Xml = xml, @@ -136,12 +136,20 @@ namespace Emby.Dlna.Service switch (reader.LocalName) { case "Body": - { - using (var subReader = reader.ReadSubtree()) { - return ParseBodyTag(subReader); + if (!reader.IsEmptyElement) + { + using (var subReader = reader.ReadSubtree()) + { + return ParseBodyTag(subReader); + } + } + else + { + reader.Read(); + } + break; } - } default: { reader.Skip(); @@ -173,11 +181,18 @@ namespace Emby.Dlna.Service result.LocalName = reader.LocalName; result.NamespaceURI = reader.NamespaceURI; - using (var subReader = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - result.Headers = ParseFirstBodyChild(subReader); + using (var subReader = reader.ReadSubtree()) + { + result.Headers = ParseFirstBodyChild(subReader); - return result; + return result; + } + } + else + { + reader.Read(); } } else diff --git a/Emby.Server.Implementations/News/NewsEntryPoint.cs b/Emby.Server.Implementations/News/NewsEntryPoint.cs index 51016f288..53c862d47 100644 --- a/Emby.Server.Implementations/News/NewsEntryPoint.cs +++ b/Emby.Server.Implementations/News/NewsEntryPoint.cs @@ -134,10 +134,18 @@ namespace Emby.Server.Implementations.News { case "channel": { - using (var subReader = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - return ParseFromChannelNode(subReader); + using (var subReader = reader.ReadSubtree()) + { + return ParseFromChannelNode(subReader); + } } + else + { + reader.Read(); + } + break; } default: { @@ -170,9 +178,16 @@ namespace Emby.Server.Implementations.News { case "item": { - using (var subReader = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - list.Add(ParseItem(subReader)); + using (var subReader = reader.ReadSubtree()) + { + list.Add(ParseItem(subReader)); + } + } + else + { + reader.Read(); } break; } diff --git a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs index 43a078316..d66cdf801 100644 --- a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs @@ -395,18 +395,32 @@ namespace MediaBrowser.LocalMetadata.Parsers case "TagLines": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromTaglinesNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromTaglinesNode(subtree, item); + } + } + else + { + reader.Read(); } break; } case "Countries": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromCountriesNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromCountriesNode(subtree, item); + } + } + else + { + reader.Read(); } break; } @@ -592,14 +606,21 @@ namespace MediaBrowser.LocalMetadata.Parsers case "Trailers": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - var hasTrailers = item as IHasTrailers; - if (hasTrailers != null) + using (var subtree = reader.ReadSubtree()) { - FetchDataFromTrailersNode(subtree, hasTrailers); + var hasTrailers = item as IHasTrailers; + if (hasTrailers != null) + { + FetchDataFromTrailersNode(subtree, hasTrailers); + } } } + else + { + reader.Read(); + } break; } @@ -699,59 +720,101 @@ namespace MediaBrowser.LocalMetadata.Parsers case "Genres": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromGenresNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromGenresNode(subtree, item); + } + } + else + { + reader.Read(); } break; } case "Tags": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromTagsNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromTagsNode(subtree, item); + } + } + else + { + reader.Read(); } break; } case "PlotKeywords": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromKeywordsNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromKeywordsNode(subtree, item); + } + } + else + { + reader.Read(); } break; } case "Persons": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchDataFromPersonsNode(subtree, itemResult); + using (var subtree = reader.ReadSubtree()) + { + FetchDataFromPersonsNode(subtree, itemResult); + } + } + else + { + reader.Read(); } break; } case "Studios": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromStudiosNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromStudiosNode(subtree, item); + } + } + else + { + reader.Read(); } break; } case "Shares": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - var hasShares = item as IHasShares; - if (hasShares != null) + using (var subtree = reader.ReadSubtree()) { - FetchFromSharesNode(subtree, hasShares); + var hasShares = item as IHasShares; + if (hasShares != null) + { + FetchFromSharesNode(subtree, hasShares); + } } } + else + { + reader.Read(); + } break; } @@ -824,6 +887,11 @@ namespace MediaBrowser.LocalMetadata.Parsers { case "Share": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { var share = GetShareFromNode(subtree); @@ -1090,6 +1158,11 @@ namespace MediaBrowser.LocalMetadata.Parsers case "Person": case "Actor": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { foreach (var person in GetPersonsFromXmlNode(subtree)) diff --git a/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs index d4334bf62..695fe2b12 100644 --- a/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs @@ -43,17 +43,31 @@ namespace MediaBrowser.LocalMetadata.Parsers case "PlaylistItems": - using (var subReader = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromCollectionItemsNode(subReader, item); + using (var subReader = reader.ReadSubtree()) + { + FetchFromCollectionItemsNode(subReader, item); + } + } + else + { + reader.Read(); } break; case "Shares": - using (var subReader = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromSharesNode(subReader, item); + using (var subReader = reader.ReadSubtree()) + { + FetchFromSharesNode(subReader, item); + } + } + else + { + reader.Read(); } break; @@ -79,6 +93,12 @@ namespace MediaBrowser.LocalMetadata.Parsers { case "PlaylistItem": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } + using (var subReader = reader.ReadSubtree()) { var child = GetLinkedChild(subReader); @@ -123,6 +143,12 @@ namespace MediaBrowser.LocalMetadata.Parsers { case "Share": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } + using (var subReader = reader.ReadSubtree()) { var child = GetShare(subReader); diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 2b3479b76..de055146a 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -218,6 +218,11 @@ namespace MediaBrowser.MediaEncoding.Probing switch (reader.Name) { case "dict": + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { ReadFromDictNode(subtree, info); @@ -279,9 +284,14 @@ namespace MediaBrowser.MediaEncoding.Probing } break; case "array": - if (!string.IsNullOrWhiteSpace(currentKey)) + if (reader.IsEmptyElement) { - using (var subtree = reader.ReadSubtree()) + reader.Read(); + continue; + } + using (var subtree = reader.ReadSubtree()) + { + if (!string.IsNullOrWhiteSpace(currentKey)) { pairs.AddRange(ReadValueArray(subtree)); } @@ -315,6 +325,12 @@ namespace MediaBrowser.MediaEncoding.Probing switch (reader.Name) { case "dict": + + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { var dict = GetNameValuePair(subtree); diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index 36371e301..ec31824db 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -274,6 +274,11 @@ namespace MediaBrowser.Providers.Music { case "release-list": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subReader = reader.ReadSubtree()) { return ParseReleaseList(subReader); @@ -311,6 +316,11 @@ namespace MediaBrowser.Providers.Music { case "release": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } var releaseId = reader.GetAttribute("id"); using (var subReader = reader.ReadSubtree()) @@ -435,6 +445,11 @@ namespace MediaBrowser.Providers.Music { case "release-group-list": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subReader = reader.ReadSubtree()) { return GetFirstReleaseGroupId(subReader); diff --git a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs index c50de1065..1a2b13e94 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs @@ -97,6 +97,11 @@ namespace MediaBrowser.Providers.Music { case "artist-list": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subReader = reader.ReadSubtree()) { return ParseArtistList(subReader); @@ -136,6 +141,11 @@ namespace MediaBrowser.Providers.Music { case "artist": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } var mbzId = reader.GetAttribute("id"); using (var subReader = reader.ReadSubtree()) diff --git a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs index dc24e3484..dd3bfb4f8 100644 --- a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs @@ -127,6 +127,11 @@ namespace MediaBrowser.Providers.People { case "Actor": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { var info = FetchImageInfoFromActorNode(personName, subtree); diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs index 9951a2519..e189c292c 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs @@ -139,6 +139,11 @@ namespace MediaBrowser.Providers.TV { case "Banner": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { AddImage(subtree, list, seasonNumber); diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs index 6d4be31ac..2595ad585 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs @@ -126,6 +126,11 @@ namespace MediaBrowser.Providers.TV { case "Banner": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { AddImage(subtree, list); diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs index 112b17f4e..cc8a90fe3 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs @@ -314,6 +314,11 @@ namespace MediaBrowser.Providers.TV { case "Series": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { return FindSeriesId(subtree); @@ -559,6 +564,11 @@ namespace MediaBrowser.Providers.TV { case "Series": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { var searchResult = GetSeriesSearchResultFromSubTree(subtree, comparableName); @@ -799,6 +809,11 @@ namespace MediaBrowser.Providers.TV { case "Series": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { FetchDataFromSeriesNode(result, subtree, cancellationToken); @@ -808,6 +823,11 @@ namespace MediaBrowser.Providers.TV case "Episode": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { var date = GetFirstAiredDateFromEpisodeNode(subtree, cancellationToken); @@ -942,6 +962,11 @@ namespace MediaBrowser.Providers.TV { case "Actor": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { FetchDataFromActorNode(result, subtree); diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 4bee8c3ca..dba6d96ac 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -655,15 +655,22 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "actor": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - var person = GetPersonFromXmlNode(subtree); - - if (!string.IsNullOrWhiteSpace(person.Name)) + using (var subtree = reader.ReadSubtree()) { - itemResult.AddPerson(person); + var person = GetPersonFromXmlNode(subtree); + + if (!string.IsNullOrWhiteSpace(person.Name)) + { + itemResult.AddPerson(person); + } } } + else + { + reader.Read(); + } break; } @@ -831,9 +838,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "fileinfo": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - FetchFromFileInfoNode(subtree, item); + using (var subtree = reader.ReadSubtree()) + { + FetchFromFileInfoNode(subtree, item); + } + } + else + { + reader.Read(); } break; } @@ -896,15 +910,22 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "resume": { - using (var subtree = reader.ReadSubtree()) + if (!reader.IsEmptyElement) { - if (!string.IsNullOrWhiteSpace(userDataUserId)) + using (var subtree = reader.ReadSubtree()) { - var userData = GetOrAdd(itemResult, userDataUserId); + if (!string.IsNullOrWhiteSpace(userDataUserId)) + { + var userData = GetOrAdd(itemResult, userDataUserId); - FetchFromResumeNode(subtree, item, userData); + FetchFromResumeNode(subtree, item, userData); + } } } + else + { + reader.Read(); + } break; } @@ -1006,6 +1027,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers { case "streamdetails": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { FetchFromStreamDetailsNode(subtree, item); @@ -1039,6 +1065,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers { case "video": { + if (reader.IsEmptyElement) + { + reader.Read(); + continue; + } using (var subtree = reader.ReadSubtree()) { FetchFromVideoNode(subtree, item);