SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV v7 Customizations

Notices

SageTV v7 Customizations This forums is for discussing and sharing user-created modifications for the SageTV version 7 application created by using the SageTV Studio or through the use of external plugins. Use this forum to discuss plugins for SageTV version 7 and newer.

Reply
 
Thread Tools Search this Thread Display Modes
  #1201  
Old 10-19-2015, 06:32 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
You shouldn't have to extend the api or anything, the funtion you need is already in the API. there are basically 3 api calls you'd need. ClearWatched(sage.Airing Airing), SetWatchedTimes(sage.Airing Airing, long WatchedEndTime, long RealStartTime), and SetWatched(sage.Airing Airing). All in the Airing API.
__________________
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
  #1202  
Old 10-19-2015, 10:57 PM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Quote:
Originally Posted by Fuzzy View Post
You shouldn't have to extend the api or anything, the funtion you need is already in the API. there are basically 3 api calls you'd need. ClearWatched(sage.Airing Airing), SetWatchedTimes(sage.Airing Airing, long WatchedEndTime, long RealStartTime), and SetWatched(sage.Airing Airing). All in the Airing API.
You mean something like this via sagex http api?

Code:
http://usr:pwd@host:port/sagex/api?c=AiringAPI.GetAiringDuration&1=3507454&encoder=json
The API says the parameter Airing is an object. How do I pass that in? Passing the airingID doesn't seem to work, I get:

Code:
{"Result":0}
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
  #1203  
Old 10-20-2015, 07:27 AM
PiX64's Avatar
PiX64 PiX64 is offline
Sage Icon
 
Join Date: Dec 2008
Location: Illinois
Posts: 1,991
Brian = LehiBri from the forums yes. He has moved on to other things, so not sure if he still monitors the forums.

While what Fuzzy said is tech. correct the issue is in when you would actually send this command to SageTV.

Once library scan is done there is no communication back with the media except for playback.

In order for it to work you would have to set your plex scanner to detect changes in the media folder, and THEN run logic inside the scanner which would check for Watched flags in plex ON EVERY recording. once it found one it woudl then call the api to set it in SageTV.

The issue here though is if there is no change in the recordings directory, you wouldn't have any changes that would trigger the code to execute.The code lives in the scanner/bmt agent which is only run when plex finds a new piece of media and proceeds to call the metadata agent.
Reply With Quote
  #1204  
Old 10-20-2015, 07:50 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,541
Quote:
Originally Posted by wildgoose View Post
You mean something like this via sagex http api?

Code:
http://usr:pwd@host:port/sagex/api?c=AiringAPI.GetAiringDuration&1=3507454&encoder=json
The API says the parameter Airing is an object. How do I pass that in? Passing the airingID doesn't seem to work, I get:

Code:
{"Result":0}
You should be able to pass the MediaFileID as the 1st parameter, as a number.
Reply With Quote
  #1205  
Old 10-20-2015, 10:43 AM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Quote:
Originally Posted by stuckless View Post
You should be able to pass the MediaFileID as the 1st parameter, as a number.
Hmm, can't get it to work:

Code:
http://user:pwd@host:8080/sagex/api?c=GetAiringDuration&1=3530652&encoder=json
Code:
{"Result":0}
The other API call I make works:

Code:
http://user:pwd@host:8080/sagex/api?c=plex:GetMediaFileForName&1=PersonofInterest-SearchandDestroy-3507454-0.mpg&encoder=json
Code:
... "MediaFileID":3530652 ...
I tried another file and same result. This is v7 on Windows.
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
  #1206  
Old 10-20-2015, 10:52 AM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Quote:
Originally Posted by PiX64 View Post
While what Fuzzy said is tech. correct the issue is in when you would actually send this command to SageTV.

Once library scan is done there is no communication back with the media except for playback.

In order for it to work you would have to set your plex scanner to detect changes in the media folder, and THEN run logic inside the scanner which would check for Watched flags in plex ON EVERY recording. once it found one it woudl then call the api to set it in SageTV.

The issue here though is if there is no change in the recordings directory, you wouldn't have any changes that would trigger the code to execute.The code lives in the scanner/bmt agent which is only run when plex finds a new piece of media and proceeds to call the metadata agent.
You are absolutely right! The plugin is only active when user does a scan, and the hooks only gets called on changed/new files. So we can't update the plugin to actively push changes to SageTV.

It'll have to be something separate such as the standalone sageplex_sync tool that the user runs manually every now and then (or set it up to run periodically like a cron job), or perhaps even a SageTV plugin that can periodically perform the sync either using the sageplex_sync tool or entirely within Java code.

