Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
        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);
        }