Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Current Media Info. #80

Open
AdamKearn opened this issue Sep 3, 2020 · 8 comments
Open

Get Current Media Info. #80

AdamKearn opened this issue Sep 3, 2020 · 8 comments

Comments

@AdamKearn
Copy link

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
Copy link
Member

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
Copy link
Author

AdamKearn commented Sep 4, 2020

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
Copy link
Member

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

@AdamKearn
Copy link
Author

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
Copy link
Member

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
Copy link
Author

AdamKearn commented Oct 28, 2020

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
Copy link
Member

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants