private ChannelMediaInfo GetMediaInfo(TrailerInfo info, bool isHd) { var mediaInfo = new ChannelMediaInfo { Path = info.TrailerUrl, Width = isHd ? 1280 : 720, Height = isHd ? 720 : 480, Container = (Path.GetExtension(info.TrailerUrl) ?? string.Empty).TrimStart('.'), AudioCodec = AudioCodec.AAC, VideoCodec = VideoCodec.H264, AudioChannels = 2, VideoBitrate = isHd ? 11000000 : 1000000, AudioBitrate = isHd ? 128000 : 80000, AudioSampleRate = 44100, Framerate = (float)23.976, VideoProfile = isHd ? "high" : "main", VideoLevel = isHd ? (float)3.1 : 3, SupportsDirectPlay = false }; if (string.Equals(mediaInfo.Container, "mov", StringComparison.OrdinalIgnoreCase)) { mediaInfo.AudioCodec = null; mediaInfo.VideoCodec = null; } mediaInfo.RequiredHttpHeaders.Add("User-Agent", "QuickTime/7.7.4"); return(mediaInfo); }
/// <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 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, ILogger logger) { var trailerInfo = new TrailerInfo { }; reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "info": FetchInfo(reader.ReadSubtree(), trailerInfo, logger); 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); }
private ChannelMediaInfo GetMediaInfo(TrailerInfo info, bool isHd) { var mediaInfo = new ChannelMediaInfo { Path = info.TrailerUrl, Width = isHd ? 1280 : 720, Height = isHd ? 720 : 480, Container = (Path.GetExtension(info.TrailerUrl) ?? string.Empty).TrimStart('.'), AudioCodec = AudioCodec.AAC, VideoCodec = VideoCodec.H264, AudioChannels = 2, VideoBitrate = isHd ? 11000000 : 1000000, AudioBitrate = isHd ? 128000 : 80000, AudioSampleRate = 44100, Framerate = (float)23.976, VideoProfile = isHd ? "high" : "main", VideoLevel = isHd ? (float)3.1 : 3 }; mediaInfo.RequiredHttpHeaders.Add("User-Agent", "QuickTime/7.7.4"); return mediaInfo; }
private ChannelMediaInfo GetMediaInfo(TrailerInfo info, bool isHd) { var mediaInfo = new ChannelMediaInfo { Path = info.TrailerUrl, Width = isHd ? 1280 : 720, Height = isHd ? 720 : 480, Container = (Path.GetExtension(info.TrailerUrl) ?? string.Empty).TrimStart('.'), AudioCodec = AudioCodec.AAC, VideoCodec = VideoCodec.H264, AudioChannels = 2, VideoBitrate = isHd ? 11000000 : 1000000, AudioBitrate = isHd ? 128000 : 80000, AudioSampleRate = 44100, Framerate = (float)23.976, VideoProfile = isHd ? "high" : "main", VideoLevel = isHd ? (float)3.1 : 3, SupportsDirectPlay = false }; mediaInfo.RequiredHttpHeaders.Add("User-Agent", "QuickTime/7.7.4"); return mediaInfo; }
/// <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; } } }