Ejemplo n.º 1
0
        private static bool CreateXmltvFile()
        {
            try
            {
                xmltv = new xmltv
                {
                    Date              = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture),
                    SourceInfoUrl     = "http://schedulesdirect.org",
                    SourceInfoName    = "Schedules Direct",
                    GeneratorInfoName = "EPG123",
                    GeneratorInfoUrl  = "http://epg123.garyan2.net",
                    Channels          = new List <XmltvChannel>(),
                    Programs          = new List <XmltvProgramme>()
                };

                foreach (var service in SdMxf.With.Services)
                {
                    xmltv.Channels.Add(BuildXmltvChannel(service));

                    if (service.MxfScheduleEntries.ScheduleEntry.Count == 0 && config.XmltvAddFillerData)
                    {
                        // add a program specific for this service
                        var program = new MxfProgram
                        {
                            Description = config.XmltvFillerProgramDescription,
                            IsGeneric   = true,
                            Title       = service.Name,
                            ProgramId   = $"EPG123FILL{service.StationId}"
                        };

                        // populate the schedule entries
                        var startTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0);
                        var stopTime  = startTime + TimeSpan.FromDays(config.DaysToDownload);
                        do
                        {
                            service.MxfScheduleEntries.ScheduleEntry.Add(new MxfScheduleEntry
                            {
                                Duration   = config.XmltvFillerProgramLength * 60 * 60,
                                mxfProgram = SdMxf.GetProgram(program.ProgramId, program),
                                StartTime  = startTime,
                                IsRepeat   = true
                            });
                            startTime += TimeSpan.FromHours(config.XmltvFillerProgramLength);
                        } while (startTime < stopTime);
                    }

                    foreach (var scheduleEntry in service.MxfScheduleEntries.ScheduleEntry)
                    {
                        xmltv.Programs.Add(BuildXmltvProgram(scheduleEntry, $"EPG123.{service.StationId}.schedulesdirect.org"));
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.WriteInformation("Failed to create the XMLTV file. Message : " + ex.Message);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static bool BuildMxfFromXmltvGuide(List <hdhrDiscover> homeruns)
        {
            var concatenatedDeviceAuth = string.Empty;
            var channelsDone           = new HashSet <string>();

            foreach (var device in homeruns.Select(homerun => Common.Api.ConnectDevice(homerun.DiscoverUrl)))
            {
                if (device == null || string.IsNullOrEmpty(device.LineupUrl))
                {
                    if (!string.IsNullOrEmpty(device?.DeviceAuth))
                    {
                        concatenatedDeviceAuth += device.DeviceAuth;
                    }
                    continue;
                }

                // determine lineup
                var model       = device.ModelNumber.Split('-')[1];
                var deviceModel = model.Substring(model.Length - 2);
                var mxfLineup   = Common.Mxf.With[0].GetLineup(deviceModel);

                // get channels
                var channels = Common.Api.GetDeviceChannels(device.LineupUrl);
                if (channels == null)
                {
                    continue;
                }
                foreach (var channel in channels)
                {
                    // skip if channel has already been added
                    if (!channelsDone.Add($"{deviceModel} {channel.GuideNumber} {channel.GuideName}"))
                    {
                        continue;
                    }

                    // determine number and subnumber
                    var digits    = channel.GuideNumber.Split('.');
                    var number    = int.Parse(digits[0]);
                    var subnumber = 0;
                    if (digits.Length > 1)
                    {
                        subnumber = int.Parse(digits[1]);
                    }

                    // determine final matchname
                    string matchName = null;
                    switch (deviceModel)
                    {
                    case "US":
                        matchName = $"OC:{number}:{subnumber}";
                        break;

                    case "DT":
                        matchName = $"DVBT:{channel.OriginalNetworkId.Replace(":", "")}:{channel.TransportStreamId.Replace(":", "")}:{channel.ProgramNumber.Replace(":", "")}";
                        break;

                    //case "CC":
                    //case "DC":
                    //case "IS":
                    default:
                        matchName = channel.GuideName;
                        break;
                    }

                    // add channel to the lineup
                    mxfLineup.channels.Add(new MxfChannel()
                    {
                        Lineup    = mxfLineup.Id,
                        LineupUid = mxfLineup.UniqueId,
                        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);
        }