From eefab227cc4fbb0de6d5c5ed5e193d36231cdb06 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Nov 2016 13:08:20 -0400 Subject: [PATCH 1/2] update xml parsing --- .../Parsers/BaseItemXmlParser.cs | 9 ++++- .../Savers/BaseXmlSaver.cs | 8 +++- .../Probing/ProbeResultNormalizer.cs | 39 ++++++++++++++----- .../Music/MusicBrainzAlbumProvider.cs | 5 ++- .../Music/MusicBrainzArtistProvider.cs | 2 + .../TV/TheTVDB/TvdbPrescanTask.cs | 14 ++++++- .../TV/TheTVDB/TvdbSeriesProvider.cs | 7 +++- ...MediaBrowser.Server.Implementations.csproj | 3 -- .../Savers/BaseNfoSaver.cs | 8 +++- 9 files changed, 75 insertions(+), 20 deletions(-) diff --git a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs index d78ddc8ea..0c9226cf0 100644 --- a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs @@ -906,8 +906,10 @@ namespace MediaBrowser.LocalMetadata.Parsers private void FetchFromTaglinesNode(XmlReader reader, T item) { reader.MoveToContent(); + reader.Read(); - while (reader.Read()) + // Loop through each element + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -923,12 +925,15 @@ namespace MediaBrowser.LocalMetadata.Parsers } break; } - default: reader.Skip(); break; } } + else + { + reader.Read(); + } } } diff --git a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs index 162143385..c489b5728 100644 --- a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs @@ -718,8 +718,10 @@ namespace MediaBrowser.LocalMetadata.Savers return; } + reader.Read(); + // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -734,6 +736,10 @@ namespace MediaBrowser.LocalMetadata.Savers reader.Skip(); } } + else + { + reader.Read(); + } } } } diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 8651f2758..f0c4c465d 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -200,9 +200,10 @@ namespace MediaBrowser.MediaEncoding.Probing using (var reader = XmlReader.Create(streamReader)) { reader.MoveToContent(); + reader.Read(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -219,6 +220,10 @@ namespace MediaBrowser.MediaEncoding.Probing break; } } + else + { + reader.Read(); + } } } } @@ -227,13 +232,14 @@ namespace MediaBrowser.MediaEncoding.Probing private void ReadFromDictNode(XmlReader reader, MediaInfo info) { - reader.MoveToContent(); - string currentKey = null; List pairs = new List(); + reader.MoveToContent(); + reader.Read(); + // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -272,17 +278,23 @@ namespace MediaBrowser.MediaEncoding.Probing break; } } + else + { + reader.Read(); + } } } private List ReadValueArray(XmlReader reader) { - reader.MoveToContent(); List pairs = new List(); + reader.MoveToContent(); + reader.Read(); + // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -303,6 +315,10 @@ namespace MediaBrowser.MediaEncoding.Probing break; } } + else + { + reader.Read(); + } } return pairs; @@ -360,13 +376,14 @@ namespace MediaBrowser.MediaEncoding.Probing private NameValuePair GetNameValuePair(XmlReader reader) { - reader.MoveToContent(); - string name = null; string value = null; + reader.MoveToContent(); + reader.Read(); + // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -383,6 +400,10 @@ namespace MediaBrowser.MediaEncoding.Probing break; } } + else + { + reader.Read(); + } } if (string.IsNullOrWhiteSpace(name) || diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index 844614791..13e341f95 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -265,6 +265,7 @@ namespace MediaBrowser.Providers.Music var list = new List(); reader.MoveToContent(); + reader.Read(); // Loop through each element while (!reader.EOF) @@ -302,6 +303,7 @@ namespace MediaBrowser.Providers.Music var list = new List(); reader.MoveToContent(); + reader.Read(); // Loop through each element while (!reader.EOF) @@ -348,7 +350,6 @@ namespace MediaBrowser.Providers.Music }; reader.MoveToContent(); - reader.Read(); // http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator @@ -428,6 +429,7 @@ namespace MediaBrowser.Providers.Music using (var reader = XmlReader.Create(oReader, settings)) { reader.MoveToContent(); + reader.Read(); // Loop through each element while (!reader.EOF) @@ -464,6 +466,7 @@ namespace MediaBrowser.Providers.Music private string GetFirstReleaseGroupId(XmlReader reader) { reader.MoveToContent(); + reader.Read(); // Loop through each element while (!reader.EOF) diff --git a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs index f752a85cb..031207c33 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs @@ -86,6 +86,7 @@ namespace MediaBrowser.Providers.Music using (var reader = XmlReader.Create(oReader, settings)) { reader.MoveToContent(); + reader.Read(); // Loop through each element while (!reader.EOF) @@ -124,6 +125,7 @@ namespace MediaBrowser.Providers.Music var list = new List(); reader.MoveToContent(); + reader.Read(); // Loop through each element while (!reader.EOF) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs index 7339995b9..ab40cdff5 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs @@ -195,9 +195,10 @@ namespace MediaBrowser.Providers.TV using (var reader = XmlReader.Create(streamReader, settings)) { reader.MoveToContent(); + reader.Read(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -212,6 +213,10 @@ namespace MediaBrowser.Providers.TV break; } } + else + { + reader.Read(); + } } } } @@ -266,9 +271,10 @@ namespace MediaBrowser.Providers.TV using (var reader = XmlReader.Create(streamReader, settings)) { reader.MoveToContent(); + reader.Read(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -290,6 +296,10 @@ namespace MediaBrowser.Providers.TV break; } } + else + { + reader.Read(); + } } } } diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs index 9dbc4a963..66adf6c8a 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs @@ -334,9 +334,10 @@ namespace MediaBrowser.Providers.TV private string FindSeriesId(XmlReader reader) { reader.MoveToContent(); + reader.Read(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -359,6 +360,10 @@ namespace MediaBrowser.Providers.TV break; } } + else + { + reader.Read(); + } } return null; diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index dad2998b9..15c2368e1 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -71,9 +71,6 @@ ..\ThirdParty\ServiceStack\ServiceStack.Api.Swagger.dll - - ..\ThirdParty\ServiceStack\ServiceStack.Common.dll - False ..\ThirdParty\SharpCompress\SharpCompress.dll diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs index fc5987815..168827025 100644 --- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs +++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs @@ -1057,8 +1057,10 @@ namespace MediaBrowser.XbmcMetadata.Savers return; } + reader.Read(); + // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -1073,6 +1075,10 @@ namespace MediaBrowser.XbmcMetadata.Savers reader.Skip(); } } + else + { + reader.Read(); + } } } } From 7cf0f79f85e386a4346a74046ee36f0d30c0dcdd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Nov 2016 13:08:34 -0400 Subject: [PATCH 2/2] update thumbnail sampling --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 10fb025e0..098cd14db 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -915,7 +915,7 @@ namespace MediaBrowser.MediaEncoding.Encoder var mapArg = imageStreamIndex.HasValue ? (" -map 0:v:" + imageStreamIndex.Value.ToString(CultureInfo.InvariantCulture)) : string.Empty; var enableThumbnail = !new List { "wtv" }.Contains(container ?? string.Empty, StringComparer.OrdinalIgnoreCase); - var thumbnail = enableThumbnail ? ",thumbnail=30" : string.Empty; + var thumbnail = enableThumbnail ? ",thumbnail=24" : string.Empty; // Use ffmpeg to sample 100 (we can drop this if required using thumbnail=50 for 50 frames) frames and pick the best thumbnail. Have a fall back just in case. var args = useIFrame ? string.Format("-i {0}{3} -threads 0 -v quiet -vframes 1 -vf \"{2}{4}\" -f image2 \"{1}\"", inputPath, tempExtractPath, vf, mapArg, thumbnail) :