MediaBrowser / emby-theater-electron

An Electron app for Emby
https://emby.media
GNU General Public License v2.0
126 stars 51 forks source link

Get Current Media Info. #80

Open AdamKearn opened 4 years ago

AdamKearn commented 4 years ago

Hi Guys,

I am looking at adding Discord Rich Presence support to emby. I have been looking at videohandler.js and found some events that I might be able to attach discord rich presence to: videohandler.js#L7-L35

I just want to know if there is a way to get the current playing media info? I am looking to try and implement this myself but I just need some pointers to get the current playing media name/time-left.

Any help is greatly appreciated.

Regards, Adam.

LukePulverenti commented 4 years ago

Hi, what is your ultimate end game? What you're looking at here would only apply to one single app. Wouldn't you rather handle it at the server level so that you can listen to events from all emby apps?

AdamKearn commented 4 years ago

Hi @LukePulverenti,

Yeah, when I was first looking into discord rich presence I was thinking of putting it on the server.

But when looking at the documentation and doing some testing myself. It only works if the rich presents is updated on a device that is signed into the discord desktop app.

I'm assuming it uses some locally cashed cookies.

So having the code to update discord rich-presents would have to be run on the client.

Now I think about it more it might make more sense to put this into a plugin and have the JavaScript that updates discord run in the users browser.

Then it should work on emby-web and emby-electron.

Can you let me know if it would be possible to include some client side JavaScript in a plug-in?

Thanks again @LukePulverenti for the quick response :)

EDIT: Here is a quick mockup that I've done on my phone of what it will look like:

image

LukePulverenti commented 4 years ago

Why exactly does it need to happen on the client instead of the server?

AdamKearn commented 4 years ago

Hi @LukePulverenti,

It has to happen on the client device because there is no authentication with discord rich presence (AFAIK). The only thing discord rich presence takes is your application ID (this is known as a client_id which can be a bit misleading)

It has to run on the client device as that will have the session cookies with the user's discord login.

I know it would make more sense to have it run on the server, but with discord current SDK it won't work like that. And I doubt it will be changing anytime soon.

FYI I was going to use this package for handing the rich presence requests: https://github.com/devsnek/discord-rich-presence

LukePulverenti commented 4 years ago

You could build a server plugin and put the discord authentication into the configuration of that plugin. Then the plugin can listen for server playback events and will work with all Emby apps.

Alternatively you can do this without a plugin using your own application and the Emby WebHooks feature. Users can configure discord rich presence in your app, then the Emby WehHooks feature will send notifications directly to your app. All you need to do is write code to receive those http requests and process them appropriately.

AdamKearn commented 4 years ago

Hey @LukePulverenti, Just wanted to pick this up again.

There is no point making it a plugin as discord rich-presence will only work on the desktop app. (Not Mobile) So it seems pointless making it a plugin that would run on all platforms as it only works on the desktop app.

It would make more sense to just include it in the electron app. Do you know if it's possible to intercept playback events from within the electron app with your current codebase? Then we can trigger the discord API to update the rich presents.

I've quickly looked over some of the code on my lunch break but couldn't see a way to detect playback evens directly from within electron.

LukePulverenti commented 4 years ago

Well there is a point to doing a server plugin or doing this with webhooks, which is that you could do it now on your own using existing api's rather than having to depend on changes to this app. None of that exists directly in the app and therefore it would require that development.

AdamKearn commented 4 years ago

Well, to do it via webhook you would have to expose a web server running inside the electron app. As the discord API can only be updated from the host with the discord app installed. It can't be updated from another computer without having the same cookies.

Unless you queried the emby API every minute checking to see if any content was playing.

With my current understanding of the API that can be done by querying the /Sessions endpoint: https://embyIP/emby/Sessions?api_key=12345

Do you know of any other ways to get this information? That could be used within the election app?