示例#1
0
        static bool DetermineUpdateMethod()
        {
            // find all HDHomeRun tuning devices on the network
            var homeruns = Common.api.DiscoverDevices();

            if (homeruns == null || homeruns.Count() == 0)
            {
                Console.WriteLine("No HDHomeRun devices were found.");
                return(false);
            }

            // determine if DVR Service is active
            bool dvrActive = false;

            foreach (HDHRDiscover homerun in homeruns)
            {
                HDHRDevice device = Common.api.ConnectDevice(homerun.DiscoverURL);
                if (device == null)
                {
                    continue;
                }
                else
                {
                    Console.WriteLine(string.Format("Found {0} {1} ({2}) with firmware {3}.", device.FriendlyName, device.ModelNumber, device.DeviceID, device.FirmwareVersion));
                }

                dvrActive |= Common.api.IsDvrActive(device.DeviceAuth);
            }
            Console.WriteLine(string.Format("HDHomeRun DVR Service is {0}active.", dvrActive ? string.Empty : "not "));

            // if DVR Service is active, use XMLTV; otherwise use iterative load from slice guide
            if (dvrActive)
            {
                Console.WriteLine("Using available 14-day XMLTV file from SiliconDust.");
                return(XmltvMxf.BuildMxfFromXmltvGuide(homeruns.ToList()));
            }
            else if (false)// (!xmltvOnly)
            {
                Console.WriteLine("Using available 24-hour slice guide data from SiliconDust.");
                return(SliceMxf.BuildMxfFromSliceGuide(homeruns.ToList()));
            }
            else
            {
                Console.WriteLine("HDHR2MXF is not configured to download guide data using JSON from SiliconDust.");
                return(false);
            }
        }
示例#2
0
        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);
        }
示例#3
0
        public static bool BuildMxfFromSliceGuide(List <HDHRDiscover> homeruns)
        {
            // scan each device for tuned channels and associated programs
            foreach (HDHRDiscover homerun in homeruns)
            {
                HDHRDevice device = Common.api.ConnectDevice(homerun.DiscoverURL);
                if (device == null || string.IsNullOrEmpty(device.LineupURL))
                {
                    continue;
                }
                else
                {
                    Console.WriteLine(string.Format("Processing {0} {1} ({2}) with firmware {3}.", device.FriendlyName, device.ModelNumber, device.DeviceID, device.FirmwareVersion));
                }

                // get channels
                List <HDHRChannel> channels = Common.api.GetDeviceChannels(device.LineupURL);
                if (channels == null)
                {
                    continue;
                }

                // determine lineup
                string    model       = device.ModelNumber.Split('-')[1];
                string    deviceModel = model.Substring(model.Length - 2);
                MxfLineup mxfLineup   = Common.mxf.With[0].getLineup(deviceModel);

                foreach (HDHRChannel channel in channels)
                {
                    int startTime = 0;
                    List <HDHRChannelGuide> programs = Common.api.GetChannelGuide(device.DeviceAuth, channel.GuideNumber, startTime);
                    if (programs == null)
                    {
                        continue;
                    }

                    // build the service
                    MxfService mxfService = Common.mxf.With[0].getService(programs[0].GuideName);
                    if (string.IsNullOrEmpty(mxfService.CallSign))
                    {
                        mxfService.CallSign  = programs[0].GuideName;
                        mxfService.Name      = channel.GuideName;
                        mxfService.Affiliate = (!string.IsNullOrEmpty(programs[0].Affiliate)) ? Common.mxf.With[0].getAffiliateId(programs[0].Affiliate) : null;
                        mxfService.LogoImage = (!Common.noLogos && !string.IsNullOrEmpty(programs[0].ImageURL)) ? Common.mxf.With[0].getGuideImage(programs[0].ImageURL).Id : null;
                        mxfService.mxfScheduleEntries.Service = mxfService.Id;
                    }

                    // add channel to the lineup
                    if (int.TryParse(channel.GuideNumber, out int iChannel) || double.TryParse(channel.GuideNumber, out double dChannel))
                    {
                        string[] digits    = channel.GuideNumber.Split('.');
                        int      number    = int.Parse(digits[0]);
                        int      subnumber = 0;
                        if (digits.Length > 1)
                        {
                            subnumber = int.Parse(digits[1]);
                        }

                        // add the channel to the lineup and make sure we don't duplicate channels
                        var vchan = mxfLineup.channels.Where(arg => arg.Service == mxfService.Id)
                                    .Where(arg => arg.Number == number)
                                    .Where(arg => arg.SubNumber == subnumber)
                                    .SingleOrDefault();
                        if (vchan == null)
                        {
                            string matchname = null;
                            switch (deviceModel)
                            {
                            case "US":      // ATSC
                                matchname = string.Format("OC:{0}:{1}", number, subnumber);
                                break;

                            case "DT":      // DVB-T
                                matchname = string.Format("DVBT:{0}:{1}:{2}", channel.OriginalNetworkID, channel.TransportStreamID, channel.ProgramNumber);
                                break;

                            case "CC":      // US CableCARD
                                matchname = mxfService.Name;
                                break;

                            case "IS":      // ISDB
                            case "DC":      // DVB-C
                            default:
                                matchname = mxfService.Name;
                                break;
                            }

                            mxfLineup.channels.Add(new MxfChannel()
                            {
                                Lineup    = mxfLineup.Id,
                                lineupUid = mxfLineup.Uid,
                                stationId = mxfService.CallSign,
                                Service   = mxfService.Id,
                                Number    = number,
                                SubNumber = subnumber,
                                MatchName = matchname
                            });
                            Console.WriteLine(string.Format("--Processing station {0} on channel {1}{2}.",
                                                            mxfService.CallSign, number, (subnumber > 0) ? "." + subnumber.ToString() : string.Empty));
                        }
                    }

                    // if this channel's listings are already done, stop here
                    if (!Common.channelsDone.Add(mxfService.CallSign))
                    {
                        continue;
                    }

                    // build the programs
                    do
                    {
                        foreach (HDHRProgram program in programs[0].Guide)
                        {
                            // establish the program ID
                            string programID = program.SeriesID;
                            if (!string.IsNullOrEmpty(program.EpisodeNumber))
                            {
                                programID += "_" + program.EpisodeNumber;
                            }
                            else if (!programID.StartsWith("MV"))
                            {
                                programID += "_" + program.GetHashCode().ToString();
                            }

                            // create an mxf program
                            MxfProgram mxfProgram = new MxfProgram()
                            {
                                index = Common.mxf.With[0].Programs.Count + 1
                            };
                            mxfProgram.programId = programID;

                            // create the schedule entry and program if needed
                            string start = program.StartDateTime.ToString("yyyy-MM-ddTHH:mm:ss");
                            if (program.StartDateTime == mxfService.mxfScheduleEntries.endTime)
                            {
                                start = null;
                            }
                            mxfService.mxfScheduleEntries.ScheduleEntry.Add(new MxfScheduleEntry()
                            {
                                Duration  = program.EndTime - program.StartTime,
                                IsHdtv    = channel.HD ? "true" : null,
                                Program   = Common.mxf.With[0].getProgram(programID, mxfProgram).Id,
                                StartTime = start
                            });

                            // build the program
                            BuildProgram(programID, program);

                            startTime = program.EndTime;
                        }
                    } while ((programs = Common.api.GetChannelGuide(device.DeviceAuth, channel.GuideNumber, startTime)) != null);
                }
            }
            return(true);
        }