| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317 | 
							- using MediaBrowser.Controller.Entities;
 
- using MediaBrowser.Model.Entities;
 
- using MediaBrowser.Model.Logging;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Globalization;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading;
 
- using System.Xml;
 
- namespace MediaBrowser.Controller.Providers
 
- {
 
-     /// <summary>
 
-     /// Provides a base class for parsing metadata xml
 
-     /// </summary>
 
-     /// <typeparam name="T"></typeparam>
 
-     public class BaseItemXmlParser<T>
 
-         where T : BaseItem
 
-     {
 
-         /// <summary>
 
-         /// The logger
 
-         /// </summary>
 
-         protected ILogger Logger { get; private set; }
 
-         /// <summary>
 
-         /// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
 
-         /// </summary>
 
-         /// <param name="logger">The logger.</param>
 
-         public BaseItemXmlParser(ILogger logger)
 
-         {
 
-             Logger = logger;
 
-         }
 
-         /// <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(T item, string metadataFile, CancellationToken cancellationToken)
 
-         {
 
-             if (item == null)
 
-             {
 
-                 throw new ArgumentNullException();
 
-             }
 
-             if (string.IsNullOrEmpty(metadataFile))
 
-             {
 
-                 throw new ArgumentNullException();
 
-             }
 
-             var settings = new XmlReaderSettings
 
-             {
 
-                 CheckCharacters = false,
 
-                 IgnoreProcessingInstructions = true,
 
-                 IgnoreComments = true,
 
-                 ValidationType = ValidationType.None
 
-             };
 
-             //Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken);
 
-             Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
 
-         }
 
-         /// <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="encoding">The encoding.</param>
 
-         /// <param name="cancellationToken">The cancellation token.</param>
 
-         private void Fetch(T item, string metadataFile, XmlReaderSettings settings, Encoding encoding, CancellationToken cancellationToken)
 
-         {
 
-             using (var streamReader = new StreamReader(metadataFile, encoding))
 
-             {
 
-                 // Use XmlReader for best performance
 
-                 using (var reader = XmlReader.Create(streamReader, settings))
 
-                 {
 
-                     reader.MoveToContent();
 
-                     // Loop through each element
 
-                     while (reader.Read())
 
-                     {
 
-                         cancellationToken.ThrowIfCancellationRequested();
 
-                         if (reader.NodeType == XmlNodeType.Element)
 
-                         {
 
-                             FetchDataFromXmlNode(reader, item);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private readonly CultureInfo _usCulture = new CultureInfo("en-US");
 
-         /// <summary>
 
-         /// Fetches metadata from one Xml Element
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <param name="item">The item.</param>
 
-         protected virtual void FetchDataFromXmlNode(XmlReader reader, T item)
 
-         {
 
-             switch (reader.Name)
 
-             {
 
-                 // DateCreated
 
-                 case "Added":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             DateTime added;
 
-                             if (DateTime.TryParse(val, out added))
 
-                             {
 
-                                 item.DateCreated = added.ToUniversalTime();
 
-                             }
 
-                             else
 
-                             {
 
-                                 Logger.Warn("Invalid Added value found: " + val);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "LocalTitle":
 
-                     item.Name = reader.ReadElementContentAsString();
 
-                     break;
 
-                 case "Type":
 
-                     {
 
-                         var type = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(type) && !type.Equals("none", StringComparison.OrdinalIgnoreCase))
 
-                         {
 
-                             item.DisplayMediaType = type;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "CriticRating":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         var hasCriticRating = item as IHasCriticRating;
 
-                         if (hasCriticRating != null && !string.IsNullOrEmpty(text))
 
-                         {
 
-                             float value;
 
-                             if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
 
-                             {
 
-                                 hasCriticRating.CriticRating = value;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Budget":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         var hasBudget = item as IHasBudget;
 
-                         if (hasBudget != null)
 
-                         {
 
-                             double value;
 
-                             if (double.TryParse(text, NumberStyles.Any, _usCulture, out value))
 
-                             {
 
-                                 hasBudget.Budget = value;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Revenue":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         var hasBudget = item as IHasBudget;
 
-                         if (hasBudget != null)
 
-                         {
 
-                             double value;
 
-                             if (double.TryParse(text, NumberStyles.Any, _usCulture, out value))
 
-                             {
 
-                                 hasBudget.Revenue = value;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Metascore":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         var hasMetascore = item as IHasMetascore;
 
-                         if (hasMetascore != null)
 
-                         {
 
-                             float value;
 
-                             if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
 
-                             {
 
-                                 hasMetascore.Metascore = value;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "AwardSummary":
 
-                     {
 
-                         var text = reader.ReadElementContentAsString();
 
-                         var hasAwards = item as IHasAwards;
 
-                         if (hasAwards != null)
 
-                         {
 
-                             if (!string.IsNullOrWhiteSpace(text))
 
-                             {
 
-                                 hasAwards.AwardSummary = text;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "SortTitle":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.ForcedSortName = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Overview":
 
-                 case "Description":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.Overview = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "ShortOverview":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             var hasShortOverview = item as IHasShortOverview;
 
-                             if (hasShortOverview != null)
 
-                             {
 
-                                 hasShortOverview.ShortOverview = val;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "CriticRatingSummary":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             var hasCriticRating = item as IHasCriticRating;
 
-                             if (hasCriticRating != null)
 
-                             {
 
-                                 hasCriticRating.CriticRatingSummary = val;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Language":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         var hasLanguage = item as IHasPreferredMetadataLanguage;
 
-                         if (hasLanguage != null)
 
-                         {
 
-                             hasLanguage.PreferredMetadataLanguage = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "PlaceOfBirth":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             var person = item as Person;
 
-                             if (person != null)
 
-                             {
 
-                                 person.PlaceOfBirth = 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 "TagLines":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             FetchFromTaglinesNode(subtree, item);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Countries":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             FetchFromCountriesNode(subtree, item);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "ContentRating":
 
-                 case "MPAARating":
 
-                     {
 
-                         var rating = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(rating))
 
-                         {
 
-                             item.OfficialRating = rating;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "MPAADescription":
 
-                     {
 
-                         var rating = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(rating))
 
-                         {
 
-                             item.OfficialRatingDescription = rating;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "CustomRating":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             item.CustomRating = val;
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "RunningTime":
 
-                     {
 
-                         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 "Network":
 
-                     {
 
-                         foreach (var name in SplitNames(reader.ReadElementContentAsString()))
 
-                         {
 
-                             if (string.IsNullOrWhiteSpace(name))
 
-                             {
 
-                                 continue;
 
-                             }
 
-                             item.AddStudio(name);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Director":
 
-                     {
 
-                         foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new Entities.PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
 
-                         {
 
-                             if (string.IsNullOrWhiteSpace(p.Name))
 
-                             {
 
-                                 continue;
 
-                             }
 
-                             item.AddPerson(p);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Writer":
 
-                     {
 
-                         foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new Entities.PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
 
-                         {
 
-                             if (string.IsNullOrWhiteSpace(p.Name))
 
-                             {
 
-                                 continue;
 
-                             }
 
-                             item.AddPerson(p);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Actors":
 
-                     {
 
-                         var actors = reader.ReadInnerXml();
 
-                         if (actors.Contains("<"))
 
-                         {
 
-                             // This is one of the mis-named "Actors" full nodes created by MB2
 
-                             // Create a reader and pass it to the persons node processor
 
-                             FetchDataFromPersonsNode(new XmlTextReader(new StringReader("<Persons>" + actors + "</Persons>")), item);
 
-                         }
 
-                         else
 
-                         {
 
-                             // Old-style piped string
 
-                             foreach (var p in SplitNames(actors).Select(v => new Entities.PersonInfo { Name = v.Trim(), Type = PersonType.Actor }))
 
-                             {
 
-                                 if (string.IsNullOrWhiteSpace(p.Name))
 
-                                 {
 
-                                     continue;
 
-                                 }
 
-                                 item.AddPerson(p);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "GuestStars":
 
-                     {
 
-                         foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new Entities.PersonInfo { Name = v.Trim(), Type = PersonType.GuestStar }))
 
-                         {
 
-                             if (string.IsNullOrWhiteSpace(p.Name))
 
-                             {
 
-                                 continue;
 
-                             }
 
-                             item.AddPerson(p);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Trailer":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         var hasTrailers = item as IHasTrailers;
 
-                         if (hasTrailers != null)
 
-                         {
 
-                             if (!string.IsNullOrWhiteSpace(val))
 
-                             {
 
-                                 hasTrailers.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 "Trailers":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             var hasTrailers = item as IHasTrailers;
 
-                             if (hasTrailers != null)
 
-                             {
 
-                                 FetchDataFromTrailersNode(subtree, hasTrailers);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "ProductionYear":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             int productionYear;
 
-                             if (int.TryParse(val, out productionYear) && productionYear > 1850)
 
-                             {
 
-                                 item.ProductionYear = productionYear;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Rating":
 
-                 case "IMDBrating":
 
-                     {
 
-                         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 "BirthDate":
 
-                 case "PremiereDate":
 
-                 case "FirstAired":
 
-                     {
 
-                         var firstAired = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(firstAired))
 
-                         {
 
-                             DateTime airDate;
 
-                             if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out airDate) && airDate.Year > 1850)
 
-                             {
 
-                                 item.PremiereDate = airDate.ToUniversalTime();
 
-                                 item.ProductionYear = airDate.Year;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "DeathDate":
 
-                 case "EndDate":
 
-                     {
 
-                         var firstAired = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(firstAired))
 
-                         {
 
-                             DateTime airDate;
 
-                             if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out airDate) && airDate.Year > 1850)
 
-                             {
 
-                                 item.EndDate = airDate.ToUniversalTime();
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "TvDbId":
 
-                     var tvdbId = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(tvdbId))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.Tvdb, tvdbId);
 
-                     }
 
-                     break;
 
-                 case "VoteCount":
 
-                     {
 
-                         var val = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(val))
 
-                         {
 
-                             int num;
 
-                             if (int.TryParse(val, NumberStyles.Integer, _usCulture, out num))
 
-                             {
 
-                                 item.VoteCount = num;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "MusicBrainzAlbumId":
 
-                     {
 
-                         var mbz = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(mbz))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.MusicBrainzAlbum, mbz);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "MusicBrainzAlbumArtistId":
 
-                     {
 
-                         var mbz = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(mbz))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, mbz);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "MusicBrainzArtistId":
 
-                     {
 
-                         var mbz = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(mbz))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.MusicBrainzArtist, mbz);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "MusicBrainzReleaseGroupId":
 
-                     {
 
-                         var mbz = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(mbz))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, mbz);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "TVRageId":
 
-                     {
 
-                         var id = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(id))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.TvRage, id);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "AudioDbArtistId":
 
-                     {
 
-                         var id = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(id))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.AudioDbArtist, id);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "AudioDbAlbumId":
 
-                     {
 
-                         var id = reader.ReadElementContentAsString();
 
-                         if (!string.IsNullOrWhiteSpace(id))
 
-                         {
 
-                             item.SetProviderId(MetadataProviders.AudioDbAlbum, id);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "RottenTomatoesId":
 
-                     var rtId = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(rtId))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.RottenTomatoes, rtId);
 
-                     }
 
-                     break;
 
-                 case "TMDbId":
 
-                     var tmdb = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(tmdb))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.Tmdb, tmdb);
 
-                     }
 
-                     break;
 
-                 case "TMDbCollectionId":
 
-                     var tmdbCollection = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(tmdbCollection))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.TmdbCollection, tmdbCollection);
 
-                     }
 
-                     break;
 
-                 case "TVcomId":
 
-                     var TVcomId = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(TVcomId))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.Tvcom, TVcomId);
 
-                     }
 
-                     break;
 
-                 case "Zap2ItId":
 
-                     var zap2ItId = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(zap2ItId))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.Zap2It, zap2ItId);
 
-                     }
 
-                     break;
 
-                 case "IMDB":
 
-                     var imDbId = reader.ReadElementContentAsString();
 
-                     if (!string.IsNullOrWhiteSpace(imDbId))
 
-                     {
 
-                         item.SetProviderId(MetadataProviders.Imdb, imDbId);
 
-                     }
 
-                     break;
 
-                 case "Genres":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             FetchFromGenresNode(subtree, item);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Tags":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             var hasTags = item as IHasTags;
 
-                             if (hasTags != null)
 
-                             {
 
-                                 FetchFromTagsNode(subtree, hasTags);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "PlotKeywords":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             var hasTags = item as IHasKeywords;
 
-                             if (hasTags != null)
 
-                             {
 
-                                 FetchFromKeywordsNode(subtree, hasTags);
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Persons":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             FetchDataFromPersonsNode(subtree, item);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Studios":
 
-                     {
 
-                         using (var subtree = reader.ReadSubtree())
 
-                         {
 
-                             FetchFromStudiosNode(subtree, item);
 
-                         }
 
-                         break;
 
-                     }
 
-                 case "Format3D":
 
-                     {
 
-                         var video = item as Video;
 
-                         if (video != null)
 
-                         {
 
-                             var val = reader.ReadElementContentAsString();
 
-                             if (string.Equals("HSBS", val, StringComparison.CurrentCulture))
 
-                             {
 
-                                 video.Video3DFormat = Video3DFormat.HalfSideBySide;
 
-                             }
 
-                             else if (string.Equals("HTAB", val, StringComparison.CurrentCulture))
 
-                             {
 
-                                 video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
 
-                             }
 
-                             else if (string.Equals("FTAB", val, StringComparison.CurrentCulture))
 
-                             {
 
-                                 video.Video3DFormat = Video3DFormat.FullTopAndBottom;
 
-                             }
 
-                             else if (string.Equals("FSBS", val, StringComparison.CurrentCulture))
 
-                             {
 
-                                 video.Video3DFormat = Video3DFormat.FullSideBySide;
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 default:
 
-                     reader.Skip();
 
-                     break;
 
-             }
 
-         }
 
-         private void FetchFromCountriesNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Country":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(val))
 
-                                 {
 
-                                     var hasProductionLocations = item as IHasProductionLocations;
 
-                                     if (hasProductionLocations != null)
 
-                                     {
 
-                                         if (!string.IsNullOrWhiteSpace(val))
 
-                                         {
 
-                                             hasProductionLocations.AddProductionLocation(val);
 
-                                         }
 
-                                     }
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Fetches from taglines node.
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <param name="item">The item.</param>
 
-         private void FetchFromTaglinesNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Tagline":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(val))
 
-                                 {
 
-                                     var hasTaglines = item as IHasTaglines;
 
-                                     if (hasTaglines != null)
 
-                                     {
 
-                                         if (!string.IsNullOrWhiteSpace(val))
 
-                                         {
 
-                                             hasTaglines.AddTagline(val);
 
-                                         }
 
-                                     }
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Fetches from genres node.
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <param name="item">The item.</param>
 
-         private void FetchFromGenresNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Genre":
 
-                             {
 
-                                 var genre = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(genre))
 
-                                 {
 
-                                     item.AddGenre(genre);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void FetchFromTagsNode(XmlReader reader, IHasTags item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Tag":
 
-                             {
 
-                                 var tag = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(tag))
 
-                                 {
 
-                                     item.AddTag(tag);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void FetchFromKeywordsNode(XmlReader reader, IHasKeywords item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "PlotKeyword":
 
-                             {
 
-                                 var tag = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(tag))
 
-                                 {
 
-                                     item.AddKeyword(tag);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Fetches the data from persons node.
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <param name="item">The item.</param>
 
-         private void FetchDataFromPersonsNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Person":
 
-                         case "Actor":
 
-                             {
 
-                                 using (var subtree = reader.ReadSubtree())
 
-                                 {
 
-                                     foreach (var person in GetPersonsFromXmlNode(subtree))
 
-                                     {
 
-                                         if (string.IsNullOrWhiteSpace(person.Name))
 
-                                         {
 
-                                             continue;
 
-                                         }
 
-                                         item.AddPerson(person);
 
-                                     }
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         private void FetchDataFromTrailersNode(XmlReader reader, IHasTrailers item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Trailer":
 
-                             {
 
-                                 var val = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(val))
 
-                                 {
 
-                                     item.AddTrailerUrl(val, false);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         protected List<ChapterInfo> FetchChaptersFromXmlNode(BaseItem item, XmlReader reader)
 
-         {
 
-             using (reader)
 
-             {
 
-                 return GetChaptersFromXmlNode(reader)
 
-                     .Where(i => i.StartPositionTicks >= 0)
 
-                     .ToList();
 
-             }
 
-         }
 
-         private IEnumerable<ChapterInfo> GetChaptersFromXmlNode(XmlReader reader)
 
-         {
 
-             var chapters = new List<ChapterInfo>();
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Chapter":
 
-                             {
 
-                                 using (var subtree = reader.ReadSubtree())
 
-                                 {
 
-                                     chapters.Add(GetChapterInfoFromXmlNode(subtree));
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-             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;
 
-         }
 
-         /// <summary>
 
-         /// Fetches from studios node.
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <param name="item">The item.</param>
 
-         private void FetchFromStudiosNode(XmlReader reader, T item)
 
-         {
 
-             reader.MoveToContent();
 
-             while (reader.Read())
 
-             {
 
-                 if (reader.NodeType == XmlNodeType.Element)
 
-                 {
 
-                     switch (reader.Name)
 
-                     {
 
-                         case "Studio":
 
-                             {
 
-                                 var studio = reader.ReadElementContentAsString();
 
-                                 if (!string.IsNullOrWhiteSpace(studio))
 
-                                 {
 
-                                     item.AddStudio(studio);
 
-                                 }
 
-                                 break;
 
-                             }
 
-                         default:
 
-                             reader.Skip();
 
-                             break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Gets the persons from XML node.
 
-         /// </summary>
 
-         /// <param name="reader">The reader.</param>
 
-         /// <returns>IEnumerable{PersonInfo}.</returns>
 
-         private IEnumerable<PersonInfo> GetPersonsFromXmlNode(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();
 
-             while (reader.Read())
 
-             {
 
-                 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;
 
-                     }
 
-                 }
 
-             }
 
-             var personInfo = new PersonInfo
 
-             {
 
-                 Name = name.Trim(),
 
-                 Role = role,
 
-                 Type = type,
 
-                 SortOrder = sortOrder
 
-             };
 
-             return new[] { personInfo };
 
-         }
 
-         /// <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);
 
-         }
 
-     }
 
- }
 
 
  |