/// <summary> /// Parse the section. /// </summary> /// <param name="byteData">The MPEG2 section containing the section.</param> /// <param name="mpeg2Header">The MPEG2 header that preceedes the section.</param> public void Process(byte[] byteData, Mpeg2ExtendedHeader mpeg2Header) { lastIndex = mpeg2Header.Index; serviceID = mpeg2Header.TableIDExtension; try { transportStreamID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; originalNetworkID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; segmentLastSectionNumber = (int)byteData[lastIndex]; lastIndex++; lastTableID = (int)byteData[lastIndex]; lastIndex++; } catch (IndexOutOfRangeException) { throw (new ArgumentOutOfRangeException("The Bell TV section is short")); } TVStation tvStation = TVStation.FindStation(originalNetworkID, transportStreamID, serviceID); if (tvStation == null) { if (!RunParameters.Instance.DebugIDs.Contains("CREATESTATIONS")) { return; } else { tvStation = new TVStation("Auto Generated Station: " + originalNetworkID + ":" + transportStreamID + ":" + serviceID); tvStation.OriginalNetworkID = originalNetworkID; tvStation.TransportStreamID = transportStreamID; tvStation.ServiceID = serviceID; TVStation.StationCollection.Add(tvStation); } } bool newSection = tvStation.AddMapEntry(mpeg2Header.TableID, mpeg2Header.SectionNumber, lastTableID, mpeg2Header.LastSectionNumber, segmentLastSectionNumber); if (!newSection) { return; } while (lastIndex < byteData.Length - 4) { BellTVEntry bellTVEntry = new BellTVEntry(); bellTVEntry.Process(byteData, lastIndex, mpeg2Header.TableID); EPGEntry epgEntry = new EPGEntry(); epgEntry.OriginalNetworkID = tvStation.OriginalNetworkID; epgEntry.TransportStreamID = tvStation.TransportStreamID; epgEntry.ServiceID = tvStation.ServiceID; epgEntry.EPGSource = EPGSource.BellTV; if (bellTVEntry.HighDefinition) { epgEntry.VideoQuality = "HDTV"; } if (bellTVEntry.ClosedCaptions) { epgEntry.SubTitles = "teletext"; } if (bellTVEntry.Stereo) { epgEntry.AudioQuality = "stereo"; } epgEntry.Duration = Utils.RoundTime(bellTVEntry.Duration); epgEntry.EventID = bellTVEntry.EventID; epgEntry.EventName = bellTVEntry.EventName; getParentalRating(epgEntry, bellTVEntry); epgEntry.RunningStatus = bellTVEntry.RunningStatus; epgEntry.Scrambled = bellTVEntry.Scrambled; epgEntry.ShortDescription = bellTVEntry.ShortDescription; if (bellTVEntry.SubTitle != bellTVEntry.EventName) { epgEntry.EventSubTitle = bellTVEntry.SubTitle; } epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetOffsetTime(bellTVEntry.StartTime)); epgEntry.EventCategory = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, bellTVEntry.ContentType, bellTVEntry.ContentSubType); epgEntry.StarRating = getStarRating(bellTVEntry); epgEntry.Date = bellTVEntry.Date; epgEntry.Cast = bellTVEntry.Cast; getSeriesEpisode(epgEntry, bellTVEntry.Series, bellTVEntry.Episode); epgEntry.HasGraphicLanguage = bellTVEntry.HasStrongLanguage; epgEntry.HasStrongSexualContent = bellTVEntry.HasSexualContent; epgEntry.HasGraphicViolence = bellTVEntry.HasViolence; epgEntry.HasNudity = bellTVEntry.HasNudity; epgEntry.PreviousPlayDate = bellTVEntry.OriginalAirDate; tvStation.AddEPGEntry(epgEntry); if (titleLogger != null) { logTitle(bellTVEntry.EventName, epgEntry, titleLogger); } if (descriptionLogger != null) { if (!RunParameters.Instance.DebugIDs.Contains("LOGORIGINAL")) { logDescription(bellTVEntry.ShortDescription, epgEntry, descriptionLogger); } else { logDescription(bellTVEntry.OriginalDescription, epgEntry, descriptionLogger); } } lastIndex = bellTVEntry.Index; } }
/// <summary> /// Parse the section. /// </summary> /// <param name="byteData">The MPEG2 section containing the section.</param> /// <param name="mpeg2Header">The MPEG2 header that preceedes the section.</param> public void Process(byte[] byteData, Mpeg2ExtendedHeader mpeg2Header) { lastIndex = mpeg2Header.Index; serviceID = mpeg2Header.TableIDExtension; transportStreamID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; originalNetworkID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; segmentLastSectionNumber = (int)byteData[lastIndex]; lastIndex++; lastTableID = (int)byteData[lastIndex]; lastIndex++; TVStation tvStation = TVStation.FindStation(originalNetworkID, transportStreamID, serviceID); if (tvStation == null) { if (!RunParameters.Instance.DebugIDs.Contains("CREATESTATIONS")) { return; } else { tvStation = new TVStation("Auto Generated Station: " + originalNetworkID + ":" + transportStreamID + ":" + serviceID); tvStation.OriginalNetworkID = originalNetworkID; tvStation.TransportStreamID = transportStreamID; tvStation.ServiceID = serviceID; TVStation.StationCollection.Add(tvStation); } } bool newSection = tvStation.AddMapEntry(mpeg2Header.TableID, mpeg2Header.SectionNumber, lastTableID, mpeg2Header.LastSectionNumber, segmentLastSectionNumber); if (!newSection) { return; } while (lastIndex < byteData.Length - 4) { EITEntry eitEntry = new EITEntry(); eitEntry.Process(byteData, lastIndex); if (eitEntry.StartTime != DateTime.MinValue) { EPGEntry epgEntry = new EPGEntry(); epgEntry.OriginalNetworkID = tvStation.OriginalNetworkID; epgEntry.TransportStreamID = tvStation.TransportStreamID; epgEntry.ServiceID = tvStation.ServiceID; epgEntry.EPGSource = EPGSource.EIT; switch (eitEntry.ComponentTypeAudio) { case 3: epgEntry.AudioQuality = "stereo"; break; case 5: epgEntry.AudioQuality = "dolby digital"; break; default: break; } if (eitEntry.ComponentTypeVideo > 9) { epgEntry.VideoQuality = "HDTV"; } if (!RunParameters.Instance.Options.Contains("USEDESCASCATEGORY")) { epgEntry.EventCategory = getEventCategory(eitEntry.EventName, eitEntry.Description, eitEntry.ContentType, eitEntry.ContentSubType); } else { epgEntry.EventCategory = eitEntry.ShortDescription; } epgEntry.Duration = Utils.RoundTime(eitEntry.Duration); epgEntry.EventID = eitEntry.EventID; epgEntry.EventName = eitEntry.EventName; if (RunParameters.Instance.CountryCode != null) { epgEntry.ParentalRating = ParentalRating.FindRating(RunParameters.Instance.CountryCode, "EIT", (eitEntry.ParentalRating + 3).ToString()); epgEntry.MpaaParentalRating = ParentalRating.FindMpaaRating(RunParameters.Instance.CountryCode, "EIT", (eitEntry.ParentalRating + 3).ToString()); } else { if (eitEntry.ParentalRating > 11) { epgEntry.ParentalRating = "AO"; epgEntry.MpaaParentalRating = "AO"; } else { if (eitEntry.ParentalRating > 8) { epgEntry.ParentalRating = "PGR"; epgEntry.MpaaParentalRating = "PG"; } else { epgEntry.ParentalRating = "G"; epgEntry.MpaaParentalRating = "G"; } } } epgEntry.RunningStatus = eitEntry.RunningStatus; epgEntry.Scrambled = eitEntry.Scrambled; if (!RunParameters.Instance.Options.Contains("USEDESCASCATEGORY")) { epgEntry.ShortDescription = eitEntry.Description; } else { epgEntry.ShortDescription = eitEntry.ExtendedDescription; } epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetOffsetTime(eitEntry.StartTime)); epgEntry.Cast = eitEntry.Cast; epgEntry.Directors = eitEntry.Directors; epgEntry.Date = eitEntry.Year; if (eitEntry.TVRating != null) { epgEntry.ParentalRating = eitEntry.TVRating; } epgEntry.StarRating = eitEntry.StarRating; if (eitEntry.TVRating != null) { epgEntry.ParentalRating = eitEntry.TVRating; } setSeriesEpisode(epgEntry, eitEntry); /*if (eitEntry.PreviousPlayDate != null) * { * try * { * TimeSpan offset = new TimeSpan(Int32.Parse(eitEntry.PreviousPlayDate) * TimeSpan.TicksPerSecond); * epgEntry.PreviousPlayDate = epgEntry.StartTime - offset; * } * catch (FormatException) { } * }*/ epgEntry.Country = eitEntry.Country; tvStation.AddEPGEntry(epgEntry); if (titleLogger != null) { logTitle(eitEntry.EventName, eitEntry, epgEntry, titleLogger); } if (descriptionLogger != null) { logTitle(eitEntry.Description, eitEntry, epgEntry, descriptionLogger); } if (RunParameters.Instance.DebugIDs.Contains("CATXREF")) { updateCategoryEntries(tvStation, eitEntry); } } lastIndex = eitEntry.Index; } }
/// <summary> /// Create the EPG entries from the stored title and summary data. /// </summary> /// <param name="station">The station that the EPG records are for.</param> /// <param name="titleLogger">A Logger instance for the program titles.</param> /// <param name="descriptionLogger">A Logger instance for the program descriptions.</param> /// <param name="collectionType">The type of collection, MHW1 or MHW2.</param> public void ProcessChannelForEPG(TVStation station, Logger titleLogger, Logger descriptionLogger, CollectionType collectionType) { bool first = true; DateTime expectedStartTime = new DateTime(); foreach (MediaHighwayTitle title in Titles) { EPGEntry epgEntry = new EPGEntry(); epgEntry.OriginalNetworkID = OriginalNetworkID; epgEntry.TransportStreamID = TransportStreamID; epgEntry.ServiceID = ServiceID; epgEntry.EventID = title.EventID; processEventName(epgEntry, title.EventName); MediaHighwaySummary summary = null; if (title.SummaryAvailable) { summary = findSummary(title.EventID); if (summary != null) { processShortDescription(epgEntry, summary.ShortDescription); } else { if (RunParameters.Instance.DebugIDs.Contains("MHW2SUMMARYMISSING")) { Logger.Instance.Write("Summary missing for event ID " + title.EventID); } } } if (summary == null) { epgEntry.ShortDescription = "No Synopsis Available"; } if (collectionType == CollectionType.MediaHighway1) { epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetOffsetTime(title.StartTime)); } else { epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetAdjustedTime(title.StartTime)); } epgEntry.Duration = Utils.RoundTime(title.Duration); epgEntry.EventCategory = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, title.CategoryID); if (collectionType == CollectionType.MediaHighway1) { epgEntry.EPGSource = EPGSource.MediaHighway1; } else { epgEntry.EPGSource = EPGSource.MediaHighway2; } epgEntry.VideoQuality = getVideoQuality(epgEntry.EventName); epgEntry.PreviousPlayDate = title.PreviousPlayDate; station.AddEPGEntry(epgEntry); if (first) { expectedStartTime = new DateTime(); first = false; } else { if (epgEntry.StartTime < expectedStartTime) { if (titleLogger != null) { titleLogger.Write(" ** Overlap In Schedule **"); } } else { if (RunParameters.Instance.Options.Contains("ACCEPTBREAKS")) { if (epgEntry.StartTime > expectedStartTime + new TimeSpan(0, 5, 0)) { if (titleLogger != null) { titleLogger.Write(" ** Gap In Schedule **"); } } } else { if (epgEntry.StartTime > expectedStartTime) { if (titleLogger != null) { titleLogger.Write(" ** Gap In Schedule **"); } } } } } expectedStartTime = epgEntry.StartTime + epgEntry.Duration; if (titleLogger != null) { if (collectionType == CollectionType.MediaHighway1) { titleLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " + " Evt ID " + title.EventID + " Cat ID " + title.CategoryID.ToString("00") + " Summary " + title.SummaryAvailable + ":" + (summary != null) + " " + " Orig Day " + title.LogDay + " Orig Hours " + title.LogHours + " YDay " + title.LogYesterday + " Day " + title.Day + " Hours " + title.Hours + " Mins " + title.Minutes + " " + epgEntry.StartTime.ToShortDateString() + " " + epgEntry.StartTime.ToString("HH:mm") + " - " + epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " + title.EventName); } else { titleLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " + " Evt ID " + title.EventID + " Cat ID " + title.CategoryID.ToString("000") + " Main cat " + title.MainCategory + " Sub cat " + title.SubCategory + " Summary " + title.SummaryAvailable + ":" + (summary != null) + " Unknown " + Utils.ConvertToHex(title.Unknown) + " " + epgEntry.StartTime.ToShortDateString() + " " + epgEntry.StartTime.ToString("HH:mm") + " - " + epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " + title.EventName); } } if (descriptionLogger != null && summary != null) { if (collectionType == CollectionType.MediaHighway1) { descriptionLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " + " Evt ID " + title.EventID + " Rpts: " + summary.ReplayCount + " " + epgEntry.StartTime.ToShortDateString() + " " + epgEntry.StartTime.ToString("HH:mm") + " - " + epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " + summary.ShortDescription); } else { descriptionLogger.Write(epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + " " + " Evt ID " + title.EventID + " " + " Unknown " + Utils.ConvertToHex(summary.Unknown) + " " + epgEntry.StartTime.ToShortDateString() + " " + epgEntry.StartTime.ToString("HH:mm") + " - " + epgEntry.StartTime.Add(epgEntry.Duration).ToString("HH:mm") + " " + summary.ShortDescription); } } if (!RunParameters.Instance.Options.Contains("ACCEPTBREAKS")) { if (epgEntry.StartTime.Second != 0) { if (titleLogger != null) { titleLogger.Write("** Suspect Start Time **"); } } } } }
/// <summary> /// Parse the section. /// </summary> /// <param name="byteData">The MPEG2 section containing the section.</param> /// <param name="mpeg2Header">The MPEG2 header that preceedes the section.</param> public void Process(byte[] byteData, Mpeg2ExtendedHeader mpeg2Header) { lastIndex = mpeg2Header.Index; serviceID = mpeg2Header.TableIDExtension; try { transportStreamID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; originalNetworkID = Utils.Convert2BytesToInt(byteData, lastIndex); lastIndex += 2; segmentLastSectionNumber = (int)byteData[lastIndex]; lastIndex++; lastTableID = (int)byteData[lastIndex]; lastIndex++; } catch (IndexOutOfRangeException) { throw (new ArgumentOutOfRangeException("The FreeSat EIT section is short")); } TVStation tvStation = TVStation.FindStation(originalNetworkID, transportStreamID, serviceID); if (tvStation == null) { return; } bool newSection = tvStation.AddMapEntry(mpeg2Header.TableID, mpeg2Header.SectionNumber, lastTableID, mpeg2Header.LastSectionNumber, segmentLastSectionNumber); if (!newSection) { return; } while (lastIndex < byteData.Length - 4) { FreeSatEntry freeSatEntry = new FreeSatEntry(); freeSatEntry.Process(byteData, lastIndex); EPGEntry epgEntry = new EPGEntry(); epgEntry.OriginalNetworkID = tvStation.OriginalNetworkID; epgEntry.TransportStreamID = tvStation.TransportStreamID; epgEntry.ServiceID = tvStation.ServiceID; epgEntry.EPGSource = EPGSource.FreeSat; switch (freeSatEntry.ComponentTypeAudio) { case 3: epgEntry.AudioQuality = "stereo"; break; case 5: epgEntry.AudioQuality = "dolby digital"; break; default: break; } if (freeSatEntry.ComponentTypeVideo > 9) { epgEntry.VideoQuality = "HDTV"; } epgEntry.Duration = Utils.RoundTime(freeSatEntry.Duration); epgEntry.EventID = freeSatEntry.EventID; epgEntry.EventName = freeSatEntry.EventName; if (freeSatEntry.ParentalRating > 11) { epgEntry.ParentalRating = "AO"; } else { if (freeSatEntry.ParentalRating > 8) { epgEntry.ParentalRating = "PGR"; } else { epgEntry.ParentalRating = "G"; } } setSeriesEpisode(epgEntry, freeSatEntry); epgEntry.RunningStatus = freeSatEntry.RunningStatus; epgEntry.Scrambled = freeSatEntry.Scrambled; epgEntry.ShortDescription = freeSatEntry.ShortDescription; epgEntry.StartTime = Utils.RoundTime(TimeOffsetEntry.GetOffsetTime(freeSatEntry.StartTime)); epgEntry.EventCategory = getEventCategory(epgEntry.EventName, epgEntry.ShortDescription, freeSatEntry.ContentType, freeSatEntry.ContentSubType); tvStation.AddEPGEntry(epgEntry); if (titleLogger != null) { logTitle(freeSatEntry.EventName, epgEntry, titleLogger); } if (descriptionLogger != null) { logDescription(freeSatEntry.ShortDescription, epgEntry, descriptionLogger); } lastIndex = freeSatEntry.Index; } }