Warning: sage.py in r70 requires patched sagex-api.jar file on Sage server

35 views
Skip to first unread message

Derek Battams

unread,
Aug 5, 2011, 9:15:59 PM8/5/11
to sagetv-b...@googlegroups.com
I'm about to commit r70 to svn.  This commit provides the ability to filter the data returned in the JSON objects of all Sage API requests.  It's not perfect, but will serve our purposes for now.  You must download the sagex-api.jar file from here:


Stop the Sage server, replace the sagex-api.jar file in JARs\ with the one above, and restart Sage.

Once you do that, then you can use the sage.py update in r70.  This update allows you to do this:

sageAPI = SageApi('host', 'id', 'pwd')
favs = sageAPI.GetFavorites(filter='FavoriteID|FavoriteDescription')

favs now contains all fav objects, but each object only contains the properties listed in the filter, all others are dropped.  The filter arg must be last and is optional; without then it operates just as it did before (i.e. return everything in the object).

The filter arg should only be used on calls like GetFavorites(), GetMediaFiles(), etc. where you want all the objects, but only want a subset of properties.  If you start mixing the filter option in with other api calls then the results may not be as expected (mainly because the filter is propagated through all api calls and object construction calls so the filter is applied recursively and will end up dumping props you don't expect).  Where this will not work is if you did this:

mf = sageAPI.GetMediaFiles('T', filter='Show|Airing')

mf will contain an object for each media file, but the show and airing props of each will be empty objects because those objects do not have properties named 'Show' or 'Airing' themselves so they will filter out all props in the returned objects.  The filter is more for grabbing a subset of primitive data types from objects.  If the need arises, I can probably fix the recursive nature of the filter.

Anyway, the new jar is available now and the new sage.py will be committed shortly.  The new sage.py will work with the old sagex-api.jar, just the filter option will be ignored if specified (by the Sage server).

I expect Sean will accept some form of this patch, if it's totally rejected then I'll have to undo this in sage.py and will have to think of something else, but server side prop filtering is by far the fastest approach here.

  - Derek

Michael Reid

unread,
Aug 5, 2011, 9:20:10 PM8/5/11
to sagetv-b...@googlegroups.com
Awesome!  I'll start messing with it asap.

~Mike
--
You received this message because you are subscribed to the Google Groups "SageTV for Boxee (Development)" group.
To post to this group, send email to sagetv-b...@googlegroups.com.
To unsubscribe from this group, send email to sagetv-boxee-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sagetv-boxee-dev?hl=en.

Derek Battams

unread,
Aug 5, 2011, 9:29:58 PM8/5/11
to sagetv-b...@googlegroups.com
r70 committed.

Tom Miranda

unread,
Aug 6, 2011, 9:07:32 AM8/6/11
to sagetv-b...@googlegroups.com
Derek,

I tried this and the app won't start.  Here is the log:

09:05:45 T:696 M:891322368   DEBUG: Dispatching sagex API call: EvaluateExpression
09:05:45 T:696 M:891318272  NOTICE: Traceback (most recent call last):
09:05:45 T:696 M:891318272  NOTICE:   File "C:\Documents and Settings\Default\Application Data\BOXEE\userdata\apps\com.googlecode.sagetvboxee.sageboxee\startsage.py", line 34, in ?
09:05:45 T:696 M:891318272  NOTICE: sageAPI.isApiServerAlive()
09:05:45 T:696 M:891318272  NOTICE:   File "C:\Documents and Settings\Default\Application Data\BOXEE\userdata\apps\com.googlecode.sagetvboxee.sageboxee\sage.py", line 315, in __getattr__
09:05:45 T:696 M:891277312  NOTICE: return _SageApiHelpers(self._host, self._id, self._pwd, self._ssl).__getattr__(name)
09:05:45 T:696 M:891277312  NOTICE:   File "C:\Documents and Settings\Default\Application Data\BOXEE\userdata\apps\com.googlecode.sagetvboxee.sageboxee\sage.py", line 339, in __getattr__
09:05:45 T:696 M:891256832  NOTICE: return _dummyCallable(api.EvaluateExpression('Size(GetOS()) > 0'))
09:05:45 T:696 M:891256832  NOTICE:   File "C:\Documents and Settings\Default\Application Data\BOXEE\userdata\apps\com.googlecode.sagetvboxee.sageboxee\sage.py", line 383, in __call__
09:05:45 T:5200 M:891248640   DEBUG: Boxee: 06/08/11 13:05:45#DEBUG#..\..\xbmc\lib\libBoxee\boxee.cpp:456(BOXEE::Boxee::SetUserAction)#Boxee::SetUserAction - Call to  return LoadFromURL with [http://app.boxee.tv/action/add] returned [retVal=0]. [ActionType=launch] (sua)
09:05:45 T:5200 M:891248640   DEBUG: Boxee: 06/08/11 13:05:45#ERROR#..\..\xbmc\lib\libBoxee\boxee.cpp:578(BOXEE::Boxee::SetUserAction_bg::SetUserActionJob::DoWork)#failed to run user action in BG
09:05:45 T:696 M:891265024  NOTICE: LOG.LogInfo(kvargs)
09:05:45 T:696 M:891265024  NOTICE:   File "C:\Documents and Settings\Default\Application Data\BOXEE\userdata\apps\com.googlecode.sagetvboxee.sageboxee\sage.py", line 488, in LogInfo
09:05:45 T:996 M:891265024   DEBUG: Found machine KIDS address 192.168.1.8 interface 00:15:17:0d:84:10 via mapping
09:05:45 T:5824 M:891252736   DEBUG: Looking for shares on host KIDS ip 192.168.1.8
09:05:45 T:696 M:891076608  NOTICE: self._log.LogInfo(msg.encode(DEFAULT_CHARSET))
09:05:45 T:696 M:891076608  NOTICE: AttributeError
09:05:45 T:696 M:891076608  NOTICE: :
09:05:45 T:696 M:891076608  NOTICE: 'dict' object has no attribute 'encode'
09:05:45 T:696 M:891076608   ERROR: Scriptresult: Error

Derek Battams

unread,
Aug 6, 2011, 4:59:38 PM8/6/11
to sagetv-b...@googlegroups.com
Fixed in r71.

Tom Miranda

unread,
Aug 6, 2011, 6:55:32 PM8/6/11
to sagetv-b...@googlegroups.com
Jump out of any airplanes lately? :)

