private string GetProgramLogo(string apiUrl, ScheduleDirect.ShowImages images) { string url = null; if (images.data != null) { var smallImages = images.data.Where(i => i.size == "Sm").ToList(); if (smallImages.Any()) { images.data = smallImages; } var logoIndex = images.data.FindIndex(i => i.category == "Logo"); if (logoIndex == -1) { logoIndex = 0; } var uri = images.data[logoIndex].uri; if (!string.IsNullOrWhiteSpace(uri)) { if (uri.IndexOf("http", StringComparison.OrdinalIgnoreCase) != -1) { url = uri; } else { url = apiUrl + "/image/" + uri; } } //_logger.Debug("URL for image is : " + url); } return url; }
private ProgramInfo GetProgram(string channel, ScheduleDirect.Program programInfo, ScheduleDirect.ProgramDetails details) { //_logger.Debug("Show type is: " + (details.showType ?? "No ShowType")); DateTime startAt = GetDate(programInfo.airDateTime); DateTime endAt = startAt.AddSeconds(programInfo.duration); ProgramAudio audioType = ProgramAudio.Stereo; bool repeat = programInfo.@new == null; string newID = programInfo.programID + "T" + startAt.Ticks + "C" + channel; if (programInfo.audioProperties != null) { if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd 5.1", StringComparison.OrdinalIgnoreCase))) { audioType = ProgramAudio.DolbyDigital; } else if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd", StringComparison.OrdinalIgnoreCase))) { audioType = ProgramAudio.DolbyDigital; } else if (programInfo.audioProperties.Exists(item => string.Equals(item, "stereo", StringComparison.OrdinalIgnoreCase))) { audioType = ProgramAudio.Stereo; } else { audioType = ProgramAudio.Mono; } } string episodeTitle = null; if (details.episodeTitle150 != null) { episodeTitle = details.episodeTitle150; } string imageUrl = null; if (details.hasImageArtwork) { imageUrl = details.images; } var showType = details.showType ?? string.Empty; var info = new ProgramInfo { ChannelId = channel, Id = newID, StartDate = startAt, EndDate = endAt, Name = details.titles[0].title120 ?? "Unkown", OfficialRating = null, CommunityRating = null, EpisodeTitle = episodeTitle, Audio = audioType, IsRepeat = repeat, IsSeries = showType.IndexOf("series", StringComparison.OrdinalIgnoreCase) != -1, ImageUrl = imageUrl, IsKids = string.Equals(details.audience, "children", StringComparison.OrdinalIgnoreCase), IsSports = showType.IndexOf("sports", StringComparison.OrdinalIgnoreCase) != -1, IsMovie = showType.IndexOf("movie", StringComparison.OrdinalIgnoreCase) != -1 || showType.IndexOf("film", StringComparison.OrdinalIgnoreCase) != -1, ShowId = programInfo.programID, Etag = programInfo.md5 }; if (programInfo.videoProperties != null) { info.IsHD = programInfo.videoProperties.Contains("hdtv", StringComparer.OrdinalIgnoreCase); } if (details.contentRating != null && details.contentRating.Count > 0) { info.OfficialRating = details.contentRating[0].code.Replace("TV", "TV-").Replace("--", "-"); var invalid = new[] { "N/A", "Approved", "Not Rated", "Passed" }; if (invalid.Contains(info.OfficialRating, StringComparer.OrdinalIgnoreCase)) { info.OfficialRating = null; } } if (details.descriptions != null) { if (details.descriptions.description1000 != null) { info.Overview = details.descriptions.description1000[0].description; } else if (details.descriptions.description100 != null) { info.ShortOverview = details.descriptions.description100[0].description; } } if (info.IsSeries) { info.SeriesId = programInfo.programID.Substring(0, 10); if (details.metadata != null) { var gracenote = details.metadata.Find(x => x.Gracenote != null).Gracenote; info.SeasonNumber = gracenote.season; info.EpisodeNumber = gracenote.episode; } } if (!string.IsNullOrWhiteSpace(details.originalAirDate)) { info.OriginalAirDate = DateTime.Parse(details.originalAirDate); } if (details.genres != null) { info.Genres = details.genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList(); info.IsNews = details.genres.Contains("news", StringComparer.OrdinalIgnoreCase); if (info.Genres.Contains("children", StringComparer.OrdinalIgnoreCase)) { info.IsKids = true; } } return info; }
private void AddToChannelPairCache(string listingsId, string channelNumber, ScheduleDirect.Station schChannel) { lock (_channelCacheLock) { Dictionary<string, ScheduleDirect.Station> cache; if (_channelPairingCache.TryGetValue(listingsId, out cache)) { cache[channelNumber] = schChannel; } else { cache = new Dictionary<string, ScheduleDirect.Station>(); cache[channelNumber] = schChannel; _channelPairingCache[listingsId] = cache; } } }
private string GetProgramLogo(string apiUrl, ScheduleDirect.ShowImages images) { string url = ""; if (images.data != null) { var smallImages = images.data.Where(i => i.size == "Sm").ToList(); if (smallImages.Any()) { images.data = smallImages; } var logoIndex = images.data.FindIndex(i => i.category == "Logo"); if (logoIndex == -1) { logoIndex = 0; } if (images.data[logoIndex].uri.Contains("http")) { url = images.data[logoIndex].uri; } else { url = apiUrl + "/image/" + images.data[logoIndex].uri; } //_logger.Debug("URL for image is : " + url); } return url; }
private ProgramInfo GetProgram(string channel, ScheduleDirect.Program programInfo, ScheduleDirect.ProgramDetails details) { _logger.Debug("Show type is: " + (details.showType ?? "No ShowType")); DateTime startAt = DateTime.ParseExact(programInfo.airDateTime, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture); DateTime endAt = startAt.AddSeconds(programInfo.duration); ProgramAudio audioType = ProgramAudio.Stereo; bool hdtv = false; bool repeat = (programInfo.@new == null); string newID = programInfo.programID + "T" + startAt.Ticks + "C" + channel; if (programInfo.audioProperties != null) { if (programInfo.audioProperties.Exists(item => item == "stereo")) { audioType = ProgramAudio.Stereo; } else { audioType = ProgramAudio.Mono; } } if ((programInfo.videoProperties != null)) { hdtv = programInfo.videoProperties.Exists(item => item == "hdtv"); } string desc = ""; if (details.descriptions != null) { if (details.descriptions.description1000 != null) { desc = details.descriptions.description1000[0].description; } else if (details.descriptions.description100 != null) { desc = details.descriptions.description100[0].description; } } ScheduleDirect.Gracenote gracenote; string EpisodeTitle = ""; if (details.metadata != null) { gracenote = details.metadata.Find(x => x.Gracenote != null).Gracenote; if ((details.showType ?? "No ShowType") == "Series") { EpisodeTitle = "Season: " + gracenote.season + " Episode: " + gracenote.episode; } } if (details.episodeTitle150 != null) { EpisodeTitle = EpisodeTitle + " " + details.episodeTitle150; } bool hasImage = false; var imageLink = ""; if (details.hasImageArtwork) { imageLink = details.images; } var info = new ProgramInfo { ChannelId = channel, Id = newID, Overview = desc, StartDate = startAt, EndDate = endAt, Genres = new List<string>() {"N/A"}, Name = details.titles[0].title120 ?? "Unkown", OfficialRating = "0", CommunityRating = null, EpisodeTitle = EpisodeTitle, Audio = audioType, IsHD = hdtv, IsRepeat = repeat, IsSeries = ((details.showType ?? "No ShowType") == "Series") || (details.showType ?? "No ShowType") == "Miniseries", ImageUrl = imageLink, HasImage = details.hasImageArtwork, IsNews = false, IsKids = false, IsSports = ((details.showType ?? "No ShowType") == "Sports non-event") || (details.showType ?? "No ShowType") == "Sports event", IsLive = false, IsMovie = (details.showType ?? "No ShowType") == "Feature Film" || (details.showType ?? "No ShowType") == "TV Movie" || (details.showType ?? "No ShowType") == "Short Film", IsPremiere = false, }; //logger.Info("Done init"); if (null != details.originalAirDate) { info.OriginalAirDate = DateTime.Parse(details.originalAirDate); } if (details.genres != null) { info.Genres = details.genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList(); info.IsNews = details.genres.Contains("news", StringComparer.OrdinalIgnoreCase); info.IsKids = false; } return info; }
private int GetSizeOrder(ScheduleDirect.ImageData image) { if (!string.IsNullOrWhiteSpace(image.height)) { int value; if (int.TryParse(image.height, out value)) { return value; } } return 0; }