Example #1
0
        private ProgramInfo GetProgram(string channelId, 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" + channelId;

            if (programInfo.audioProperties != null)
            {
                if (programInfo.audioProperties.Exists(item => string.Equals(item, "atmos", StringComparison.OrdinalIgnoreCase)))
                {
                    audioType = ProgramAudio.Atmos;
                }
                else 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;
            }

            var showType = details.showType ?? string.Empty;

            var info = new ProgramInfo
            {
                ChannelId       = channelId,
                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        = details.primaryImage,
                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,
                Etag            = programInfo.md5
            };

            var showId = programInfo.programID ?? string.Empty;

            // 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", StringComparer.OrdinalIgnoreCase);
                info.Is3D = programInfo.videoProperties.Contains("3d", 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.Overview = 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.IsSeries || info.IsRepeat))
            {
                info.OriginalAirDate = DateTime.Parse(details.originalAirDate);
                info.ProductionYear  = info.OriginalAirDate.Value.Year;
            }

            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);
        }
Example #2
0
        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   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,
                HasImage        = details.hasImageArtwork,
                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);
        }
Example #3
0
        private ProgramInfo GetProgram(string channelId, ScheduleDirect.Program programInfo, ScheduleDirect.ProgramDetails details)
        {
            var startAt   = GetDate(programInfo.airDateTime);
            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 != null)
            {
                if (programInfo.audioProperties.Exists(item => string.Equals(item, "atmos", StringComparison.OrdinalIgnoreCase)))
                {
                    audioType = ProgramAudio.Atmos;
                }
                else 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;
            }

            var info = new ProgramInfo
            {
                ChannelId       = channelId,
                Id              = newID,
                StartDate       = startAt,
                EndDate         = endAt,
                Name            = details.titles[0].title120 ?? "Unkown",
                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", StringComparer.OrdinalIgnoreCase);
                info.Is3D = programInfo.videoProperties.Contains("3d", 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 && 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 (!string.IsNullOrWhiteSpace(details.originalAirDate))
            {
                info.OriginalAirDate = DateTime.Parse(details.originalAirDate, CultureInfo.InvariantCulture);
                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", StringComparer.OrdinalIgnoreCase);

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

            return(info);
        }
        private ProgramInfo GetProgram(string channel, ScheduleDirect.Program programInfo,
                                       ScheduleDirect.ProgramDetails details)
        {
            _logger.Info("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;
                }
            }
            if (details.episodeTitle150 != null)
            {
                EpisodeTitle = EpisodeTitle + " " + details.episodeTitle150;
            }
            bool hasImage  = false;
            var  imageLink = "";

            if (details.hasImageArtwork)
            {
                hasImage  = true;
                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 = hasImage,
                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);
        }