Jump to content

Webhooks Plugin


nxenos83
 Share

Recommended Posts

I put together a plugin that triggers a POST to URL whenever playback starts, stops, pause, or resumes. You can configure which events and which content types you would like the webbook to be triggered.

Content of the post is a json that conforms with the format being used by Plex webhooks. Currently, the json only contains the following:



{
 event: "(media.play, media.stop, media.resume, media.pause, or media.added)",
 Player{
  uuid:"Emby device ID",
  title: "Emby client name"
 },
 Metadata{
  guid: "Item ID""
  type: "content type"
  title: "item title"
  parentTitle: "items parent name",
  grandparentTitle: "items grandparentTitle"
 }
​}


 

I understand that there is a plan to fold webhooks into the core application at some point in the future, but until then you can use this plugin.  

I am willing to add additional functionality as requested if there is sufficient need from the community (or others can contribute https://github.com/nxenos83/emby.plugin.Webhooks

If there is sufficient interest in this plugin, I can make a request to have it added to the plugin catalogue, but will need to get feedback from the community.

 

3/1/2017: Added logic to ignore virtual items

9/16/2017: Changed target to .Net 1.3 to be compatible with .net Core (https://github.com/nxenos83/emby.plugin.Webhooks/releases/tag/v1.0)

 

Edited by nxenos83
  • Like 1
Link to comment
Share on other sites

First of all thanks for the work and already implementing some of my request outside of this thread! Secondly you seem to have a closing paranthesis in that link so it's not clickable ^^

 

Keep it up. Been using it and works like a charm.

 

~Cheers

Link to comment
Share on other sites

Hey today I got a Webhook call for an episode that's not in my library. I think it was during a library scan or some similiar scheduled task. Corrosponding log file entry:

2017-02-28 08:47:51.8152 Info App: Removing missing/unaired episode Trickster 1x20
2017-02-28 08:47:51.8460 Info App: Creating virtual unaired episode Trickster 1x20

~Cheers

Link to comment
Share on other sites

@mpearson

 

I could look to make header, content, and request type configurable. Most of the effort for me would be setting up the configuration page. BUT it looks like wink's api requires an OAuth token with each request. You would have to update the header each time the token expired. In pwoershell, do you have to pass your credentials every time? Setting up the plugin to send the Oath request and then use the token from that in subsequent requests AND making it easily configurable to be used by multiple services is a bit more of an effort.

 

I see three routes to go to extend this plugin to help with wink:

 

1. I can look into the possibility of triggering a local script through the plugin. That way you can wrap your existing powershell commands in a script that can be called on the events

2. Add the ability to configure the header, content, and http request type that is triggered. I'm assuming you would need to update the header config often, so you would probably end up needing to run a ps script to get a new access token and then edit the config's xml file

3. Create a plugin for wink that makes emby act as a sensor. I don't have a wink hub to help here. But maybe someone else in the community does. I would be happy to work on something like this if you'd like to donate a hub :)  Outside of that, if you can provide the details on the OAuth request and response, I can put it together-hope for the best- and send your way for testing

Link to comment
Share on other sites

Hey today I got a Webhook call for an episode that's not in my library. I think it was during a library scan or some similiar scheduled task. Corrosponding log file entry:

2017-02-28 08:47:51.8152 Info App: Removing missing/unaired episode Trickster 1x20
2017-02-28 08:47:51.8460 Info App: Creating virtual unaired episode Trickster 1x20

~Cheers

 

Ah, didn't even consider the upcoming episodes. Updated plugin to ignore virtual items

  • Like 1
Link to comment
Share on other sites

Ah, didn't even consider the upcoming episodes. Updated plugin to ignore virtual items

Maybe you could add it as a release on github as well? I searched for the download a bit until I realized you edited your first post :)

 

Regarding the 3 ways of doing thing regarding WINK-API. I think a plugin for Wink would be the worst way to go tbh. As it would transfer from a Webhook into a polling scheme. Which means updates depend on the wink api refresh rate. I thought about making the HTTP header configurable as well in my original answer BUT thought it would be to much too ask of you.

For wink there seems to be a way of getting a client_id and a client_secret if you email them, which then works over the cloud at least that's how the home assistant component is described here https://home-assistant.io/components/wink/

 

~Cheers

  • Like 1
Link to comment
Share on other sites

Good idea, I'm just getting familiar with GitHub.

 

So default configuration will be to send the post with formatted JSON, but I'll add an advanced option that allows for the type, header and content to be changed. In the advanced I'll also add an option to send the commands sequentially or async. If it's being used to control lights, might want to first send a command to save light states before sending a command to turn them off.

 

Then I see the next request is to filter based upon client devices.... no wonder plex just stopped with a formatted json and left it up to external application to parse it.

 

BTW: I'm disappointed that wink requires internet access to control. I'm in the process of evaluating smartthings, insteion and wink. Was excited about wink's pricing and the cool in wall command relay.. but now I way have to take it out of consideration

  • Like 1
Link to comment
Share on other sites

Yeah on that note. Due to plex letting the application handle the parsing we have some real trouble back at home assistant because plex is also sending a base64 encoded picture with a multipart request which is not correctly handled in home assistant at this point.

 

So your ideas sound really awesome (especially like the customizable header part) but also like a lot of work. Looking forward to test stuff :)

 

~Cheers

Link to comment
Share on other sites

could this work with https://simkl.com/596511/  Simkl has a webhook that works with plex

