SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Github Development
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Github Development Discussion related to SageTV Open Source Development. Use this forum for development topics about the Open Source versions of SageTV, hosted on Github.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-02-2016, 11:34 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Sage API question

How do you specify a context when trying to get data from the Sage MediaPlayer API to pull info like the currently playing MediaFile?

I know how to do this with Sagex - just hit "http://192.168.1.11:8080/sagex/api?c=GetCurrentMediaFile&context=001abc4cf481"

But how do you do this with the Sage API from Java or Groovy? I would think it would be something like:
println MediaPlayerAPI.GetCurrentMediaFile(context)

But the MediaPlayerAPI doesn't seem to allow you to pass a context? Or is it in another Class that I can't find right now?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #2  
Old 01-03-2016, 05:40 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
You are close... in Sagex API you need to create a UIContext object, and pass the content in that.

Code:
MediaPlayerAPI.GetCurrentMediaFile(new UIContext("001abc4cf481"));
If you are going to be doing multiple api calls with the same context, then you can create an instance, and just pass it around.

Code:
UIContext ctx = new UIContext("001abc4cf481");
MediaPlayerAPI.GetCurrentMediaFile(ctx);
The context is always the first parameter to api call. And each API call has a method WITH and WITHOUT a context.
Reply With Quote
  #3  
Old 01-03-2016, 03:14 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Thanks Stuckless. In case anyone finds this and needs the answer (especially me) here is a snippet of code that will list some info for all active contexts. This code is in Groovy although it will likely also work in Java.

Code:
import sagex.api.*
import org.apache.commons.lang.time.DurationFormatUtils

CurrentUIs= Global.GetUIContextNames()
CurrentUIs.each {
    ctx=new sagex.UIContext(it)
    MFobj= MediaPlayerAPI.GetCurrentMediaFile(ctx)
    MF=MediaFileAPI.GetMediaFileID(MFobj)
    Airing=MediaFileAPI.GetMediaFileAiring(MFobj)
    Show = AiringAPI.GetShow(Airing)
    println ShowAPI.GetShowTitle(Show)+" - "+ ShowAPI.GetShowEpisode(Show)
    println "Show Duration is: " + DurationFormatUtils.formatDuration(MediaPlayerAPI.GetMediaDuration(ctx), "HH:mm:ss")
    println "Current Playback Time: " +  DurationFormatUtils.formatDuration(MediaPlayerAPI.GetRawMediaTime(ctx), "HH:mm:ss")
    TimeInput=  Utility.GetTimeSinceLastInput(ctx)
    println "Time Since last input is:"+ DurationFormatUtils.formatDuration(TimeInput, "HH:mm:ss")
    println ""
}
The output is like this:
Code:
Blue's Clues - Snack Time
Show Duration is: 00:29:50
Current Playback Time: 00:18:55
Time Since last input is:00:18:58

Foul Play - Foul Play
Show Duration is: 01:56:05
Current Playback Time: 01:10:26
Time Since last input is:00:02:29

NBA Basketball - Chicago Bulls at Toronto Raptors
Show Duration is: 00:47:08
Current Playback Time: 00:21:36
Time Since last input is:00:11:25
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #4  
Old 01-03-2016, 03:57 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
I'm not sure what you are working on, but felt I should point out that UIContexts only show server contexts. Clients do not show in this, and to access them, I believe you'd have to connect to the sagex of the client itself.
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #5  
Old 01-03-2016, 04:55 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
You can change the command "CurrentUIs= Global.GetUIContextNames()" to "CurrentUIs= Global.GetCurrentClients()"

But for some reason I seem to add the two lists (Global.GetUIContextNames() and Global.GetCurrentClients()) together. Any idea how to do that? The "+" operator doesn't work, but aren't they just two string lists?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #6  
Old 01-03-2016, 05:46 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by wayner View Post
You can change the command "CurrentUIs= Global.GetUIContextNames()" to "CurrentUIs= Global.GetCurrentClients()"

But for some reason I seem to add the two lists (Global.GetUIContextNames() and Global.GetCurrentClients()) together. Any idea how to do that? The "+" operator doesn't work, but aren't they just two string lists?
you could try..

Code:
def list = []
list.addAll(Global.GetUIContextNames());
list.addAll(Global.GetCurrentClients())
I don't use groovy, but that might work.
Reply With Quote
  #7  
Old 01-03-2016, 07:39 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
I tried adddlist before and it didn't work early either.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #8  
Old 01-04-2016, 03:31 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Unfortunately, it might be better to keep the lists separate for working with anyway, since you have to access them differently.
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #9  
Old 01-04-2016, 09:08 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
When I changed the line for current UIs from Contexts to Clients the code worked. But my only "client" was actually the server at localhost - so the list contained something like "[/127.0.0.1:5313]". But the code worked perfectly well with that as the context argument.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #10  
Old 01-04-2016, 09:13 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
I noticed that SageTV has a DataUnion api (ie, add to sets and remove any overlapping)

http://download.sage.tv/api/sage/api...va.lang.Object, java.lang.Object)

So, you can try,

Code:
Database.DataUnion(Global.GetUIContextNames(), Global.GetCurrentClients()).each {
   ...
}
Reply With Quote
  #11  
Old 01-04-2016, 09:21 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Thanks, I will give that a try when I get home from work tonight and I will also try to turn on a client to see if it works with that as well.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #12  
Old 01-04-2016, 06:41 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
That works, at least for the server (which is a connected client) and an extender - why wouldn't a similar language command work? Is there something special about these lists?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #13  
Old 01-04-2016, 08:38 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
The code seems agnostic as to whether you throw it a MAC ID as a context or a client as a IPort.