On Sat, Aug 6, 2011 at 4:59 PM, Derek Battams <de...@battams.ca> wrote:
Fixed in r71.

Derek Battams

unread,
Aug 7, 2011, 2:21:32 AM8/7/11
to sagetv-b...@googlegroups.com
Yeah, did that earlier today... the world looks a little different when standing at the edge of an open airplane door at 13,500 feet and then jumping out. :)  The free fall was definitely an experience!

  - Derek

Michael Reid

unread,
Aug 7, 2011, 9:06:34 PM8/7/11
to sagetv-b...@googlegroups.com
Derek or Tom,

I am trying to use this new method of filtering as described, and The result i get back is still a Gigantic listItems object that contains everything about the favorite, NOT the only 2 items in the filter.

Tom does this work for you?

--
You received this message because you are subscribed to the Google Groups "SageTV for Boxee (Development)" group.
To post to this group, send email to sagetv-b...@googlegroups.com.
To unsubscribe from this group, send email to sagetv-boxee-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sagetv-boxee-dev?hl=en.



--
~Mike

Derek Battams

unread,
Aug 7, 2011, 9:51:43 PM8/7/11
to sagetv-b...@googlegroups.com
Did you upgrade the sagex-api.jar file as well?  The filtering will only work if you upgrade the jar.

Michael Reid

unread,
Aug 7, 2011, 10:01:25 PM8/7/11
to sagetv-b...@googlegroups.com
yup i followed the instructions that you gave.  I went out to google code, downloded just that file that was out there (the newest)  stop sage service.  Then copied the new file into the sage directory....  When i call it directly in a web browser with the filtering options i get the same giganitic list back.

what are you seeing?

On Sun, Aug 7, 2011 at 8:51 PM, Derek Battams <de...@battams.ca> wrote:
Did you upgrade the sagex-api.jar file as well?  The filtering will only work if you upgrade the jar.
On Sun, Aug 7, 2011 at 21:06, Michael Reid <mrei...@gmail.com> wrote:
Derek yoor Tom,



--
~Mike

Derek Battams

unread,
Aug 7, 2011, 10:28:29 PM8/7/11
to sagetv-b...@googlegroups.com
The filtered JSON object:


{"MediaFile":{"MediaFileID":7171696,"MediaTitle":"Curb Your Enthusiasm"}}
The filter only works for the JSON encoder.  The XML encoder will ignore it.


  - Derek

Michael Reid

unread,
Aug 7, 2011, 10:39:39 PM8/7/11
to sagetv-b...@googlegroups.com
I was trying to do this based on your earlier post about this method:

favs = sageAPI.GetFavorites(filter='FavoriteID|FavoriteDescription')

when i make that call i get a full set of fully populated objects...no filters applied.

Is that not how i am suppose to use it?

Oen Sun, Aug 7, 2011 at 9:28 PM, Derek Battams <de...@battams.ca> wrote:
{"MediaFile":{"MedediaFileID":7171696,"MediaTitle":"Curb Your Enthusiasm"}}



--
~Mike

Derek Battams

unread,
Aug 7, 2011, 10:49:41 PM8/7/11
to sagetv-b...@googlegroups.com
That works for me, too. :)

print sageAPI.GetFavoriteForID(153489, filter='FavoriteID|FavoriteDescription')

{'FavoriteDescription': 'Saturday Night Live First Runs', 'FavoriteID': 153489}

print sageAPI.GetFavorites(filter='FavoriteID|FavoriteDescription')

This also works, but I have like over 100 favorites so I didn't paste in the output here, but each object only had the two properties listed.

If it's not working then make sure you have the latest sage.py + the latest sagex-api.jar installed.  If that's good, then check the boxee.log and paste the URL it's using into your browser and see if it's working there.

  - Derek

Michael Reid