As far as I can tell yes. Just copy the link you get from simkl into the emby plugin instead of the plex webhooks page. As long as nxenos keeps the json according to the plex one this should work.

 

~Cheers

Link to comment
Share on other sites

could this work with https://simkl.com/596511/  Simkl has a webhook that works with plex

 

That was the intention of using the same format that plex uses. Right now, the output is not fully populated, so it is possible that we are missing a piece of data that this service relies on. Give it a shot and let us know :)

Link to comment
Share on other sites

@@mayberts

Just looked into this a bit more, and I currently don't handle two of the events that plex does (media rated and media viewed).

I just about have a change completed that allows custom headers and content, but I will turn my attention to getting these items added.

 

I just purchased my first house, so there isn't a lot of free time to work on it, but I'll shot for having something put together by the end of this week.

  • Like 1
Link to comment
Share on other sites

Thanks for looking into this and getting back to me.  Good luck with your new house, I know how stressful that can be at times

Link to comment
Share on other sites

  • 1 month later...

Finally got things settled here at home and got my developement environment in place.

 

I acquired a networked projector and and 2.35:1 screen, so I have a need to execute shell commands based upon aspect ratio to auto zoom. Im doing this with a python script, so I'll be adding in script execution as an option to the webhooks in the coming week. Got it working on Windows, will need some help checking on Linux and osx boxes.

 

Sorry for the lack of action here, just been busy with the new house and my day job :)

Edited by nxenos83
Link to comment
Share on other sites

No worries. Glad everything worked out so far on your end. I'd be happy to provide the testing from a linux side. Running it on a 64-bit debian.

 

~Cheers

Link to comment
Share on other sites

  • 5 months later...

@PhyberApex looking into updating to support new plugin requirements for .net core. Doesn't look that complicated to make the change. I will find some time on the weekend to take care of this.

  • Like 1
Link to comment
Share on other sites

@PhyberApex I think I did everything correct. I didn't see any errors when loading the plugin on .Net Core standalone server.  Let me know if you run into any troubles:

 

https://github.com/nxenos83/emby.plugin.Webhooks/releases/tag/v1.0

Works on my end so far. I only have a test installation as of now. Will report back after emby is switched over completely to .net core. Thanks for the fast work! You are awesome!

 

~Cheers

Link to comment
Share on other sites

  • 1 month later...

I took some time tonight to expand your work and fill in some of the gaps for use in my own tool -:

 

{
"event": "media.play",
"user": false,
"owner": false,
"Account": {
"id": "redacted",
"title": "redacted"
},
"Server": {
"title": "redacted",
"uuid": "redacted"
},
"Player": {
"local": true,
"publicAddress": "192.168.1.110",
"title": "Emby Mobile",
"uuid": "redacted",
"name": "Chrome"
},
"Metadata": {
"guid": "28e0459a-a0a2-acc1-8af2-fd4048131dd6",
"librarySectionID": 0,
"type": "music",
"title": "Major Tom (völlig losgelöst)",
"grandparentTitle": "Atomic Blonde",
"parentTitle": "Atomic Blonde OST",
"index": 2,
"ratingCount": 0,
"addedAt": 0,
"updatedAt": 0,
"runTimeTicks": 2992590080
},
"Session": {
"sessionId": "804e5453f78093d5d63288ab20edfe22",
"positionTicks": 0,
"timestamp": "2017-11-11 02:53:51.663"
}
}
 
Submitted a PR in case you're interested.
Edited by randomevents
  • Like 1
Link to comment
Share on other sites

Is it possible to post to a GroupMe chat using this?  I currently have a script that runs every hour checking for new items added and it'll use a curl command to post to a specific GroupMe chat.

 

Ex: 

curl -d '{"text" : "Your message here", "bot_id" : "XXXXXX"}' https://api.groupme.com/v3/bots/post

Would love a cleaner/more efficient way to accomplish this!

Link to comment
Share on other sites

Is it possible to post to a GroupMe chat using this?  I currently have a script that runs every hour checking for new items added and it'll use a curl command to post to a specific GroupMe chat.

 

Ex: 

curl -d '{"text" : "Your message here", "bot_id" : "XXXXXX"}' https://api.groupme.com/v3/bots/post

Would love a cleaner/more efficient way to accomplish this!

 

If you have a compiler, all you have to do is change 3 lines of code. If not, PM me and I'll make you a custom dll

Link to comment
Share on other sites

{

"event": "media.play",
"Session": {
"sessionId": "804e5453f78093d5d63288ab20edfe22",
"positionTicks": 0,
"timestamp": "2017-11-11 02:53:51.663"
}
}

 

Is that positionTicks as in "when stop webhook is received, percent watched is positionTicks/runtimeTicks"?  Would make my life way easier if I could use that to infer that a file has been watched.

Link to comment
Share on other sites

  • 3 months later...

Hey, I don't know when it actually started but I started to receive stop webhook even tho my file is clearly still going...they happen one time into a movie / series after about 5-10 minutes. Anything that could be done about this? My lights always going full bright 10 minutes in is kind of annoying and I had to disable that webhook for now.

 

~Cheers

Link to comment
Share on other sites

  • 2 weeks later...
randomevents

Hey, I don't know when it actually started but I started to receive stop webhook even tho my file is clearly still going...they happen one time into a movie / series after about 5-10 minutes. Anything that could be done about this? My lights always going full bright 10 minutes in is kind of annoying and I had to disable that webhook for now.

 

~Cheers

 

Can you tell me what server version, app, transcoding? I can try and test it today

Edited by randomevents
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
 Share

×
×
  • Create New...