Jump to content

Emby Xpath Url?


Dodgexander

Recommended Posts

Dodgexander

I am trying to put my home media server to sleep when I'm not using it using this service: https://autosuspend.readthedocs.io/en/3.0/available_checks.html#xpath

 

Both Plex and TVheadend can be configured using Xpath with examples given.

 

Can I do the same with Emby?

 

I had a search but I couldn't find anything definitive. 

 

Thanks for any help.

Link to comment
Share on other sites

Hmm. Our api is json based but when responses are empty it might not matter. @@chef might be able to help you with an example.

  • Like 1
Link to comment
Share on other sites

chef

You could try using the "Users/Public" endpoint and check the "LastActivityDate" of each user.

 

Or we write a quick plugin endpoint which counts active users and returns an empty response if there are no connections.

Link to comment
Share on other sites

chef

But now I'm wondering if a sleep plugin should be created. I don't know how hard it is, but a configurable plugin which puts machines to sleep when there are no active connections sounds like a good idea.

Edited by chef
Link to comment
Share on other sites

Dodgexander

Thanks. The guide here: http://swagger.emby.media/?staticview=true#/SessionsService states two things.

 

1. It states the API can be looked up using XML format and not json.

 

2. There's a 'get sessions' section. Would this return '200'if there's a session and nothing if not?

 

I'm no developer but I'm trying to figure out how to mimic autosuspends behavior with Plex.

 

A plug-in would work too but is it needed with the API?

 

A sleep plug-in may be useful in certain circumstances but if you're using the server for other services it wouldn't be too useful.

Link to comment
Share on other sites

chef

Thanks. The guide here: http://swagger.emby.media/?staticview=true#/SessionsService states two things.

 

1. It states the API can be looked up using XML format and not json.

 

2. There's a 'get sessions' section. Would this return '200'if there's a session and nothing if not?

 

I'm no developer but I'm trying to figure out how to mimic autosuspends behavior with Plex.

 

A plug-in would work too but is it needed with the API?

 

A sleep plug-in may be useful in certain circumstances but if you're using the server for other services it wouldn't be too useful.

So if you query "{serverIp}:{port}/sessions&api_key={apiKey}"

 

It should be able to return the response you are looking for.

 

You can create an API key in the dashboard.

Edited by chef
Link to comment
Share on other sites

Dodgexander

Thanks for your help!

 

I'm trying to get this working but struggling.

http://my.server.ip:8096/emby/System/Info?Sessions&api_key=855this44fbis169myb4670API

But it only returns:

{"SystemUpdateLevel":"Release","OperatingSystemDisplayName":"Unix","HasPendingRestart":false,"IsShuttingDown":false,"OperatingSystem":"Linux","SupportsLibraryMonitor":true,"WebSocketPortNumber":8096,"CompletedInstallations":[],"CanSelfRestart":true,"CanSelfUpdate":false,"CanLaunchWebBrowser":false,"ProgramDataPath":"/config","ItemsByNamePath":"/config/metadata","CachePath":"/config/cache","LogPath":"/config/logs","InternalMetadataPath":"/config/metadata","TranscodingTempPath":"/config/transcoding-temp","HttpServerPortNumber":8096,"SupportsHttps":false,"HttpsPortNumber":8920,"HasUpdateAvailable":false,"SupportsAutoRunAtStartup":false,"HardwareAccelerationRequiresPremiere":true,"LocalAddress":"http://192.168.50.149:8096","ServerName":"basement","Version":"4.3.1.0","Id":"ce44dcf077aa4ca8b5ba2977ba5ee46e"}

There's no reference to sessions.

 

Is it because sessions only supports user authentication? The FAQ states "Requires authentication as user".

 

My code in the autosuspend.conf is:

[check.XPath]
enabled = true
url = http://192.168.50.149:8096/emby/System/Info?api_key=855aba9194d44fb78d169bbfb4670970
xpath = /Sessions[@size>'0']

But I don't think its reading the xml correctly since it returns:

autosuspend.checks.TemporaryCheckError: Start tag expected, '<' not found, line 1, column 1 (<string>, line 1)
Link to comment
Share on other sites

chef

