Arno500 / plex-richpresence

A fast and lightweight Plex app for Discord Rich Presence
40 stars 2 forks source link

feat: supply activity type, add buttons, other misc changes #26

Closed brw closed 3 days ago

brw commented 2 weeks ago

I've also added buttons to the activity for episodes and movies linking to details on Plex Discover, just like the track details on listen.plex.tv. I've gone through several different options for this and I've landed on linking to the Plex Discover page on app.plex.tv. We could also use watch.plex.tv for this but for some reason it doesn't show if any of the libraries you have access to contain the media item, while the Plex Discover page on app.plex.tv does. So while it's not as pretty it does have more information and can be accessed without an account all the same (I know quite a lot of people on Discord who also use Plex and often have access to my server so this is useful to them).

As I'm no longer ever showing the elapsed/remaining time I've also removed the setting for it. Could add it back though if people want to have the old behavior as an option but I'd say the time bar is a massive upgrade so I don't really see why you would.

I've also added a button to search YouTube for the artist + track title for songs as listen.plex.tv often doesn't have have links to other platforms for items in my music library. Could maybe change it to only show if listen.plex.tv doesn't have any external links, or could be removed entirely if you don't think people would find this useful.

Maybe I should've split these changes up a bit but oh well. I was experimenting with multiple things so it kind of came together organically.

This PR also depends on https://github.com/fawni/rp/pull/2 for the activity type but I don't know if that library is still being maintained so you might want to switch to something else or fork it.

Some pictures: Episode Movie Music
Screenshot from 2024-09-15 23-07-28 Screenshot from 2024-09-15 23-08-15 image
Show details on Plex Movie details on Plex Track details on Plex (unchanged)
Search on YouTube

Closes #25

brw commented 2 weeks ago

I haven't added French strings for the new buttons as I don't speak French of course (not particularly well at least lol), so you'll have to add those :P

brw commented 2 weeks ago

Let's see if the maintainer reacts in some days, if he does not, let's fork this (you can do it if you want!) and merge the PR in the fork

Sure thing. As I mentioned I don't have much Go experience, or experience with RPC/IPC/socket stuff (I'm primarily a web dev lol), but I suppose I don't have to let that stop me. I think we might as well use my fork now and maybe change it back if original maintainer continues working on their fork (doesn't look like it though, it's been almost two years).

You forgot to edit types.go:94 to remove the "TimeMode" key

Oops I'll remove it, and from settings/main.go as well.

It's kind of a detail, but I noted that the RP library tries to "read" everytime they send a command, which does not seem to be really working all the time :/. I replaced the line 81 in ipc/ipc.go like that:

        ipc.Socket.SetDeadline(time.Now().Add(time.Second))
    res := ipc.Read()
    ipc.Socket.SetDeadline(time.Time{})
    return res, nil

and it made the whole Discord integration much faster and errorproof. I was even wondering if we could skip the .Read() anyway (but that could cause memory leaks in the socket, or even block it I guess?)

Interesting. Can't say I've ran into any errors on my end, and I'm not seeing any differences with this either. Can't hurt though so I guess I'll add it in my fork anyway.

And even with that I'm also noticing that sometimes it'll report that it successfully set the Discord activity but nothing actually happened. Seems to resolve itself after a while as well though. Not quite sure why it happens.

Maybe we also want to retry setting the activity at least once in case Discord restarted since the last time the activity was set as it'll give a write: broken pipe error but recover the next time, or maybe add some more retrying logic in general, but I suppose that's not very urgent.

Arno500 commented 3 days ago

Maybe we also want to retry setting the activity at least once in case Discord restarted since the last time the activity was set as it'll give a write: broken pipe error but recover the next time, or maybe add some more retrying logic in general, but I suppose that's not very urgent.

That would definitely be a good idea for another PR!