unread,
Aug 7, 2011, 10:55:52 PM8/7/11
to sagetv-b...@googlegroups.com
yup thats exactly what i did to see that calling the sagex directly wasn't working.  i will truple check i have the latest sage.py and jar file installed...trhnx

Michael Reid

unread,
Aug 7, 2011, 11:13:35 PM8/7/11
to sagetv-b...@googlegroups.com
there we go...now its working.

Thanks Derek.
--
~Mike

Derek Battams

unread,
Aug 8, 2011, 12:38:24 PM8/8/11
to sagetv-b...@googlegroups.com
Sean did an updated build of the remote APIs - 7.1.9.1.  This build includes all the patches I've made plus a fix for the IsShowFirstRun bug.  I've deleted the jars on our project site - all users should upgrade to 7.1.9.1 immediately to use the latest sage.py.

  - Derek

Tom Miranda

unread,
Aug 9, 2011, 10:08:39 PM8/9/11
to sagetv-b...@googlegroups.com
So how would I use this if the object has subkeys?  Example, I get Airings and I only want some of the subkeys of Show? (Show is a key, and Show has various subkeys, bu I only want the 'SubCategory' subkey)

--

Michael Reid

unread,
Aug 9, 2011, 10:12:51 PM8/9/11
to sagetv-b...@googlegroups.com
I am having issues getting my favorites object into a usable form as well.  I have tried various ways of iterating the list i send to my new method, but i cannot seem to get it right.

when i pass in my object i have the same as i showed the other day

{"FavoriteDescription":"The Dr. Oz Show","FavoriteID":123232"}

i was hoping i could do something like:
for key,value in list:
      do something...
--
~Mike

Tom Miranda

unread,
Aug 9, 2011, 10:18:00 PM8/9/11
to sagetv-b...@googlegroups.com
Not sure what you're trying to do, maybe attach some sample code.

If the dictionary is called fav, then your code would liik something like:

description = fav['FavoriteDescription']
... do something with description ...

favID = fav['FavoriteID']
... do something with favID ...

I don't see why you'd want to iterate over the keys or values.

Michael Reid

unread,
Aug 9, 2011, 10:26:05 PM8/9/11
to sagetv-b...@googlegroups.com
Thanks Tom.  I swear i tried that using the elements in an associative fashion, and it wasn't working...it seems to be working now though.  Thanks!

Michael Reid

unread,
Aug 9, 2011, 11:49:31 PM8/9/11
to sagetv-b...@googlegroups.com
Got some general layout:  working: favorites being pulled in, displaying in list on the right with list of options on the left just like the Favorites Manager:

Does anyone know when u hit Sort By in the Favorites Manager what it actually sorts on?  I looked for a priority indicator in the favorites object returned from GetFavorites, and i couldn't find anything that made sense.. any ideas?
--
~Mike

Tom Miranda

unread,
Aug 10, 2011, 4:51:57 PM8/10/11
to sagetv-b...@googlegroups.com
Mike,

"Sort by" just allows you to change between the Favorite name and the Favorite priority.  By default GetFavorites() returns them in priority order.

Tom

Michael Reid

unread,
Aug 10, 2011, 5:01:01 PM8/10/11
to sagetv-b...@googlegroups.com
oh - ok.

My thought here is to only hit the sagexapi once for all favorites, aside from saving the info back to the  sage server of course.

I am going to try and make one call using the GetFavorites(and filters) to get everytrhing i need for all favorite screens.  I would then store these items in a list object with custom properties.

If the user wants to sort i will call a seperate function (either in sage.py or local to my favorites.xml) which will sort the list based on my criteria.  I don't however see a property for favorite priority.... Does one exist?

Tom Miranda

unread,
Aug 10, 2011, 5:03:42 PM8/10/11
to sagetv-b...@googlegroups.com
I forget, but I don't think so.  I think you just need to keep track of the priority based on where it was in the list.  There is a method to increase priority.

Michael Reid

unread,
Aug 10, 2011, 5:05:47 PM8/10/11
to sagetv-b...@googlegroups.com
Yeah i am keeping track right now depending on how the list is returned from my initial call.  I will most likely end up saving that to a custom property field so that i can easily sort on it or the name without problem.  This will bascially mimic a sort by priority.

There are going to be a few tricky things with favorites as you mentioned before...one of which i don't even know right now if it is possible.  The option i am referring to is the way you can right arrow on a favorite and move it up and down in the list...It should be possible but im not sure how im going to accomplish it yet.

Thanks tom!

Tom Miranda

unread,
Aug 10, 2011, 5:11:20 PM8/10/11
to sagetv-b...@googlegroups.com
I wouldn't worry about that fancy stuff until I got the basics working.  What you can do is execute the Sage API to change the priority and then reload the listitems into the control.

Michael Reid

unread,
Aug 10, 2011, 5:12:33 PM8/10/11
to sagetv-b...@googlegroups.com
Cool.  The fancy stuff is on the back burner, but i am keeping it in mind as i move forward with the basics.  That way there won't be as much redesign when i try and implement new features.
Reply all
Reply to author
Forward
0 new messages