sessions do utilize authentication, but you're okay because of your API key. It's because you are requesting system/info.

 

try this:

http://{SERVER_IP}:8096/emby/Sessions?api_key={API_KEY}" 
Edited by chef
Link to comment
Share on other sites

Dodgexander

 

sessions do utilize authentication, but you're okay because of your API key. It's because you are requesting system/info.

 

try this:

http://{SERVER_IP}:8096/emby/Sessions?api_key={API_KEY}" 

thanks. That works better.

 

I picked up the system part from the authentication FAQ  :huh:

 

Now I have to figure out the best way to call something from that path to indicate a session is in process. Sadly there's no "Session Active=" tag.

 

When there's a current session the request remains full, so its not empty when there is no session at all.

Link to comment
Share on other sites

chef

So requesting that URL when there are no users connected doesn't return "{}"

 

EDIT: I see what you mean, the request is using an open session.

Edited by chef
Link to comment
Share on other sites

chef

@@Dodgexander

 

I've  figured it out my friend!

 

It was Swagger keeping an open connection and active account open when I initially tested.

 

If you close Swagger, and then close all open account, you will find that there are no User objects in the JSON response, when using the web browser url.

 

Is there away you can look for the absence of "UserName" in the response? 

 

If it's null then you know there are no connections, and you can trigger the sleep/hibernate.

Edited by chef
Link to comment
Share on other sites

Dodgexander

@@Dodgexander

 

I've  figured it out my friend!

 

It was Swagger keeping an open connection and active account open when I initially tested.

 

If you close Swagger, and then close all open account, you will find that there are no User objects in the JSON response, when using the web browser url.

 

Is there away you can look for the absence of "UserName" in the response? 

 

If it's null then you know there are no connections, and you can trigger the sleep/hibernate.

thanks.

 

Looking at the result of what is returned below it seems to count any requests to the API as a logged in session. This remains there even when all users are logged out.

[{"PlayState":{"CanSeek":false,"IsPaused":false,"IsMuted":false,"RepeatMode":"RepeatNone"},"AdditionalUsers":[],"RemoteEndPoint":"192.168.50.19","PlayableMediaTypes":[],"PlaylistIndex":0,"PlaylistLength":0,"Id":"09c0d5f6cd61aea2aa97325ad7060ea6","ServerId":"ce44dcf077aa4ca8b5ba2977ba5ee46e","Client":"Autosuspend","LastActivityDate":"2020-03-08T18:32:57.6654108Z","DeviceName":"basement","DeviceId":"ce44dcf077aa4caasdb5ba2977ba5ee46e","ApplicationVersion":"4.3.1.0","SupportedCommands":[],"SupportsRemoteControl":false},{"PlayState":{"CanSeek":false,"IsPaused":false,"IsMuted":false,"RepeatMode":"RepeatNone"},"AdditionalUsers":[],"RemoteEndPoint":"192.168.10.167","PlayableMediaTypes":["Audio","Video","Photo"],"PlaylistIndex":0,"PlaylistLength":0,"Id":"509bd6421f7190945fcdc1ccadc5d2a8","ServerId":"ce44dcf077aa4ca8b5ba2977ba5ee46e","UserId":"f561d86798ebdsf699a7faa35c28b8ce","UserName":"ben","Client":"Roku SG","LastActivityDate":"2020-03-08T04:37:58.2023008Z","DeviceName":"43' TCL Roku TV","DeviceId":"32f81dsab-6b13-5f0f-92e6-770b78asf67c7","ApplicationVersion":"3.0.193","AppIconUrl":"https://github.com/MediaBrowser/Emby.Resources/raw/master/images/devices/roku.jpg","SupportedCommands":["MoveUp","MoveDown","MoveLeft","MoveRight","Select","Back","GoHome","SendString","GoToSearch","GoToSettings","DisplayContent","DisplayMessage","SetAudioStreamIndex","SetSubtitleStreamIndex","PlayMediaSource"],"SupportsRemoteControl":true}]

For this to work I need something autosuspend can search for that defines a session is active or not based on an actual session, not a call to the API.

 

It would be a lot easier if Emby were to integrate a simple boolean for 'user active' and make it only count for those actually using the UI for browse or playback.

 

