Scripting functions? (1 Viewer)

JDWestoby

MP Donator
  • Premium Supporter
  • April 9, 2008
    265
    32
    69
    Poltimore, Devon
    Home Country
    United Kingdom United Kingdom
    Dear All

    Scripting (in this context) puts a 'human' interface to what [MediaPortal] can do.


    I wondered if anyone had thoughts about what scripting functions might be useful.

    So instead of a series of database/tuner C# procedure calls you would make a string like 'Record channel four now for one hour' or just simply 'TV on' or even 'Press six'

    I want to do this to be able to use HomeSeer invoke certain MediaPortal functions and this while not the easiest solution is the most flexible.

    (In fact this is the exact reverse of my MediaPortal to HomeSeer plugin, so the techniques are well proven. You can drie this using Telnet!)

    It would allow a non developer to make MediaPortal dance exactly how they want without having to learn the intricacies of driving MediaPortal programmatically.

    I haven't seen anything like this in MediaPortal so I assume it isn't around.

    I'll start my own list but anyone have any thoughts?
     

    cheezey

    Community Plugin Dev
    August 26, 2004
    1,560
    312
    56
    West Yorks, UK
    Home Country
    United Kingdom United Kingdom
    iPiMP has the MPCC process plugin which provides many of these features via a JSON interface, allowing remote access to control your mediaportal client and tv server. You can call the interface via tcp or http, it's currently used by the iPiMP smartphone web app and Yatse.
     

    JDWestoby

    MP Donator
  • Premium Supporter
  • April 9, 2008
    265
    32
    69
    Poltimore, Devon
    Home Country
    United Kingdom United Kingdom
    I know, I looked at these, but they require a web server and more "junk" clogging up the system. More things means it is more likely to fall over.

    I like to keep things simple so that's why I'm considering doing this.

    I had a look (and bought) at the Android gPad which is simple but this is one step up from just sending keypresses.

    Adding a process plugin is comparatively easy, keeping a web server going a bit more involved and more than I want to bother with.
     

    Tolriq

    Portal Pro
    September 13, 2010
    91
    19
    Home Country
    France France
    The MPCC plugin can be installed apart from the full IPIMP package :)

    It's just a process plugin, and i can confirm that it works quite wells for that since Yatse relies on this little 70KB plugin and it does it's job quickly and efficiency :)
     

    JDWestoby

    MP Donator
  • Premium Supporter
  • April 9, 2008
    265
    32
    69
    Poltimore, Devon
    Home Country
    United Kingdom United Kingdom
    Maybe (if I can get it to work)!

    OK, looked at this and the StartChannel might be just what I need (might run Radio too). Added this as a reference to my alarm code OK.

    Trouble is I don't know how to send to it!


    I know you've written YATSE and you're using this. Any chance of an example TCP call so I know how to set it up.

    As an aside I DID try doing my own call directly to MediaPortal
    Channel c = myNavigator.GetChannel("BBC ONE");
    bool b = TVHome.ViewChannelAndCheck(c);

    This correctly fires up the TV (not Radion - why?) but stops after half a second!!!

    No idea why, it gets the requested channel although the scrolling text below is wrong.

    I'm using a client PC to the MediaPortal server.


    >>SO<< happy you just have to attach to the MediaPortal ext to debug...!

    Aw well at least I've got a dimmable clock so far :D

    Anyway, any chance someone wants to tell me how to set up and send the MPCC request?
     

    Tolriq

    Portal Pro
    September 13, 2010
    91
    19
    Home Country
    France France
    Just to give you an idea, the code is not usable alone like this, but at least you have the required json parameters needed.

    You can find the needed params value in the ipimp code for your needs. I don't use radio or EPG so can"t help on this part.

    It use Jayrock for the json handling.

    Code:
    public JsonObject IPimpCommand(CommandInfoIPimp command)
            {
                var error = new JsonObject();
                error["result"] = false;
    
                if (command == null)
                    return error;
    
                lock (Locker)
                {
                    var args = new JsonObject();
                    args["action"] = command.Action;
                    args["filter"] = command.Filter;
                    args["value"] = command.Value;
                    args["start"] = command.Start;
                    args["pagesize"] = command.PageSize;
                    args["shuffle"] = command.Shuffle;
                    args["enqueue"] = command.Enqueue;
                    args["tracks"] = command.Tracks;
    
                    if (command.Action != "ping" && command.Action != "nowplaying")
                        Log("COMMAND : " + args);
                    else
                        Trace("COMMAND : " + args);
    
                    var myCompleteMessage = "";
    
                    var webRequest = WebRequest.Create(GetApiPath());
                    webRequest.Method = "POST";
    
                    var byteArray = Encoding.UTF8.GetBytes(args.ToString());
                    webRequest.ContentType = "application/x-www-form-urlencoded";
                    webRequest.ContentLength = byteArray.Length;
    
                    try
                    {
                        var datastream = webRequest.GetRequestStream();
                        {
                            datastream.Write(byteArray, 0, byteArray.Length);
                            datastream.Close();
    
                            var webResponse = webRequest.GetResponse();
                            if (webResponse != null)
                            {
                                using (var datastream2 = webResponse.GetResponseStream())
                                {
                                    if (datastream2 != null)
                                    {
                                        var reader = new StreamReader(datastream2);
                                        myCompleteMessage = reader.ReadToEnd();
                                    }
                                }
                                webResponse.Close();
                            }
                        }
                    }
                    catch (Exception)
                    {
                        if (command.Action != "ping" && command.Action != "nowplaying")
                            Log("ERROR - COMMAND : " + args);
                        else
                            Trace("ERROR - COMMAND : " + args);
                        myCompleteMessage = error.ToString();
                    }
    
                    Trace(myCompleteMessage);
                    return (JsonObject)JsonConvert.Import(myCompleteMessage);
                }
            }
     

    JDWestoby

    MP Donator
  • Premium Supporter
  • April 9, 2008
    265
    32
    69
    Poltimore, Devon
    Home Country
    United Kingdom United Kingdom
    Ah - that would be good, ol' VB then. Now to convert it to C# (it's MediaPortal's preferred, no idea why).

    Thank you for that, dumped in a ref to Jayrock and now I get a load of var errors etc.


    I did get a reply from Cheezey too but it seems he doesn't use Radio! So that won't work - ho hum.


    Not sure I 'like' the idea of a http request when a simple TCP/IP packet will do, seems a bit of an overkill.

    This is why people end up writing their own things, interfaces should be easy (that's why I just use something 'dumb' like strings).

    Maybe I WILL write my own script interface......<sigh>

    Anyway, HUGE thanks, it IS appreciated - any information is good information. Maybe I'll try your YATSE sometime (I thought it was the game YAHZEE - silly me).
     

    Tolriq

    Portal Pro
    September 13, 2010
    91
    19
    Home Country
    France France
    The code i post is c#:)

    The overhead of HTTP is just like nothing :) And it solve many problem of inventing protocols to send data over tcp :) Just try to get more than 15 ko of data on tcp without writing a protocol wrapper :)
     

    Users who are viewing this thread

    Top Bottom