NextPVR Forums

Full Version: Creating .exe for Sky Q Commads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all. I am an experienced developer, but new to using NextPVR. I am looking to use an executable that can take advantage of the Sky Q's capability to be controlled over the local network via NodeJS. I have no idea whether this is possible or not.
A complete list of possible commands the box will accept can be found on this page: https://github.com/dalhundal/sky-remote. I think covers almost all of the functions you can achieve using the Sky Q remote.

An example of some simple NodeJs code looks as below:

Code:
ar SkyRemote = require('sky-remote');

// var remoteControl = new SkyRemote('192.168.1.157', SkyRemote.SKY_Q);
var remoteControl = new SkyRemote('192.168.1.157');

// Simple - just send a command
// remoteControl.press('channelup');

// Nice - send commands with a callback
remoteControl.press(['4', '0', '1', 'select'], function(err) {
    if (err) {
        console.log("Woah! Something went wrong. Cry time.");
    } else {
        console.log("I just pressed the Channel Up command.");
    };
});

Does anyone have any example scripts they use? I am assuming that I may have to do something like write out some dynamic parameters to a text file with the NodeJS code in, then execute that, but I could be barking completely up the wrong tree. All I need really is a toe hold to get me started, then I should be alright from there.

Any help gratefully received.

Thanks
Personally I wouldn't bother with NodeJS. Looking at the code in sky-remote.js in the repository, it's pretty basic what it's doing. It's basically opens a socket, and sends 8 bytes. I'd just make an executable in your language of choice (C#, C++, whatever), and have it do the same steps. It'd probably be like 20 lines of code.
sub Wrote:Personally I wouldn't bother with NodeJS. Looking at the code in sky-remote.js in the repository, it's pretty basic what it's doing. It's basically opens a socket, and sends 8 bytes. I'd just make an executable in your language of choice (C#, C++, whatever), and have it do the same steps. It'd probably be like 20 lines of code.

Hi, thanks for replying. Whilst I am an experienced dev, unfortunately it is not using Javascript based languages, so I am having to make educated guesses at what all of the code is doing. I think what you are saying though is that I need the following steps:

1) Set up a connection to the IP address of my box on port 49160.
2) Pull in the dictionary of key value pairs for Sky Q commands.
3) The numeric value of each command into an 8 byte value using the expression '[4,1,0,0,0,0, Math.floor(224 + (code/16)), code % 16]', where code represents the numeric value of a command from said dictionary.
4) Push this to the box over the above open connection.

I use Python for this sort of stuff, so I would be using the requests module. I may then remap into C++ for my own personal development. Have I misunderstood any of what the JS is doing? Also, I am still a bit unsure about Next PVR executes all of this. I know you create a .exe and point it to that, but how does NPVR pass down say a change channel command to the executable? Can you point me in the direction of any example scripts?

Lastly, as the list of command available could, if executed in the right order go to a given movie and download it to the Sky Q box, can NPVR handle commands like that, or is it strictly on the basis of you select a channel, it pushed a command out to change to that channel.

Thanks again.
gdogg371 Wrote:Hi, thanks for replying. Whilst I am an experienced dev, unfortunately it is not using Javascript based languages, so I am having to make educated guesses at what all of the code is doing. I think what you are saying though is that I need the following steps:

1) Set up a connection to the IP address of my box on port 49160.
2) Pull in the dictionary of key value pairs for Sky Q commands.
3) The numeric value of each command into an 8 byte value using the expression '[4,1,0,0,0,0, Math.floor(224 + (code/16)), code % 16]', where code represents the numeric value of a command from said dictionary.
4) Push this to the box over the above open connection.
Correct.

Quote:I use Python for this sort of stuff, so I would be using the requests module. I may then remap into C++ for my own personal development. Have I misunderstood any of what the JS is doing? Also, I am still a bit unsure about Next PVR executes all of this. I know you create a .exe and point it to that, but how does NPVR pass down say a change channel command to the executable?
NextPVR runs your executable whenever it needs a specific channel for live tv or recording. It passes in the channel number as the first argument when it runs your executable, and your executable is free to do whatever it wants with that channel number. ie, it'd probably break the channel number into digits, and send those digits to your Sky-Q interface. Depending on what is best for this set top box, you might also send an 'enter/select' key after the number.

