Jump to content


Photo

Emby Server api


  • Please log in to reply
146 replies to this topic

#1 PrincessClevage OFFLINE  

PrincessClevage

    Advanced Member

  • Members
  • 974 posts
  • Local time: 05:31 PM

Posted 24 August 2018 - 07:17 PM

Hello gents,
On the Mios Vera forums we have been discussing what is possible to integrate automation from Vera > emby using emby api
E.g
Would it be possible to use emby api to:
Play live tv selecting channel xyz on emby device xyz
Another example:
Would it be possible to use emby api to play xyz music on emby device xyz

If the above is possible could you please provide some guidance on where to find the appropriate api commands and which command might be valid to use in the above scenarios

#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 131347 posts
  • Local time: 03:31 AM

Posted 24 August 2018 - 11:02 PM

Hi, yes, all of that is possible. I would suggest checking out our api wiki:

https://github.com/M...owser/Emby/wiki

 

Please let us know if this helps. Thanks !



#3 PrincessClevage OFFLINE  

PrincessClevage

    Advanced Member

  • Members
  • 974 posts
  • Local time: 05:31 PM

Posted 25 August 2018 - 12:21 AM

Link to the Mios Vera thread:
Vera 2 Emby
https://r.tapatalk.c...45&share_type=t

#4 PrincessClevage OFFLINE  

PrincessClevage

    Advanced Member

  • Members
  • 974 posts
  • Local time: 05:31 PM

Posted 25 August 2018 - 12:28 AM

Hi, yes, all of that is possible. I would suggest checking out our api wiki:
https://github.com/M...owser/Emby/wiki

Please let us know if this helps. Thanks !

Thanks Luke,
I have started a thread on the Vera forums and hope it will get some traction there. Mios has been bought out and the new owners are suggesting deeper user interaction and improvements to the product so this will be a good benchmark to see if things improve. I must say if they get anywhere close to Embys model for employee and customer forum interaction it would be a huge improvement as I believe that Emby must be a market leader in this area!

#5 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 131347 posts
  • Local time: 03:31 AM

Posted 25 August 2018 - 12:34 AM

Thanks for the feedback !



#6 cw-kid OFFLINE  

cw-kid

    Advanced Member

  • Members
  • 1211 posts
  • Local time: 08:31 AM
  • LocationEngland

Posted 25 August 2018 - 11:16 AM

Hi

 

I've been looking at the Emby API to try and send some simple http commands from Vera using wget to the Emby server to control an Emby client device etc. 

 

I can get some of the curl commands working OK but when I try to use a http command in the browser it says: 

 

Unable to find the specified file.

 

I posted about this on the Vera forum as well here:

 

 

Under SessionService you can use the following to list the current sessions and get a session ID number.
 
/Sessions Gets a list of sessions
 
I then used the: 
 
/Sessions/{Id}/Playing/{Command} Issues a playstate command to a client
 
I wanted to try and Play / Pause a movie that was playing in Emby on my Android tablet. 
 
The Swagger constructs the following commands:
 
CURL:
 