So, phase1, get the sync tool working. phase2, perhaps a native sagetv plugin that performs the sync.
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
  #1207  
Old 10-20-2015, 11:45 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Since you cannot pass objects through the http request, you'll likely have to use EvaluateExpression to pass in a more advanced (compound) function. Something like:
Code:
/sagex/api?c=EvaluateExpression&1=GetAiringDuration(GetAiringForID(25885579))
__________________
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
  #1208  
Old 10-20-2015, 12:21 PM
PiX64's Avatar
PiX64 PiX64 is offline
Sage Icon
 
Join Date: Dec 2008
Location: Illinois
Posts: 1,991
It may help to take a look at what already in the .js file that sits on the sage server. It may already have what you need in there, I can't quite remember.
Reply With Quote
  #1209  
Old 10-20-2015, 12:56 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,541
Quote:
Originally Posted by wildgoose View Post
Hmm, can't get it to work:

Code:
http://user:pwd@host:8080/sagex/api?c=GetAiringDuration&1=3530652&encoder=json
Code:
{"Result":0}
The other API call I make works:

Code:
http://user:pwd@host:8080/sagex/api?c=plex:GetMediaFileForName&1=PersonofInterest-SearchandDestroy-3507454-0.mpg&encoder=json
Code:
... "MediaFileID":3530652 ...
I tried another file and same result. This is v7 on Windows.
Quote:
Originally Posted by Fuzzy View Post
Since you cannot pass objects through the http request, you'll likely have to use EvaluateExpression to pass in a more advanced (compound) function. Something like:
Code:
/sagex/api?c=EvaluateExpression&1=GetAiringDuration(GetAiringForID(25885579))
Very first line of http://server:8080/sagex/api

Quote:
NOTE: If the command arg expects a sage object, such mediafile, ariing, playlist, channel, show, plugin, favorite, series, etc, then you can still pass a reference to sage object, using mediafile:MEDIAFILE_ID, airing:AIRING_ID, playlist:PLAYLIST_NAME, channel:CHANNEL_NUMBER, show:EXTERNAL_ID, series:SERIES_INFO_ID, favorite:FAVORITE_ID, plugin:PLUGIN_ID, playlist:PLAYLIST_NAME, widget:SYMBOL, etc.

Example: /sages/api?c=IsMediaFileObject&1=mediafile:3231112
So, if you need to pass an object, you use "mediafile:#" or "airing:#" ,etc.
Reply With Quote
  #1210  
Old 10-20-2015, 01:45 PM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Quote:
Originally Posted by stuckless View Post
Very first line of http://server:8080/sagex/api
Somehow forgot about this. Self documenting API, nice!

Quote:
Originally Posted by stuckless View Post
So, if you need to pass an object, you use "mediafile:#" or "airing:#" ,etc.
oh boy, so trivial. I was wondering how you would tell them apart, now it makes sense!

This worked beautifully:

Code:
http://user:pwd@host:8080/sagex/api?c=GetAiringDuration&1=airing:3507454&encoder=json
Code:
{"Result":3540000}
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
  #1211  
Old 10-20-2015, 03:28 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Bah.. EvaluateExpresison is still cleaner... :-)
__________________
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
  #1212  
Old 10-20-2015, 05:10 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,541
Quote:
Originally Posted by Fuzzy View Post
Bah.. EvaluateExpresison is still cleaner... :-)
I use the EvaluateExpression, a lot, but I was thinking that I could have sworn that I had support for native object types (And I did)
Reply With Quote
  #1213  
Old 10-29-2015, 02:19 PM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Testing my two way sync tool. When exactly does Sage consider the show watched? I assume this is X away from ending, where X can be a time or percentage?

I need to know this as the 2 system treats watched shows differently. Sage position will stay at the end, while PLEX position will reset back to beginning. If you re-watch a show, Sage clears the watched status while PLEX don't (they keep a watch count). Want to avoid unnecessary syncs.

I am currently using 5% from ending as a guess. Using the same rule that Sage does would be better.
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
  #1214  
Old 10-29-2015, 06:30 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
if you get this working lmk the quickest way to make it automatic it a hook in the stv everytime playback is stopped your tool resynchs the watch status for the file. so leave a way for me to pass the file and I'll add the hook.
Reply With Quote
  #1215  
Old 10-29-2015, 06:59 PM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Quote:
Originally Posted by PLUCKYHD View Post
if you get this working lmk the quickest way to make it automatic it a hook in the stv everytime playback is stopped your tool resynchs the watch status for the file. so leave a way for me to pass the file and I'll add the hook.
Very good point. Need to think about this a bit because right now the tool craws the PLEX library first, and for each media, find the Sage media file and does a check/sync.