Quote:Lastly, as the list of command available could, if executed in the right order go to a given movie and download it to the Sky Q box, can NPVR handle commands like that, or is it strictly on the basis of you select a channel, it pushed a command out to change to that channel.
NextPVR wouldn't know anything about your set top box, or what it's menus look like etc. The only time it'd call your executable is to request a specific channel. Anything else, like special features of your set top box, wouldn't be used.
sub Wrote:Correct.

NextPVR runs your executable whenever it needs a specific channel for live tv or recording. It passes in the channel number as the first argument when it runs your executable, and your executable is free to do whatever it wants with that channel number. ie, it'd probably break the channel number into digits, and send those digits to your Sky-Q interface. Depending on what is best for this set top box, you might also send an 'enter/select' key after the number.

NextPVR wouldn't know anything about your set top box, or what it's menus look like etc. The only time it'd call your executable is to request a specific channel. Anything else, like special features of your set top box, wouldn't be used.

Ok, I will write some standalone Python scripts for anything outside of the EPG and call them from Kodi. Do you have an example executable script I could use as a starting point, please? That would be a big help.
gdogg371 Wrote:Do you have an example executable script I could use as a starting point, please?
I'm not sure what you're talking about. Are you talking about Python scripts? I'm not sure if anyone has ever created python sription for this stuff before. I'm not that familiar with Python, so can't give a lot of advice on that front.

From memory, Python is interpreted, so you'd probably need to set the executable to pythonw.exe or similar, and set the args to something like "c:\path\to\your\script.py {channel}", and pythonw.exe would run your script, and pass in the channel number in the place of {channel}. Your python script would do something like this to get the channel number https://stackoverflow.com/questions/4033...-in-python, then follow those steps mentioned earlier for sending the digits to the Sky Q box.

Normally I use compiled languages that create .exe files, and I could just set the channel changer to that. (ie, no scripts required)
sub Wrote:I'm not sure what you're talking about. Are you talking about Python scripts? I'm not sure if anyone has ever created python sription for this stuff before. I'm not that familiar with Python, so can't give a lot of advice on that front.

From memory, Python is interpreted, so you'd probably need to set the executable to pythonw.exe or similar, and set the args to something like "c:\path\to\your\script.py {channel}", and pythonw.exe would run your script, and pass in the channel number in the place of {channel}. Your python script would do something like this to get the channel number https://stackoverflow.com/questions/4033...-in-python, then follow those steps mentioned earlier for sending the digits to the Sky Q box.

Normally I use compiled languages that create .exe files, and I could just set the channel changer to that. (ie, no scripts required)

Sorry for the confusion. What I mean is, do you have an example of the code you would use (in whatever language you prefer) to pass arguments to and change the channels. Thanks.
gdogg371 Wrote:What I mean is, do you have an example of the code you would use (in whatever language you prefer) to pass arguments to and change the channels.
This is pretty much the code it runs:

Code:
args = args.Replace("{channel}", channelMapping.channelNumber.ToString());

                    args = args.Replace("{channel_d1}", channelMapping.channelNumber.ToString("D4")[0].ToString());
                    args = args.Replace("{channel_d2}", channelMapping.channelNumber.ToString("D4")[1].ToString());
                    args = args.Replace("{channel_d3}", channelMapping.channelNumber.ToString("D4")[2].ToString());
                    args = args.Replace("{channel_d4}", channelMapping.channelNumber.ToString("D4")[3].ToString());

                    ProcessStartInfo startInfo = new ProcessStartInfo(executable, args);
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    startInfo.CreateNoWindow = true;
                    startInfo.UseShellExecute = false;

                    Logger.Info("Running blaster: " + executable + " " + args);
                    if (File.Exists(executable))
                    {
                        Process blasterProcess = Process.Start(startInfo);
                        blasterProcess.WaitForExit(20000);
                    }
