chadwpalm / Lumunarr

Connector application for using Plex Webhooks with Philips Hue Bridges.
GNU General Public License v3.0
52 stars 0 forks source link

Feature request: scene activation delay #6

Closed nimbleghost closed 1 year ago

nimbleghost commented 1 year ago

This could be a quirk of Plex's end credits detection, but in my experience watching a few things with HuePlex enabled, the scene is activated approx. a few seconds (I'd have to measure) before the episode ends. This can be a little jarring, as it can ruin a cliffhanger (e.g. you know the episode is imminently ending a few seconds before it actually does).

I wonder if adding a configurable delay, perhaps per-event, would be a good idea. e.g. I could configure a 3 second delay only on scrobble. I'd be happy to contribute this! It could be a simple setTimeout after receiving the webhook payload.

I'm also curious to hear your experience with the end credits / scrobble event on your setup.

chadwpalm commented 1 year ago

I have noticed that the lights will change a second or two before the end credits happens both on movies and tv shows. Not sure why Plex chose to send the webhook slightly early. If I had to guess a reason, it is because the scrobble function is meant for sending signals to platforms like Trakt to indicate that something has been watched and they might push out the webhook early in case the user wants to stop the stream as soon as they see credits and they want to make sure the services are notified before that happens. Just a guess though.

Since HuePlex is dependent on the webhook the only solution at this point would be to do what you suggest, to add a delay option. I'm not sure if a delay is particularly necessary on all of the other functions (unless you've seen behavior to the contrary), so it may just be okay to have it on scrobble as to not clutter up the selection page too much.

I don't want to blanket add the delay on the backend as some people might not want it, so I'll add a selection item as an option with maybe selections from half a second to 5 seconds with half-second intervals. I don't want it to be a fill-in option because if someone screws up and puts in a really long interval by accident it will require a restart of the app.

I was planning this week to add a few other features, like time schedules for when the profiles will be active, and I want to create a global settings page as well so that you can not only change settings for each profile, but globally as well if you choose. I can add in this feature to that release, but I'm going to try and get a hot-fix out for the other issue you gave for the zones.

nimbleghost commented 1 year ago

Yeah, a value with a narrow range for just the scrobble event seems like a good solution! I'd like to work on this if that's okay, now that we're aligned on the details.

chadwpalm commented 1 year ago

Sure. If you wanna take a stab at it I'll set you up a feature branch and give you access to it, that way when you push to it the build server will build it and create a tag for that branch on Docker Hub for you to test locally. I personally work locally for easier testing before pushing it to GitHub. If you go through the Native install (https://github.com/chadwpalm/HuePlex/wiki/Installation#native) you can run HuePlex locally for testing that way. The gitignore will keep the node-modules from uploading to GitHub when you do decide to push. I don't think you will have merge capabilities, so when you are done please do a pull request and I'll merge it in and bump the rev.

A couple things to keep in mind:

  1. After adding the selection to the UI you will need to update the submit handler to add the new value to the config file, so the backend webhook handler can pick it up. (The config file is the mediary between the frontend and the backend)
  2. Make sure the config file is forward compatible.....meaning that those who upgrade versions will still have their older config files, so if there is no scrobble delay item in the config it doesn't error out when the webhook code is executed. This can either be handled by doing a check for "undefined" in the webhook code, or by adding code to add a default scrobble delay item on the first loading of the app after the update. I did this for the new active toggles I put on the profiles. The file backend/load.js always runs at application start (or when you hit refresh on the browser) and my example is the block of code from lines 51 to 55.
  3. Any time you make changes to the frontend UI, you need to rebuild it using "npm run build" from the HuePlex/frontend directory. This creates the static page that the webserver uses to display the frontend.
nimbleghost commented 1 year ago

Thanks for the pointers. Will look into this later today.