/// <summary> /// Fetches from the preview node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchTrailerUrl(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "large": info.TrailerUrl = reader.ReadStringSafe(); break; default: reader.Skip(); break; } } }
/// <summary> /// Fetches trailer info from an xml node /// </summary> /// <param name="reader">The reader.</param> /// <returns>TrailerInfo.</returns> private static TrailerInfo FetchTrailerInfo(XmlReader reader) { var trailerInfo = new TrailerInfo { }; reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "info": FetchInfo(reader.ReadSubtree(), trailerInfo); break; case "cast": FetchCast(reader.ReadSubtree(), trailerInfo); break; case "genre": FetchGenres(reader.ReadSubtree(), trailerInfo); break; case "poster": FetchPosterUrl(reader.ReadSubtree(), trailerInfo); break; case "preview": FetchTrailerUrl(reader.ReadSubtree(), trailerInfo); break; default: reader.Skip(); break; } } } return(trailerInfo); }
/// <summary> /// Fetches from the genre node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchGenres(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.IsStartElement()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "name": info.Video.AddGenre(reader.ReadStringSafe()); break; default: reader.Skip(); break; } } } }
/// <summary> /// Fetches trailer info from an xml node /// </summary> /// <param name="reader">The reader.</param> /// <returns>TrailerInfo.</returns> private static TrailerInfo FetchTrailerInfo(XmlReader reader) { var trailerInfo = new TrailerInfo { }; reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "info": FetchInfo(reader.ReadSubtree(), trailerInfo); break; case "cast": FetchCast(reader.ReadSubtree(), trailerInfo); break; case "genre": FetchGenres(reader.ReadSubtree(), trailerInfo); break; case "poster": FetchPosterUrl(reader.ReadSubtree(), trailerInfo); break; case "preview": FetchTrailerUrl(reader.ReadSubtree(), trailerInfo); break; default: reader.Skip(); break; } } } return trailerInfo; }
/// <summary> /// Fetches from the cast node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchCast(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.IsStartElement()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "name": info.Video.AddPerson(new PersonInfo { Name = reader.ReadStringSafe(), Type = PersonType.Actor }); break; default: reader.Skip(); break; } } } }
/// <summary> /// Fetches from the poster node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchPosterUrl(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "location": info.ImageUrl = reader.ReadStringSafe(); break; case "xlarge": info.HdImageUrl = reader.ReadStringSafe(); break; default: reader.Skip(); break; } } }
/// <summary> /// Fetches from the info node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchInfo(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "title": info.Video.Name = reader.ReadStringSafe(); break; case "runtime": { var runtime = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(runtime)) { if (runtime.StartsWith(":", StringComparison.OrdinalIgnoreCase)) { runtime = "0" + runtime; } TimeSpan runtimeTimeSpan; if (TimeSpan.TryParse(runtime, UsCulture, out runtimeTimeSpan)) { info.Video.OriginalRunTimeTicks = runtimeTimeSpan.Ticks; } } break; } case "rating": { var rating = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(rating) && !string.Equals("not yet rated", rating, StringComparison.OrdinalIgnoreCase)) { info.Video.OfficialRating = rating; } break; } case "studio": { var studio = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(studio)) { info.Video.AddStudio(studio); } break; } case "postdate": { DateTime date; if (DateTime.TryParse(reader.ReadStringSafe(), UsCulture, DateTimeStyles.None, out date)) { info.PostDate = date.ToUniversalTime(); } break; } case "releasedate": { var val = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(val)) { DateTime date; if (DateTime.TryParse(val, UsCulture, DateTimeStyles.None, out date)) { info.Video.PremiereDate = date.ToUniversalTime(); info.Video.ProductionYear = date.Year; } } break; } case "director": { var directors = reader.ReadStringSafe() ?? string.Empty; foreach (var director in Split(directors, ',', StringSplitOptions.RemoveEmptyEntries)) { var name = director.Trim(); if (!string.IsNullOrWhiteSpace(name)) { info.Video.AddPerson(new PersonInfo { Name = name, Type = PersonType.Director }); } } break; } case "description": info.Video.Overview = reader.ReadStringSafe(); break; default: reader.Skip(); break; } } }
/// <summary> /// Fetches from the cast node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchCast(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.IsStartElement()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "name": { var name = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(name)) { info.People.Add(new PersonInfo { Name = name, Type = PersonType.Actor }); } break; } default: reader.Skip(); break; } } } }
/// <summary> /// Fetches from the genre node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchGenres(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.IsStartElement()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "name": { var val = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(val)) { info.Genres.Add(val); } break; } default: reader.Skip(); break; } } } }
/// <summary> /// Fetches from the info node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchInfo(XmlReader reader, TrailerInfo info, ILogger logger) { reader.MoveToContent(); reader.Read(); while (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "title": info.Name = reader.ReadStringSafe(); break; case "runtime": { var val = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(val)) { var parts = val.Split(':'); if (parts.Length == 2) { int mins; int secs; if (int.TryParse(parts[0], NumberStyles.Any, UsCulture, out mins) && int.TryParse(parts[1], NumberStyles.Any, UsCulture, out secs)) { var totalSeconds = (mins*60) + secs; info.RunTimeTicks = TimeSpan.FromSeconds(totalSeconds).Ticks; } } } break; } case "rating": { var rating = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(rating) && !string.Equals("not yet rated", rating, StringComparison.OrdinalIgnoreCase)) { info.OfficialRating = rating; } break; } case "studio": { var studio = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(studio)) { info.Studios.Add(studio); } break; } case "postdate": { DateTime date; if (DateTime.TryParse(reader.ReadStringSafe(), UsCulture, DateTimeStyles.None, out date)) { info.PostDate = date.ToUniversalTime(); } break; } case "releasedate": { var val = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(val)) { DateTime date; if (DateTime.TryParse(val, UsCulture, DateTimeStyles.None, out date)) { info.PremiereDate = date.ToUniversalTime(); info.ProductionYear = date.Year; } } break; } case "director": { var directors = reader.ReadStringSafe() ?? string.Empty; foreach (var director in Split(directors, ',', StringSplitOptions.RemoveEmptyEntries)) { var name = director.Trim(); if (!string.IsNullOrWhiteSpace(name)) { info.People.Add(new PersonInfo { Name = name, Type = PersonType.Director }); } } break; } case "description": info.Overview = reader.ReadStringSafe(); break; default: reader.Skip(); break; } } }
/// <summary> /// Fetches from the info node /// </summary> /// <param name="reader">The reader.</param> /// <param name="info">The info.</param> private static void FetchInfo(XmlReader reader, TrailerInfo info) { reader.MoveToContent(); reader.Read(); while (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "title": info.Video.Name = reader.ReadStringSafe(); break; case "runtime": { var runtime = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(runtime)) { if (runtime.StartsWith(":", StringComparison.OrdinalIgnoreCase)) { runtime = "0" + runtime; } TimeSpan runtimeTimeSpan; if (TimeSpan.TryParse(runtime, UsCulture, out runtimeTimeSpan)) { info.Video.OriginalRunTimeTicks = runtimeTimeSpan.Ticks; } } break; } case "rating": info.Video.OfficialRating = reader.ReadStringSafe(); break; case "studio": { var studio = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(studio)) { info.Video.AddStudio(studio); } break; } case "postdate": { DateTime date; if (DateTime.TryParse(reader.ReadStringSafe(), UsCulture, DateTimeStyles.None, out date)) { info.PostDate = date.ToUniversalTime(); } break; } case "releasedate": { var val = reader.ReadStringSafe(); if (!string.IsNullOrWhiteSpace(val)) { DateTime date; if (DateTime.TryParse(val, UsCulture, DateTimeStyles.None, out date)) { info.Video.PremiereDate = date.ToUniversalTime(); info.Video.ProductionYear = date.Year; } } break; } case "director": { var directors = reader.ReadStringSafe() ?? string.Empty; foreach (var director in Split(directors, ',', StringSplitOptions.RemoveEmptyEntries)) { var name = director.Trim(); if (!string.IsNullOrWhiteSpace(name)) { info.Video.AddPerson(new PersonInfo { Name = name, Type = PersonType.Director }); } } break; } case "description": info.Video.Overview = reader.ReadStringSafe(); break; default: reader.Skip(); break; } } }