Need to see if there's a quick way to locate a PLEX media from the Sage media, as otherwise may need to do some caching. Also not sure if it can be made automatic the other way (when you stop watch a PLEX show). That would be ideal.
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
  #1216  
Old 10-29-2015, 07:16 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by wildgoose View Post
Very good point. Need to think about this a bit because right now the tool craws the PLEX library first, and for each media, find the Sage media file and does a check/sync.

Need to see if there's a quick way to locate a PLEX media from the Sage media, as otherwise may need to do some caching. Also not sure if it can be made automatic the other way (when you stop watch a PLEX show). That would be ideal.
TBH I started something a while back and got so frustrated with how limiting plex's api is for developers I pushed it to the side pretty quickly. For such on "open" platform their developer support and api is terrible.

That being said glad to see you attempt it. It is something that would be nice to see in sage.
Reply With Quote
  #1217  
Old 10-30-2015, 05:29 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,541
Totally agree with PLUCKY about how horrible it is to work with plex (and their apis). That's pretty much why I abandoned any plex/sage integration, myself.

That being said, maybe you can figure something out by looking through the Trakt plugin for plex. (I have to admit there was way more code here than I ever expected to see)

https://github.com/trakt/Plex-Trakt-Scrobbler

Another option might be to simply write a Trakt plugin for sagetv and then use the trakt plugins on plex and sagetv to keep the watched statuses in sync on each platform.
Reply With Quote
  #1218  
Old 10-30-2015, 08:33 AM
PiX64's Avatar
PiX64 PiX64 is offline
Sage Icon
 
Join Date: Dec 2008
Location: Illinois
Posts: 1,991
Quote:
Originally Posted by stuckless View Post
Totally agree with PLUCKY about how horrible it is to work with plex (and their apis). That's pretty much why I abandoned any plex/sage integration, myself.

That being said, maybe you can figure something out by looking through the Trakt plugin for plex. (I have to admit there was way more code here than I ever expected to see)

https://github.com/trakt/Plex-Trakt-Scrobbler

Another option might be to simply write a Trakt plugin for sagetv and then use the trakt plugins on plex and sagetv to keep the watched statuses in sync on each platform.
Great Idea Sean - Thats prolly the cleanest solution, cause Plex is def. terrible to work with from a coding/scripting standpoint.
Reply With Quote
  #1219  
Old 11-05-2015, 12:05 AM
peternm22 peternm22 is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 607
With the sageplex_sync.exe tool, is it possible to pass it a SageTV MediaFileID? Right now, it seems to only except the Plex media ID.

I'm trying to setup a SJQ task that can update the Plex watched position, and I would like to be able to do it on a per recording basis (instead of having to go through all of my SageTV recordings).
Reply With Quote
  #1220  
Old 11-05-2015, 11:33 PM
wildgoose wildgoose is offline
Sage Advanced User
 
Join Date: Jan 2010
Location: CA
Posts: 156
Quote:
Originally Posted by peternm22 View Post
With the sageplex_sync.exe tool, is it possible to pass it a SageTV MediaFileID? Right now, it seems to only except the Plex media ID.

I'm trying to setup a SJQ task that can update the Plex watched position, and I would like to be able to do it on a per recording basis (instead of having to go through all of my SageTV recordings).
Not currently. The API info I have about PLEX allowed me to craw the PLEX library tree, so that's how the sync tool works. There is already a way to find a Sage MFID based on a filename, so that's what I use to lookup the Sage recording (and it's fast). But unfortunately not the other way around.

PLEX web client does have a search function, and I can probably look at the HTTP request sent and see if I can use it. If not, then another option is to build a cache index on demand....

But, I've been busy testing my new implementation of the two way sync in sageplex_sync. It's coming along nicely. Lots of corner cases to handle due to the way the two system differs in how they treat watched shows, etc... Should be out soon, stay tuned...
__________________
sagetv-for-plexmediacenter v8.3.1 is available! Github/Download site.
Reply With Quote
Reply


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

Advanced Search
Display Modes

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
Comparing to Plex heffneil Batch Metadata Tools 20 01-08-2012 04:54 PM
Need help with SJQv4 remote agent coppit SageTV v7 Customizations 4 12-19-2010 11:03 AM
Plex in a TV? What about sage? rwc General Discussion 9 09-05-2010 04:38 PM
Possible to get SageTV to handle my library more like Plex? DAMAC SageTV Mac Edition 0 06-10-2009 10:33 AM
SagetTVService Virus Win32.Agent.dwo Ponchera SageTV Software 6 02-04-2008 06:33 PM


All times are GMT -6. The time now is 01:52 AM.


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