public static bool BuildMxfFromXmltvGuide(List <HDHRDiscover> homeruns) { string concatenatedDeviceAuth = string.Empty; HashSet <string> ChannelsDone = new HashSet <string>(); foreach (HDHRDiscover homerun in homeruns) { // connect to the device HDHRDevice device = Common.api.ConnectDevice(homerun.DiscoverURL); if (device == null || string.IsNullOrEmpty(device.LineupURL)) { if (!string.IsNullOrEmpty(device?.DeviceAuth)) { concatenatedDeviceAuth += device.DeviceAuth; } continue; } // determine lineup string model = device.ModelNumber.Split('-')[1]; string deviceModel = model.Substring(model.Length - 2); MxfLineup mxfLineup = Common.mxf.With[0].getLineup(deviceModel); // get channels List <HDHRChannel> channels = Common.api.GetDeviceChannels(device.LineupURL); if (channels == null) { continue; } foreach (HDHRChannel channel in channels) { // skip if channel has already been added if (!ChannelsDone.Add(string.Format("{0} {1} {2}", deviceModel, channel.GuideNumber, channel.GuideName))) { continue; } // determine number and subnumber string[] digits = channel.GuideNumber.Split('.'); int number = int.Parse(digits[0]); int subnumber = 0; if (digits.Length > 1) { subnumber = int.Parse(digits[1]); } // determine final matchname string matchName = null; switch (deviceModel) { case "US": matchName = string.Format("OC:{0}:{1}", number, subnumber); break; case "DT": matchName = string.Format("DVBT:{0}:{1}:{2}", channel.OriginalNetworkID.Replace(":", ""), channel.TransportStreamID.Replace(":", ""), channel.ProgramNumber.Replace(":", "")); break; case "CC": case "DC": case "IS": default: break; } // add channel to the lineup mxfLineup.channels.Add(new MxfChannel() { Lineup = mxfLineup.Id, lineupUid = mxfLineup.uid_, MatchName = channel.GuideName.ToUpper(), Number = number, SubNumber = subnumber, match = matchName, isHD = channel.HD }); } concatenatedDeviceAuth += device.DeviceAuth; } if ((xmltv = Common.api.GetHdhrXmltvGuide(concatenatedDeviceAuth)) == null) { return(false); } BuildLineupServices(); BuildScheduleEntries(); return(true); }
private static bool CreateXmltvFile() { try { xmltv = new XMLTV() { Date = DateTime.UtcNow.ToString(), SourceInfoUrl = "http://schedulesdirect.org", SourceInfoName = "Schedules Direct", GeneratorInfoName = "EPG123", GeneratorInfoUrl = "http://epg123.garyan2.net", Channels = new List <XmltvChannel>(), Programs = new List <XmltvProgramme>() }; foreach (MxfLineup lineup in sdMxf.With[0].Lineups) { foreach (MxfChannel channel in lineup.channels) { xmltv.Channels.Add(buildXmltvChannel(channel)); } } foreach (MxfService service in sdMxf.With[0].Services) { DateTime startTime = new DateTime(); if (service.mxfScheduleEntries.ScheduleEntry.Count == 0 && config.XmltvAddFillerData) { // add a program specific for this service MxfProgram program = new MxfProgram() { Description = config.XmltvFillerProgramDescription, IsGeneric = "true", Title = service.Name, tmsId = string.Format("EPG123FILL{0}", service.StationID), index = sdMxf.With[0].Programs.Count + 1, jsonProgramData = new sdProgram() }; // populate the schedule entries startTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0); DateTime stopTime = startTime + TimeSpan.FromDays(config.DaysToDownload); do { service.mxfScheduleEntries.ScheduleEntry.Add(new MxfScheduleEntry() { Duration = config.XmltvFillerProgramLength * 60 * 60, Program = sdMxf.With[0].getProgram(program.tmsId, program).Id, StartTime = startTime.ToString("yyyy-MM-ddTHH:mm:ss"), IsRepeat = "true" }); startTime += TimeSpan.FromHours((double)config.XmltvFillerProgramLength); } while (startTime < stopTime); } foreach (MxfScheduleEntry scheduleEntry in service.mxfScheduleEntries.ScheduleEntry) { if (!string.IsNullOrEmpty(scheduleEntry.StartTime)) { startTime = DateTime.Parse(scheduleEntry.StartTime + "Z").ToUniversalTime(); } xmltv.Programs.Add(buildXmltvProgram(scheduleEntry, startTime, service.xmltvChannelID, out startTime)); } } return(true); } catch (Exception ex) { Logger.WriteInformation("Failed to create the XMLTV file. Message : " + ex.Message); } return(false); }