| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 | 
							- using MediaBrowser.Common.Configuration;
 
- using MediaBrowser.Controller.Entities;
 
- using MediaBrowser.Controller.Providers;
 
- using MediaBrowser.Model.Entities;
 
- using MediaBrowser.Model.Extensions;
 
- using MediaBrowser.Model.Logging;
 
- using MediaBrowser.XbmcMetadata.Configuration;
 
- using MediaBrowser.XbmcMetadata.Savers;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Globalization;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Text.RegularExpressions;
 
- using System.Threading;
 
- using System.Xml;
 
- using MediaBrowser.Controller.Entities.TV;
 
- using MediaBrowser.Model.IO;
 
- using MediaBrowser.Model.Xml;
 
- namespace MediaBrowser.XbmcMetadata.Parsers
 
- {
 
-     public class BaseNfoParser<T>
 
-         where T : BaseItem
 
-     {
 
-         /// <summary>
 
-         /// The logger
 
-         /// </summary>
 
-         protected ILogger Logger { get; private set; }
 
-         protected IFileSystem FileSystem { get; private set; }
 
-         protected IProviderManager ProviderManager { get; private set; }
 
-         protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
 
-         private readonly CultureInfo _usCulture = new CultureInfo("en-US");
 
-         private readonly IConfigurationManager _config;
 
-         private Dictionary<string, string> _validProviderIds;
 
-         /// <summary>
 
-         /// Initializes a new instance of the <see cref="BaseNfoParser{T}" /> class.
 
-         /// </summary>
 
-         public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
 
-         {
 
-             Logger = logger;
 
-             _config = config;
 
-             ProviderManager = providerManager;
 
-             FileSystem = fileSystem;
 
-             XmlReaderSettingsFactory = xmlReaderSettingsFactory;
 
-         }
 
-         /// <summary>
 
-         /// Fetches metadata for an item from one xml file
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="metadataFile">The metadata file.</param>
 
-         /// <param name="cancellationToken">The cancellation token.</param>
 
-         /// <exception cref="System.ArgumentNullException">
 
-         /// </exception>
 
-         public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
 
-         {
 
-             if (item == null)
 
-             {
 
-                 throw new ArgumentNullException();
 
-             }
 
-             if (string.IsNullOrEmpty(metadataFile))
 
-             {
 
-                 throw new ArgumentNullException();
 
-             }
 
-             var settings = XmlReaderSettingsFactory.Create(false);
 
-             settings.CheckCharacters = false;
 
-             settings.IgnoreProcessingInstructions = true;
 
-             settings.IgnoreComments = true;
 
-             _validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 
-             var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
 
-             foreach (var info in idInfos)
 
-             {
 
-                 var id = info.Key + "Id";
 
-                 if (!_validProviderIds.ContainsKey(id))
 
-                 {
 
-                     _validProviderIds.Add(id, info.Key);
 
-                 }
 
-             }
 
-             //Additional Mappings
 
-             _validProviderIds.Add("collectionnumber", "TmdbCollection");
 
-             _validProviderIds.Add("tmdbcolid", "TmdbCollection");
 
-             _validProviderIds.Add("imdb_id", "Imdb");
 
-             Fetch(item, metadataFile, settings, cancellationToken);
 
-         }
 
-         protected virtual bool SupportsUrlAfterClosingXmlTag
 
-         {
 
-             get { return false; }
 
-         }
 
-         /// <summary>
 
-         /// Fetches the specified item.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="metadataFile">The metadata file.</param>
 
-         /// <param name="settings">The settings.</param>
 
-         /// <param name="cancellationToken">The cancellation token.</param>
 
-         protected virtual void Fetch(MetadataResult<T> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
 
-         {
 
-             if (!SupportsUrlAfterClosingXmlTag)
 
-             {
 
-                 using (var fileStream = FileSystem.OpenRead(metadataFile))
 
-                 {
 
-                     using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
 
-                     {
 
-                         // Use XmlReader for best performance
 
-                         using (var reader = XmlReader.Create(streamReader, settings))
 
-                         {
 
-                             item.ResetPeople();
 
-                             reader.MoveToContent();
 
-                             reader.Read();
 
-                             // Loop through each element
 
-                             while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 
-                             {
 
-                                 cancellationToken.ThrowIfCancellationRequested();
 
-                                 if (reader.NodeType == XmlNodeType.Element)
 
-                                 {
 
-                                     FetchDataFromXmlNode(reader, item);
 
-                                 }
 
-                                 else
 
-                                 {
 
-                                     reader.Read();
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 return;
 
-             }
 
-             using (var fileStream = FileSystem.OpenRead(metadataFile))
 
-             {
 
-                 using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
 
-                 {
 
-                     item.ResetPeople();
 
-                     // Need to handle a url after the xml data
 
-                     // http://kodi.wiki/view/NFO_files/movies
 
-                     var xml = streamReader.ReadToEnd();
 
-                     // 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)
 
-                     {
 
-                         var endingXml = xml.Substring(index);
 
-                         ParseProviderLinks(item.Item, endingXml);
 
-                         // If the file is just an imdb url, don't go any further
 
-                         if (index == 0)
 
-                         {
 
-                             return;
 
-                         }
 
-                         xml = xml.Substring(0, index + 1);
 
-                     }
 
-                     else
 
-                     {
 
-                         // If the file is just an Imdb url, handle that
 
-                         ParseProviderLinks(item.Item, xml);
 
-                         return;
 
-                     }
 
-                     using (var ms = new MemoryStream())
 
-                     {
 
-                         var bytes = Encoding.UTF8.GetBytes(xml);
 
-                         ms.Write(bytes, 0, bytes.Length);
 
-                         ms.Position = 0;
 
-                         // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
 
-                         try
 
-                         {
 
-                             // Use XmlReader for best performance
 
-                             using (var reader = XmlReader.Create(ms, settings))
 
-                             {
 
-                                 reader.MoveToContent();
 
-                                 reader.Read();
 
-                                 // Loop through each element
 
-                                 while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 
-                                 {
 
-                                     cancellationToken.ThrowIfCancellationRequested();
 
-                                     if (reader.NodeType == XmlNodeType.Element)
 
-                                     {
 
-                                         FetchDataFromXmlNode(reader, item);
 
-                                     }
 
-                                     else
 
-                                     {
 
-                                         reader.Read();
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                         catch (XmlException)
 
-                         {
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         protected virtual string MovieDbParserSearchString
 
-         {
 
-             get { return "themoviedb.org/movie/"; }
 
-         }
 
-         protected void ParseProviderLinks(T item, string xml)
 
-         {
 
-             //Look for a match for the Regex pattern "tt" followed by 7 digits
 
-             Match m = Regex.Match(xml, @"tt([0-9]{7})", RegexOptions.IgnoreCase);
 
-             if (m.Success)
 
-             {
 
-                 item.SetProviderId(MetadataProviders.Imdb, m.Value);
 
-             }
 
-             // Support Tmdb
 
-             // http://www.themoviedb.org/movie/36557
 
-             var srch = MovieDbParserSearchString;
 
-             var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
 
-             if (index != -1)
 
-             {
 
-                 var tmdbId = xml.Substring(index + srch.Length).TrimEnd('/');
 
-                 int value;
 
-                 if (!string.IsNullOrWhiteSpace(tmdbId) && int.TryParse(tmdbId, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
 
-                 {
 
-                     item.SetProviderId(MetadataProviders.Tmdb, tmdbId);
 
-                 }
 
-             }
 
-             if (item is Series)
 
-             {
 
-                 srch = "thetvdb.com/?tab=series&id=";
 
-                 index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
 
-                 if (index != -1)
 
-                 {
 
-                     var tvdbId = xml.Substring(index + srch.Length).TrimEnd('/');
 
-                     int value;
 
-                     if (!string.IsNullOrWhiteSpace(tvdbId) && int.TryParse(tvdbId, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.Tvdb, tvdbId);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> itemResult)
 
-         {
 
-             var item = itemResult.Item;
 
-             switch (reader.Name)
 
-             {
 
-                 // DateCreated
 
-                 case "dateadded":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             DateTime added;
 
-                             if (DateTime.TryParseExact(val, BaseNfoSaver.DateAddedFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out added))
 
-                             {
 
-                                 item.DateCreated = added.ToUniversalTime();
 
-                             }
 
-                             else if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out added))
 
-                             {
 
-                                 item.DateCreated = added.ToUniversalTime();
 
-                             }
 
-                             else
 
-                             {
 
-                                 Logger.Warn("Invalid Added value found: " + val);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "originaltitle":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrEmpty(val))
 
-                         {
 
-                             item.OriginalTitle = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "type":
 
-                     item.DisplayMediaType = reader.ReadElementContentAsString();
 
-                     break;
 
-                 case "title":
 
-                 case "localtitle":
 
-                     item.Name = reader.ReadElementContentAsString();
 
-                     break;
 
-                 case "criticrating":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrEmpty(text))
 
-                         {
 
-                             float value;
 
-                             if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
 
-                             {
 
-                                 item.CriticRating = value;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "sorttitle":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.ForcedSortName = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "biography":
 
-                 case "plot":
 
-                 case "review":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.Overview = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "language":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         item.PreferredMetadataLanguage = val;
 
-                         break;
 
-                     }
 
-                 case "countrycode":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         item.PreferredMetadataCountryCode = val;
 
-                         break;
 
-                     }
 
-                 case "website":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.HomePageUrl = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "lockedfields":
 
-                     {
 
-                         var fields = new List<MetadataFields>();
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             var list = val.Split('|').Select(i =>
 
-                             {
 
-                                 MetadataFields field;
 
-                                 if (Enum.TryParse<MetadataFields>(i, true, out field))
 
-                                 {
 
-                                     return (MetadataFields?)field;
 
-                                 }
 
-                                 return null;
 
-                             }).Where(i => i.HasValue).Select(i => i.Value);
 
-                             fields.AddRange(list);
 
-                         }
 
-                         item.LockedFields = fields;
 
-                         break;
 
-                     }
 
-                 case "tagline":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.Tagline = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "country":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.ProductionLocations.AddRange(val.Split('/')
 
-                                 .Select(i => i.Trim())
 
-                                 .Where(i => !string.IsNullOrWhiteSpace(i)));
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "mpaa":
 
-                     {
 
-                         var rating = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(rating))
 
-                         {
 
-                             item.OfficialRating = rating;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "customrating":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.CustomRating = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "runtime":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(text))
 
-                         {
 
-                             int runtime;
 
-                             if (int.TryParse(text.Split(' ')[0], NumberStyles.Integer, _usCulture, out runtime))
 
-                             {
 
-                                 item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "aspectratio":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         var hasAspectRatio = item as IHasAspectRatio;
 
-                         if (!string.IsNullOrWhiteSpace(val) && hasAspectRatio != null)
 
-                         {
 
-                             hasAspectRatio.AspectRatio = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "lockdata":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.IsLocked = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "studio":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             //var parts = val.Split('/')
 
-                             //    .Select(i => i.Trim())
 
-                             //    .Where(i => !string.IsNullOrWhiteSpace(i));
 
-                             //foreach (var p in parts)
 
-                             //{
 
-                             //    item.AddStudio(p);
 
-                             //}
 
-                             item.AddStudio(val);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "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))
 
-                             {
 
-                                 continue;
 
-                             }
 
-                             itemResult.AddPerson(p);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "credits":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             var parts = val.Split('/').Select(i => i.Trim())
 
-                                 .Where(i => !string.IsNullOrEmpty(i));
 
-                             foreach (var p in parts.Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
 
-                             {
 
-                                 if (string.IsNullOrWhiteSpace(p.Name))
 
-                                 {
 
-                                     continue;
 
-                                 }
 
-                                 itemResult.AddPerson(p);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "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))
 
-                             {
 
-                                 continue;
 
-                             }
 
-                             itemResult.AddPerson(p);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "actor":
 
-                     {
 
-                         if (!reader.IsEmptyElement)
 
-                         {
 
-                             using (var subtree = reader.ReadSubtree())
 
-                             {
 
-                                 var person = GetPersonFromXmlNode(subtree);
 
-                                 if (!string.IsNullOrWhiteSpace(person.Name))
 
-                                 {
 
-                                     itemResult.AddPerson(person);
 
-                                 }
 
-                             }
 
-                         }
 
-                         else
 
-                         {
 
-                             reader.Read();
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "trailer":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         var hasTrailer = item as IHasTrailers;
 
-                         if (hasTrailer != null)
 
-                         {
 
-                             if (!string.IsNullOrWhiteSpace(val))
 
-                             {
 
-                                 val = val.Replace("plugin://plugin.video.youtube/?action=play_video&videoid=", "https://www.youtube.com/watch?v=", StringComparison.OrdinalIgnoreCase);
 
-                                 hasTrailer.AddTrailerUrl(val, false);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "displayorder":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         var hasDisplayOrder = item as IHasDisplayOrder;
 
-                         if (hasDisplayOrder != null)
 
-                         {
 
-                             if (!string.IsNullOrWhiteSpace(val))
 
-                             {
 
-                                 hasDisplayOrder.DisplayOrder = val;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "year":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             int productionYear;
 
-                             if (int.TryParse(val, out productionYear) && productionYear > 1850)
 
-                             {
 
-                                 item.ProductionYear = productionYear;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "rating":
 
-                     {
 
-                         var rating = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(rating))
 
-                         {
 
-                             float val;
 
-                             // All external meta is saving this as '.' for decimal I believe...but just to be sure
 
-                             if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out val))
 
-                             {
 
-                                 item.CommunityRating = val;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "aired":
 
-                 case "formed":
 
-                 case "premiered":
 
-                 case "releasedate":
 
-                     {
 
-                         var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             DateTime date;
 
-                             if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out date) && date.Year > 1850)
 
-                             {
 
-                                 item.PremiereDate = date.ToUniversalTime();
 
-                                 item.ProductionYear = date.Year;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "enddate":
 
-                     {
 
-                         var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             DateTime date;
 
-                             if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out date) && date.Year > 1850)
 
-                             {
 
-                                 item.EndDate = date.ToUniversalTime();
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "genre":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             var parts = val.Split('/')
 
-                                 .Select(i => i.Trim())
 
-                                 .Where(i => !string.IsNullOrWhiteSpace(i));
 
-                             foreach (var p in parts)
 
-                             {
 
-                                 item.AddGenre(p);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "style":
 
-                 case "tag":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.AddTag(val);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "plotkeyword":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.AddKeyword(val);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "fileinfo":
 
-                     {
 
-                         if (!reader.IsEmptyElement)
 
-                         {
 
-                             using (var subtree = reader.ReadSubtree())
 
-                             {
 
-                                 FetchFromFileInfoNode(subtree, item);
 
-                             }
 
-                         }
 
-                         else
 
-                         {
 
-                             reader.Read();
 
-                         }
 
-                         break;
 
-                     }
 
-                 default:
 
-                     string readerName = reader.Name;
 
-                     string providerIdValue;
 
-                     if (_validProviderIds.TryGetValue(readerName, out providerIdValue))
 
-                     {
 
-                         var id = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(id))
 
-                         {
 
-                             item.SetProviderId(providerIdValue, id);
 
-                         }
 
-                     }
 
-                     else
 
-                     {
 
-                         reader.Skip();
 
-                     }
 
-                     break;
 
-             }
 
-         }
 
-         private void FetchFromFileInfoNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             reader.Read();
 
-             // Loop through each element
 
-             while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "streamdetails":
 
-                             {
 
-                                 if (reader.IsEmptyElement)
 
-                                 {
 
-                                     reader.Read();
 
-                                     continue;
 
-                                 }
 
-                                 using (var subtree = reader.ReadSubtree())
 
-                                 {
 
-                                     FetchFromStreamDetailsNode(subtree, item);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     reader.Read();
 
-                 }
 
-             }
 
-         }
 
-         private void FetchFromStreamDetailsNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             reader.Read();
 
-             // Loop through each element
 
-             while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "video":
 
-                             {
 
-                                 if (reader.IsEmptyElement)
 
-                                 {
 
-                                     reader.Read();
 
-                                     continue;
 
-                                 }
 
-                                 using (var subtree = reader.ReadSubtree())
 
-                                 {
 
-                                     FetchFromVideoNode(subtree, item);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     reader.Read();
 
-                 }
 
-             }
 
-         }
 
-         private void FetchFromVideoNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             reader.Read();
 
-             // Loop through each element
 
-             while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "format3d":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 var video = item as Video;
 
-                                 if (video != null)
 
-                                 {
 
-                                     if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
 
-                                     {
 
-                                         video.Video3DFormat = Video3DFormat.HalfSideBySide;
 
-                                     }
 
-                                     else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
 
-                                     {
 
-                                         video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
 
-                                     }
 
-                                     else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
 
-                                     {
 
-                                         video.Video3DFormat = Video3DFormat.FullTopAndBottom;
 
-                                     }
 
-                                     else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
 
-                                     {
 
-                                         video.Video3DFormat = Video3DFormat.FullSideBySide;
 
-                                     }
 
-                                     else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase))
 
-                                     {
 
-                                         video.Video3DFormat = Video3DFormat.MVC;
 
-                                     }
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     reader.Read();
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Gets the persons from XML node.
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <returns>IEnumerable{PersonInfo}.</returns>
 
-         private PersonInfo GetPersonFromXmlNode(XmlReader reader)
 
-         {
 
-             var name = string.Empty;
 
-             var type = PersonType.Actor;  // If type is not specified assume actor
 
-             var role = string.Empty;
 
-             int? sortOrder = null;
 
-             reader.MoveToContent();
 
-             reader.Read();
 
-             // Loop through each element
 
-             while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "name":
 
-                             name = reader.ReadElementContentAsString() ?? string.Empty;
 
-                             break;
 
-                         case "type":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(val))
 
-                                 {
 
-                                     type = val;
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         case "role":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(val))
 
-                                 {
 
-                                     role = val;
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         case "sortorder":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(val))
 
-                                 {
 
-                                     int intVal;
 
-                                     if (int.TryParse(val, NumberStyles.Integer, _usCulture, out intVal))
 
-                                     {
 
-                                         sortOrder = intVal;
 
-                                     }
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     reader.Read();
 
-                 }
 
-             }
 
-             return new PersonInfo
 
-             {
 
-                 Name = name.Trim(),
 
-                 Role = role,
 
-                 Type = type,
 
-                 SortOrder = sortOrder
 
-             };
 
-         }
 
-         /// <summary>
 
-         /// Used to split names of comma or pipe delimeted genres and people
 
-         /// </summary>
 
-         /// <param name="value">The value.</param>
 
-         /// <returns>IEnumerable{System.String}.</returns>
 
-         private IEnumerable<string> SplitNames(string value)
 
-         {
 
-             value = value ?? string.Empty;
 
-             // Only split by comma if there is no pipe in the string
 
-             // We have to be careful to not split names like Matthew, Jr.
 
-             var separator = value.IndexOf('|') == -1 && value.IndexOf(';') == -1 ? new[] { ',' } : new[] { '|', ';' };
 
-             value = value.Trim().Trim(separator);
 
-             return string.IsNullOrWhiteSpace(value) ? new string[] { } : Split(value, separator, StringSplitOptions.RemoveEmptyEntries);
 
-         }
 
-         /// <summary>
 
-         /// Provides an additional overload for string.split
 
-         /// </summary>
 
-         /// <param name="val">The val.</param>
 
-         /// <param name="separators">The separators.</param>
 
-         /// <param name="options">The options.</param>
 
-         /// <returns>System.String[][].</returns>
 
-         private static string[] Split(string val, char[] separators, StringSplitOptions options)
 
-         {
 
-             return val.Split(separators, options);
 
-         }
 
-     }
 
- }
 
 
  |