curl -X POST "http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/PlayPause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "accept: */*" -H "Content-Type: application/json" -d "{\"Command\":\"PlayPause\",\"SeekPositionTicks\":0,\"ControllingUserId\":\"string\"}"
 
The curl command works OK and pauses / plays the movie on the Android tablet.
 
However the http command if I run that in a browser I get the response: "Unable to find the specified file." and it does not work. 
 
http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/PlayPause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 



#7 PrincessClevage OFFLINE  

PrincessClevage

    Advanced Member

  • Members
  • 974 posts
  • Local time: 05:31 PM

Posted 26 August 2018 - 03:51 AM

Can any Emby gurus help out here please?

#8 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 131347 posts
  • Local time: 03:31 AM

Posted 26 August 2018 - 11:14 AM

First, did you consult the wiki? You can also review our JavaScript libraries:

https://github.com/M...ient.Javascript

 

Emby apps use these libraries directly so you can find examples for just about everything that you need to do.



#9 chef OFFLINE  

chef

    Advanced Member

  • Developers
  • 3833 posts
  • Local time: 03:31 AM
  • LocationPeterborough, Canada

Posted 27 August 2018 - 07:29 AM

There has to be specific headers in the request.

I have examples of Ajax requests I can post here.

I also seem to remember having to use SHA encoding and MD5 encoding if I recall.

#10 cw-kid OFFLINE  

cw-kid

    Advanced Member

  • Members
  • 1211 posts
  • Local time: 08:31 AM
  • LocationEngland

Posted 27 August 2018 - 08:00 AM

There has to be specific headers in the request.


So looks like we won't be able to send simple one line http JSON commands from Vera to Emby then.

Another usage example, would be sending popup notifications to Emby client devices from the Vera HA controller, when something happens for example a doorbell trigger.

#11 chef OFFLINE  

chef

    Advanced Member

  • Developers
  • 3833 posts
  • Local time: 03:31 AM
  • LocationPeterborough, Canada

Posted 27 August 2018 - 08:25 AM

So looks like we won't be able to send simple one line http JSON commands from Vera to Emby then.

Unless adding the API key to the end of the URL stops the nessessity of headers.

Cw-kid Is there no way of adding headers to a Lua wget method?

Edited by chef, 27 August 2018 - 08:25 AM.


#12 chef OFFLINE  

chef

    Advanced Member

  • Developers
  • 3833 posts
  • Local time: 03:31 AM
  • LocationPeterborough, Canada

Posted 27 August 2018 - 09:19 AM

here is a weget example using lua?

wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
--header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
--header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
--header="Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7" \
--referer=http://www.site.com/dc/517870b8cc7
http://www.site.com/download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx

Here are the headers for emby:

Authorization=Emby UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", 
Client="Android", Device="Samsung Galaxy SIII", DeviceId="xxx", Version="1.0.0.0"

But in order to get a list of users you would make a call to public users, the choose an ID.

 

The public users endpoint doesn't need a token to get information. It is an open endpoint.

 

You can then use the information from that return to build your headers for following requests.

 

The next request would be to authorize a specific user, using the header example above.



#13 chef OFFLINE  

chef

    Advanced Member

  • Developers
  • 3833 posts
  • Local time: 03:31 AM
  • LocationPeterborough, Canada

Posted 27 August 2018 - 09:27 AM

I'm thinking it might look like this:

wget "{embyUrl:Port}/Users/Public"

That will return a list of users.

 

Maybe try:

wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
--header="Accept: application/json" \
--header="X-Emby-Token: {ApiKey}" \
http://{EmbyIp:Port}/{ApiEndpoint}

Or something similar. I also could be completely wrong.

 

Or maybe I helped.

 

I think it might actually be something like this:

wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \
--header="Accept: application/json" \
--header="X-Emby-Token: {ApiKey}" \
--header="Authorization=Emby UserId=\"{userId}\", Client=\"Vera\", Device=\"{VeraDeviceType}\", DeviceId=\"xxx\", Version=\"1.0.0.0\""
http://{EmbyIp:Port}/{ApiEndpoint}

Like I say if it where a C# based service monitor which watched for events in Vera, and triggered Emby command lines. I have already written it. But I know this is about a lua based plugin for vera.


Edited by chef, 27 August 2018 - 09:58 AM.


#14 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 131347 posts
  • Local time: 03:31 AM

Posted 27 August 2018 - 05:35 PM

So looks like we won't be able to send simple one line http JSON commands from Vera to Emby then.

Another usage example, would be sending popup notifications to Emby client devices from the Vera HA controller, when something happens for example a doorbell trigger.

 

Are you not able to attach request headers?



#15 cw-kid OFFLINE  

cw-kid

    Advanced Member

  • Members
  • 1211 posts
  • Local time: 08:31 AM
  • LocationEngland

Posted 28 August 2018 - 08:33 AM

The problem is I don't really know what I am doing. 

 

I just found some sample code on this Vera wiki page here.

 

If I run the code below (Method 2) in the Vera Test Luup Code (Lua) window. It works and the video playback on the Emby Android client app, then pauses or plays. 

require('ltn12')
  local http = require('socket.http')
 
  -- 5 Second timeout
  socket.http.TIMEOUT = 5
 
  local response_body = {}
  local request_body = ''
 
  local r, c, h = socket.http.request{
    url = 'http://192.168.1.101/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    method = "POST",
    port = 8096,
    headers = {
      ["Content-Length"] = string.len(request_body),
      ["Content-Type"] = "application/x-www-form-urlencoded"
    },
    source = ltn12.source.string(request_body),
    sink = ltn12.sink.table(response_body)
  }

I have no idea if this is the proper or best way to send a wget command from Vera to Emby  ?

 

It doesn't seem to matter what the content type is either: ["Content-Type"] = "application/x-www-form-urlencoded" or ["Content-Type"] = "application/json" work.

 

Maybe @chef can give us some better Lua code examples? for interacting with Emby and sending control commands to it from Vera etc. 

 

Ideally we need a LUA based plugin for Vera to monitor / control Emby. 


Edited by cw-kid, 28 August 2018 - 08:40 AM.

  • chef likes this

#16 cw-kid OFFLINE  

cw-kid

    Advanced Member

  • Members
  • 1211 posts
  • Local time: 08:31 AM
  • LocationEngland

Posted 28 August 2018 - 08:39 AM

I just tried Method 3 from the Vera wiki page and that code works also and the Emby Android client app pauses or plays OK:

local http = require("socket.http")
 
  -- 5 Second timeout
  http.TIMEOUT = 5
 
  -- The return parameters are in a different order from luup.inet.wget(...)
  result, status = http.request("http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "run=run")


#17 cw-kid OFFLINE  

cw-kid

    Advanced Member

  • Members
  • 1211 posts
  • Local time: 08:31 AM
  • LocationEngland

Posted 28 August 2018 - 08:47 AM

But simply running this one line of code from Vera does not work:

luup.inet.wget("http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")


#18 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 131347 posts
  • Local time: 03:31 AM

Posted 28 August 2018 - 11:35 AM

 

But simply running this one line of code from Vera does not work:

luup.inet.wget("http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

 

And you understand why, right?



#19 cw-kid OFFLINE  

cw-kid

    Advanced Member

  • Members
  • 1211 posts
  • Local time: 08:31 AM
  • LocationEngland

Posted 28 August 2018 - 12:33 PM

And you understand why, right?


Not really LOL.

Because it needs a socket connection and headers?

#20 chef OFFLINE  

chef

    Advanced Member

  • Developers
  • 3833 posts
  • Local time: 03:31 AM
  • LocationPeterborough, Canada

Posted 28 August 2018 - 12:35 PM

Because one is a 'post' method and the other a 'get' method.


Edited by chef, 28 August 2018 - 01:07 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users