Here is the output of my code and the list: (with slight obscuring of MAC)
Code:
Blue's Clues - Blue's Prediction
Show Duration is: 00:29:59
Current Playback Time: 00:01:45
Time Since last input is:00:01:48

Up - 
Show Duration is: 01:44:55
Current Playback Time: 01:36:03
Time Since last input is:01:33:53

NBA Basketball - Toronto Raptors at Cleveland Cavaliers
Show Duration is: 02:38:32
Current Playback Time: 00:00:08
Time Since last input is:00:00:11

Rugby - Pro 12: Newport Gwent Dragons vs. Cardiff
Show Duration is: 02:15:00
Current Playback Time: 00:13:58
Time Since last input is:28:20:19

Result: [001d6a4bfxxx, 001d6a4cfxxx, /192.168.1.94:62280, /127.0.0.1:51513]
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #14  
Old 01-04-2016, 08:40 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Pretty sure those two Global calls to get the context names return arrays, not Collections. And you can't "add" arrays to lists and vice versa in groovy (well you can, it just won't do what you expect it to do). And the Collections.addAll() call in Java only works on args that are Collections, not arrays. But you can "add" two arrays together. So the fix would be not to initialize your var as a list, instead, this should work (weird not having a Sage service online to actually test):

Code:
import sagex.api.*

// def list = [] // This inits list as a List<Object>, but Sage APIs are returning arrays so need to handle it one way or the other

def allConnections = Global.GetUIContextNames() + Global.GetConnectedClients()

allConnections.each {
   println it
}
Presumably, the Sage api call DataUnion() does the same kind of thing (handling the fact that addAll() only works on Collections, not arrays, figures it all out and does what needs to be done to get you the proper union as well).
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...

Last edited by Slugger; 01-04-2016 at 08:42 PM.
Reply With Quote
  #15  
Old 01-04-2016, 08:45 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Quote:
Originally Posted by wayner View Post
The code seems agnostic as to whether you throw it a MAC ID as a context or a client as a IPort.
This ability was added at the request of me (and various other devs) and just managed to squeeze into one of the last releases before Google came along.
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...
Reply With Quote
  #16  
Old 01-04-2016, 09:38 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
The plus operator doesn't work, at least not in Groovy. Here is the error:
Code:
groovy.lang.MissingMethodException: No signature of method: [Ljava.lang.String;.plus() is applicable for argument types: ([Ljava.lang.String;) values: [[/127.0.0.1:51513]]
Possible solutions: last(), sum(), is(java.lang.Object), split(groovy.lang.Closure), use([Ljava.lang.Object;), minus(java.lang.Object)
On a related note - how do you get a job to start on events like - MediaFile Playback finished or recording finished. Sure you can use SJQ for recording finished, but how do you access this from the Sage API?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #17  
Old 01-04-2016, 10:28 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Hmm... might be the older version of Groovy used in Sage because this works on my system with Groovy 2.1.8 (I believe I last packaged Groovy 2.0.x into Sage, which is the probably the differnce):

Code:
def a = ['1', '2', '3'] as String[]
def b = ['4', '5', '6'] as String[]
def c = a + b
println c.class
println c
Code:
class [Ljava.lang.Object;
[1, 2, 3, 4, 5, 6]
As for the event handling, you have to implement the SageTVEventListener interface and then register your implementation with the SageTVPluginRegistry. You get the registry via PluginAPI.GetSageTVPluginRegistry().

The gotcha to all of this is that you must do all of this within the Sage server process. Like you can't make all of these calls in an SJQ script that runs in a Windows service client, for example, otherwise it won't work -- I don't think. It might work if you did the calls outside of the Sage process but thru sagex remote api calls. But then if you do, the interface implementation class has to be on the server's classpath in order to work. Either way, the events can only be passed to objects created by and known to the server (or Sage client) process that fires the event. The events can never be passed thru to something external (like a daemon or SJQ client, etc.).
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...
Reply With Quote
  #18  
Old 01-04-2016, 10:32 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
I get the error when I try to run your above code in the Sage Groovy Console so you are right - it must have been added later.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #19  
Old 01-04-2016, 10:43 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Quote:
Originally Posted by Slugger View Post
As for the event handling, you have to implement the SageTVEventListener interface and then register your implementation with the SageTVPluginRegistry. You get the registry via PluginAPI.GetSageTVPluginRegistry().

The gotcha to all of this is that you must do all of this within the Sage server process. Like you can't make all of these calls in an SJQ script that runs in a Windows service client, for example, otherwise it won't work -- I don't think. It might work if you did the calls outside of the Sage process but thru sagex remote api calls. But then if you do, the interface implementation class has to be on the server's classpath in order to work. Either way, the events can only be passed to objects created by and known to the server (or Sage client) process that fires the event. The events can never be passed thru to something external (like a daemon or SJQ client, etc.).
Ok thanks. I found some of your code that I can try to reference to get some ideas.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #20  
Old 01-05-2016, 02:01 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Quote:
Originally Posted by Slugger View Post
This ability was added at the request of me (and various other devs) and just managed to squeeze into one of the last releases before Google came along.
Ahhh.. okay, good to know. It's been many years since I interacted with sage in this manner, and remembered having to pass client calls directly to a sagex instance on the client. If that was improved to be able to pass those through the server, that's great.
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sage TV/WHS question Karkas SageTV Software 12 02-13-2009 08:08 PM
Legal Question Sage squeed SageTV Software 2 08-30-2008 11:31 AM
Sage UI Question mike1961 SageTV Software 4 03-27-2006 01:35 PM
Upgrading Sage - question re: Cayars/Sage cclayton SageTV Customizations 3 02-01-2005 01:11 PM
Sage TV question mets3145 SageTV Software 1 08-13-2004 09:23 AM


All times are GMT -6. The time now is 02:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.