/// <summary> /// Fetches the actors. /// </summary> /// <param name="series">The series.</param> /// <param name="actorsDoc">The actors doc.</param> /// <param name="seriesDoc">The seriesDoc.</param> /// <returns>Task.</returns> private void FetchActors(Series series, XmlDocument actorsDoc, XmlDocument seriesDoc) { var xmlNodeList = actorsDoc.SelectNodes("Actors/Actor"); if (xmlNodeList != null) { series.People.Clear(); foreach (XmlNode p in xmlNodeList) { string actorName = p.SafeGetString("Name"); string actorRole = p.SafeGetString("Role"); if (!string.IsNullOrWhiteSpace(actorName)) { // Sometimes tvdb actors have leading spaces series.AddPerson(new PersonInfo { Type = PersonType.Actor, Name = actorName.Trim(), Role = actorRole }); } } } }
/// <summary> /// Fetches the data from actor node. /// </summary> /// <param name="series">The series.</param> /// <param name="reader">The reader.</param> private void FetchDataFromActorNode(Series series, XmlReader reader) { reader.MoveToContent(); var personInfo = new PersonInfo(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Name": { personInfo.Name = (reader.ReadElementContentAsString() ?? string.Empty).Trim(); break; } case "Role": { personInfo.Role = (reader.ReadElementContentAsString() ?? string.Empty).Trim(); break; } default: reader.Skip(); break; } } } personInfo.Type = PersonType.Actor; if (!string.IsNullOrEmpty(personInfo.Name)) { series.AddPerson(personInfo); } }
/// <summary> /// Fetches the actors. /// </summary> /// <param name="series">The series.</param> /// <param name="seriesId">The series id.</param> /// <param name="doc">The doc.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> private async Task FetchActors(Series series, string seriesId, XmlDocument doc, CancellationToken cancellationToken) { string urlActors = string.Format(getActors, TVUtils.TVDBApiKey, seriesId); var docActors = new XmlDocument(); try { using (var actors = await HttpClient.Get(urlActors, TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { docActors.Load(actors); } } catch (HttpException) { } if (docActors.HasChildNodes) { XmlNode actorsNode = null; if (ConfigurationManager.Configuration.SaveLocalMeta) { //add to the main doc for saving var seriesNode = doc.SelectSingleNode("//Series"); if (seriesNode != null) { actorsNode = doc.CreateNode(XmlNodeType.Element, "Persons", null); seriesNode.AppendChild(actorsNode); } } var xmlNodeList = docActors.SelectNodes("Actors/Actor"); if (xmlNodeList != null) { foreach (XmlNode p in xmlNodeList) { string actorName = p.SafeGetString("Name"); string actorRole = p.SafeGetString("Role"); if (!string.IsNullOrWhiteSpace(actorName)) { series.AddPerson(new PersonInfo { Type = PersonType.Actor, Name = actorName, Role = actorRole }); if (ConfigurationManager.Configuration.SaveLocalMeta && actorsNode != null) { //create in main doc var personNode = doc.CreateNode(XmlNodeType.Element, "Person", null); foreach (XmlNode subNode in p.ChildNodes) { personNode.AppendChild(doc.ImportNode(subNode, true)); } //need to add the type var typeNode = doc.CreateNode(XmlNodeType.Element, "Type", null); typeNode.InnerText = "Actor"; personNode.AppendChild(typeNode); actorsNode.AppendChild(personNode); } } } } } }