Beispiel #1
0
        private ProgramInfo GetProgram(string channelId, ProgramDto programInfo, ProgramDetailsDto details)
        {
            if (programInfo.AirDateTime == null)
            {
                return(null);
            }

            var startAt   = programInfo.AirDateTime.Value;
            var endAt     = startAt.AddSeconds(programInfo.Duration);
            var audioType = ProgramAudio.Stereo;

            var programId = programInfo.ProgramId ?? string.Empty;

            string newID = programId + "T" + startAt.Ticks + "C" + channelId;

            if (programInfo.AudioProperties.Count != 0)
            {
                if (programInfo.AudioProperties.Contains("atmos", StringComparison.OrdinalIgnoreCase))
                {
                    audioType = ProgramAudio.Atmos;
                }
                else if (programInfo.AudioProperties.Contains("dd 5.1", StringComparison.OrdinalIgnoreCase))
                {
                    audioType = ProgramAudio.DolbyDigital;
                }
                else if (programInfo.AudioProperties.Contains("dd", StringComparison.OrdinalIgnoreCase))
                {
                    audioType = ProgramAudio.DolbyDigital;
                }
                else if (programInfo.AudioProperties.Contains("stereo", StringComparison.OrdinalIgnoreCase))
                {
                    audioType = ProgramAudio.Stereo;
                }
                else
                {
                    audioType = ProgramAudio.Mono;
                }
            }

            string episodeTitle = null;

            if (details.EpisodeTitle150 != null)
            {
                episodeTitle = details.EpisodeTitle150;
            }

            var info = new ProgramInfo
            {
                ChannelId       = channelId,
                Id              = newID,
                StartDate       = startAt,
                EndDate         = endAt,
                Name            = details.Titles[0].Title120 ?? "Unknown",
                OfficialRating  = null,
                CommunityRating = null,
                EpisodeTitle    = episodeTitle,
                Audio           = audioType,
                // IsNew = programInfo.@new ?? false,
                IsRepeat      = programInfo.New == null,
                IsSeries      = string.Equals(details.EntityType, "episode", StringComparison.OrdinalIgnoreCase),
                ImageUrl      = details.PrimaryImage,
                ThumbImageUrl = details.ThumbImage,
                IsKids        = string.Equals(details.Audience, "children", StringComparison.OrdinalIgnoreCase),
                IsSports      = string.Equals(details.EntityType, "sports", StringComparison.OrdinalIgnoreCase),
                IsMovie       = IsMovie(details),
                Etag          = programInfo.Md5,
                IsLive        = string.Equals(programInfo.LiveTapeDelay, "live", StringComparison.OrdinalIgnoreCase),
                IsPremiere    = programInfo.Premiere || (programInfo.IsPremiereOrFinale ?? string.Empty).IndexOf("premiere", StringComparison.OrdinalIgnoreCase) != -1
            };

            var showId = programId;

            if (!info.IsSeries)
            {
                // It's also a series if it starts with SH
                info.IsSeries = showId.StartsWith("SH", StringComparison.OrdinalIgnoreCase) && showId.Length >= 14;
            }

            // According to SchedulesDirect, these are generic, unidentified episodes
            // SH005316560000
            var hasUniqueShowId = !showId.StartsWith("SH", StringComparison.OrdinalIgnoreCase) ||
                                  !showId.EndsWith("0000", StringComparison.OrdinalIgnoreCase);

            if (!hasUniqueShowId)
            {
                showId = newID;
            }

            info.ShowId = showId;

            if (programInfo.VideoProperties != null)
            {
                info.IsHD = programInfo.VideoProperties.Contains("hdtv", StringComparison.OrdinalIgnoreCase);
                info.Is3D = programInfo.VideoProperties.Contains("3d", StringComparison.OrdinalIgnoreCase);
            }

            if (details.ContentRating != null && details.ContentRating.Count > 0)
            {
                info.OfficialRating = details.ContentRating[0].Code.Replace("TV", "TV-", StringComparison.Ordinal)
                                      .Replace("--", "-", StringComparison.Ordinal);

                var invalid = new[] { "N/A", "Approved", "Not Rated", "Passed" };
                if (invalid.Contains(info.OfficialRating, StringComparison.OrdinalIgnoreCase))
                {
                    info.OfficialRating = null;
                }
            }

            if (details.Descriptions != null)
            {
                if (details.Descriptions.Description1000 != null && details.Descriptions.Description1000.Count > 0)
                {
                    info.Overview = details.Descriptions.Description1000[0].Description;
                }
                else if (details.Descriptions.Description100 != null && details.Descriptions.Description100.Count > 0)
                {
                    info.Overview = details.Descriptions.Description100[0].Description;
                }
            }

            if (info.IsSeries)
            {
                info.SeriesId = programId.Substring(0, 10);

                info.SeriesProviderIds[MetadataProvider.Zap2It.ToString()] = info.SeriesId;

                if (details.Metadata != null)
                {
                    foreach (var metadataProgram in details.Metadata)
                    {
                        var gracenote = metadataProgram.Gracenote;
                        if (gracenote != null)
                        {
                            info.SeasonNumber = gracenote.Season;

                            if (gracenote.Episode > 0)
                            {
                                info.EpisodeNumber = gracenote.Episode;
                            }

                            break;
                        }
                    }
                }
            }

            if (details.OriginalAirDate != null)
            {
                info.OriginalAirDate = details.OriginalAirDate;
                info.ProductionYear  = info.OriginalAirDate.Value.Year;
            }

            if (details.Movie != null)
            {
                if (!string.IsNullOrEmpty(details.Movie.Year) &&
                    int.TryParse(details.Movie.Year, out int year))
                {
                    info.ProductionYear = year;
                }
            }

            if (details.Genres != null)
            {
                info.Genres = details.Genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList();
                info.IsNews = details.Genres.Contains("news", StringComparison.OrdinalIgnoreCase);

                if (info.Genres.Contains("children", StringComparison.OrdinalIgnoreCase))
                {
                    info.IsKids = true;
                }
            }

            return(info);
        }
Beispiel #2
0
 private static bool IsMovie(ProgramDetailsDto programInfo)
 {
     return(string.Equals(programInfo.EntityType, "movie", StringComparison.OrdinalIgnoreCase));
 }