fixes #1160 - XBMCmetadata\BaseNfoParser - trim imdb url in .nfos without trailing slash

This commit is contained in:
Luke Pulverenti 2015-08-31 00:09:39 -04:00
parent 8a1946235e
commit 2811e5c317

View file

@ -1,8 +1,8 @@
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.XbmcMetadata.Configuration; using MediaBrowser.XbmcMetadata.Configuration;
using MediaBrowser.XbmcMetadata.Savers; using MediaBrowser.XbmcMetadata.Savers;
@ -12,6 +12,7 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Xml; using System.Xml;
@ -117,7 +118,15 @@ namespace MediaBrowser.XbmcMetadata.Parsers
var xml = streamReader.ReadToEnd(); var xml = streamReader.ReadToEnd();
var index = xml.LastIndexOf('>'); // Find last closing Tag
// Need to do this in two steps to account for random > characters after the closing xml
var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
// If closing tag exists, move to end of Tag
if (index != -1)
{
index = xml.IndexOf('>', index);
}
if (index != -1) if (index != -1)
{ {
@ -149,35 +158,41 @@ namespace MediaBrowser.XbmcMetadata.Parsers
ms.Write(bytes, 0, bytes.Length); ms.Write(bytes, 0, bytes.Length);
ms.Position = 0; ms.Position = 0;
// Use XmlReader for best performance // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
using (var reader = XmlReader.Create(ms, settings)) try
{ {
reader.MoveToContent(); // Use XmlReader for best performance
using (var reader = XmlReader.Create(ms, settings))
// Loop through each element
while (reader.Read())
{ {
cancellationToken.ThrowIfCancellationRequested(); reader.MoveToContent();
if (reader.NodeType == XmlNodeType.Element) // Loop through each element
while (reader.Read())
{ {
FetchDataFromXmlNode(reader, item); cancellationToken.ThrowIfCancellationRequested();
if (reader.NodeType == XmlNodeType.Element)
{
FetchDataFromXmlNode(reader, item);
}
} }
} }
} }
catch (XmlException)
{
}
} }
} }
} }
private void ParseProviderLinks(T item, string xml) private void ParseProviderLinks(T item, string xml)
{ {
var imdbId = xml.Split('/') //Look for a match for the Regex pattern "tt" followed by 7 digits
.FirstOrDefault(i => i.StartsWith("tt", StringComparison.OrdinalIgnoreCase)); Match m = Regex.Match(xml, @"tt([0-9]{7})", RegexOptions.IgnoreCase);
if (m.Success)
if (!string.IsNullOrWhiteSpace(imdbId))
{ {
item.SetProviderId(MetadataProviders.Imdb, imdbId); item.SetProviderId(MetadataProviders.Imdb, m.Value);
} }
// TODO: Support Tmdb // TODO: Support Tmdb