As it stands right now my 'session' is always going to be populated as the request is made to the API.

Edited by Dodgexander
Link to comment
Share on other sites

 

 

It would be a lot easier if Emby were to integrate a simple boolean for 'user active' and make it only count for those actually using the UI for browse or playback.

That would be fine.

Link to comment
Share on other sites

Dodgexander

That would be fine.

Can I make this request somehow?

 

I've searched through the difference in the /Sessions API both with an active viewer session and when the API is populated by the autosuspend script and I can't see a way to read whether a session is active unless I use a different username to play back content to authenticate via the API.

 

The other alternative is using one of the playback states such as 'is playing' or 'is paused' but it would mean the system could still sleep when someone is using the UI.

 

I will try and figure out how to check for active user whilst generating and using the api somehow as a different user. This way I should be able to prevent sleep when my other user is active.

Link to comment
Share on other sites

I can add something, yes. There is actually an ActiveWithinSeconds param.

  • Like 1
Link to comment
Share on other sites

Dodgexander

I can add something, yes. There is actually an ActiveWithinSeconds param.

thanks.

 

I can't find that parameter.

Link to comment
Share on other sites

Dodgexander

I have an issue open with autosuspend on Github and need to change my request to the server to return a response in XML rather than JSON.

 

I've tried:

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://192.168.50.149:8096/sessions?api_key=855sdsdad44fb78d169bbfb4670970

But I still receive a json response.

 

Any pointers for this noob? The api says its available in XML as well as JSON.

Edited by Dodgexander
Link to comment
Share on other sites

Well that should work but the reality is xml testing has fallen by the wayside because hardly anyone uses it. 

 

I'll look at it. In the meantime you could try adding &format=xml to the query string.

 

@@chef you still use xml in some cases, right?

Link to comment
Share on other sites

Dodgexander

Well that should work but the reality is xml testing has fallen by the wayside because hardly anyone uses it. 

 

I'll look at it. In the meantime you could try adding &format=xml to the query string.

 

@@chef you still use xml in some cases, right?

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://192.168.50.149:8096/sessions?api_key=855sdsdad44fb78d169bbfb4670970&format=xml

If so it seems to still output in JSON.

 

​So XML just isn't working right now?

 

I actually downloaded an app (postman) to test outside of terminal and the request returns the following as headers:

access-control-allow-headers →Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, Want-Digest, X-MediaBrowser-Token, X-Emby-Token, X-Emby-Authorization
access-control-allow-methods →GET, POST, PUT, DELETE, PATCH, OPTIONS
access-control-allow-origin →*
content-encoding →deflate
content-length →1069
content-type →application/json; charset=utf-8
date →Tue, 10 Mar 2020 22:21:19 GMT
expires →-1
server →UPnP/1.0 DLNADOC/1.50
vary →Accept-Encoding

So I guess this is why it doesn't work. As you said originally XML is not supported.

I will have to think of the best way to determine if a session is active by calling an external command. If i can use a command to return 0 if system is active, it should work. Perhaps I can use the api for this?

Edited by Dodgexander
Link to comment
Share on other sites

chef

Well that should work but the reality is xml testing has fallen by the wayside because hardly anyone uses it.

 

I'll look at it. In the meantime you could try adding &format=xml to the query string.

 

@@chef you still use xml in some cases, right?

I've switched mostly to JSON, the obvious plugin configurations are XML.

 

I'm going to test a couple requests here and see if the API still returns data as XML.

 

If it doesn't, and all we need is an endpoint to count session users in XML format. I can make that happen.

Edited by chef
Link to comment
Share on other sites

chef

I definitely get "Access token is invalid or expired." when requesting Users/Public with the "&format=xml"

Link to comment
Share on other sites

Seems to be working just fine for me using &format=xml.

 

I'll need to test the accept header.

Link to comment
Share on other sites

Try omitting this request header because you're not sending xml:

-H "Content-Type: application/xml"
Link to comment
Share on other sites

chef

Interesting, when testing the Sessions endpoint with the '&format=xml' (and an api key created in the dashboard) I get this response

Type 'Emby.Server.Implementations.Session.WebSocketController' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...