That's not really important for you though. You just need to know if you don't specify a command line, the channel number is passed as the first argument to the executable. If you have specified a command line, like you need to specify other parameters etc, then {channel} will be replaced with the required channel number.

For your purposes, you can just test it from the command line, independently of NextPVR, until you're happy it's working. ie, just run "something.exe 123" where 123 is the channel number.
sub Wrote:This is pretty much the code it runs:

Code:
args = args.Replace("{channel}", channelMapping.channelNumber.ToString());

                    args = args.Replace("{channel_d1}", channelMapping.channelNumber.ToString("D4")[0].ToString());
                    args = args.Replace("{channel_d2}", channelMapping.channelNumber.ToString("D4")[1].ToString());
                    args = args.Replace("{channel_d3}", channelMapping.channelNumber.ToString("D4")[2].ToString());
                    args = args.Replace("{channel_d4}", channelMapping.channelNumber.ToString("D4")[3].ToString());

                    ProcessStartInfo startInfo = new ProcessStartInfo(executable, args);
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    startInfo.CreateNoWindow = true;
                    startInfo.UseShellExecute = false;

                    Logger.Info("Running blaster: " + executable + " " + args);
                    if (File.Exists(executable))
                    {
                        Process blasterProcess = Process.Start(startInfo);
                        blasterProcess.WaitForExit(20000);
                    }
That's not really important for you though. You just need to know if you don't specify a command line, the channel number is passed as the first argument to the executable. If you have specified a command line, like you need to specify other parameters etc, then {channel} will be replaced with the required channel number.

For your purposes, you can just test it from the command line, independently of NextPVR, until you're happy it's working. ie, just run "something.exe 123" where 123 is the channel number.

Am I missing something here? What I mean is if you have 'Something.exe', what goes in that? is it the code you have posted, or is that from the NVR source code? Apologies if I am asking the wrong questions.
gdogg371 Wrote:Am I missing something here? What I mean is if you have 'Something.exe', what goes in that? is it the code you have posted, or is that from the NVR source code? Apologies if I am asking the wrong questions.

Forgive me if I am stating the bleedin' obvious. NextPVR records TV shows to the hard drive of your computer. NextPVR expects to receive a broadcast stream from some device. The device can be a tuner device that is connected to the NextPVR computer (by PCI or USB or Ethernet). NextPVR communicates with these tuner devices via the device driver and is able to send, for example, channel change commands via the device driver interface.

NextPVR is also able to receive a broadcast stream from a set-top box (STB) via an analogue connection (for example, s-video or composite) into a port on a video capture device such as Hauppauge Colussus. The STB functions as if NextPVR was a human watching TV and controlling the STB using the buttons on a remote control. Typically, there would be a wire from the computer back to the STB with an infra-red emitter that can control the STB (a channel-changer). NextPVR would run a program to send a command to cause the IR emitter to emit IR that would cause the STB to do something ... http://www.nextpvr.com/nwiki/pmwiki.php?...etupDialog ... In most setups this is used to change the channel on the STB.

NextPVR is also able to receive a broadcast stream from a STB via a digital connection, such as HDMI, into a video capture device such as Hauppauge Colussus. Typically, these STBs are also controlled via an IR emitter but there are examples of devices being controlled via a program that sends a channel change command via HDMI.

In summary, NextPVR sends channel change commands to digital tuners via the device driver. NextPVR sends channel change commands to STBs via an IR emitter (usually).

What is it that you want to do with the Sky Q box? You could connect the box to NextPVR via HDMI and use the "network" interface to send channel change commands (as an alternative to using an IR emitter). At the other extreme, you might be able to develop an ecosystem so that the Sky Q box sees the NextPVR computer as several different devices and is able to stream a different channel across the Ethernet to each "device" via Sky Q Multiscreen. You would be able to use NextPVR to record multiple shows simultaneously.

And finally, it may be that that a Sky Q Multiscreen box already does everything that NextPVR can do.
Pages: 1 2