![]() |
|
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. |
![]() |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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")); Code:
UIContext ctx = new UIContext("001abc4cf481"); MediaPlayerAPI.GetCurrentMediaFile(ctx);
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#3
|
|||
|
|||
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 "" } 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 |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
Quote:
Code:
def list = [] list.addAll(Global.GetUIContextNames()); list.addAll(Global.GetCurrentClients())
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#7
|
|||
|
|||
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 |
#8
|
||||
|
||||
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 |
#9
|
|||
|
|||
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 |
#10
|
||||
|
||||
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 { ... }
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#11
|
|||
|
|||
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 |
#12
|
|||
|
|||
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 |
#13
|
|||
|
|||
The code seems agnostic as to whether you throw it a MAC ID as a context or a client as a IP
![]() 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 |
#14
|
|||
|
|||
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 }
__________________
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. |
#15
|
|||
|
|||
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... |
#16
|
|||
|
|||
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)
__________________
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 |
#17
|
|||
|
|||
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] 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... |
#18
|
|||
|
|||
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 |
#19
|
|||
|
|||
Quote:
__________________
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 |
#20
|
||||
|
||||
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 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
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 |