keifufu / WebNowPlaying

WebNowPlaying browser extension. Provides support for browser-based players
MIT License
81 stars 10 forks source link

Usage with webpage in browser #26

Closed busybox11 closed 3 months ago

busybox11 commented 9 months ago

Hi, I don't think this is possible currently, though I figured I'd ask anyway.

I'd like to use this extension directly from a website. I don't need a locally hosted adapter, using the data this extension provides from the browser's data would be enough for me.

Have you thought about this usage before? Do you have any thoughts about it? Hope this isn't bothering you. I haven't seen any similar issue, comment or anything but I hope this hasn't been addressed before lol.

Have a nice day!

keifufu commented 9 months ago

Curious so I can maybe suggest solutions: what would be the use case for this in a webpage context?

busybox11 commented 9 months ago

I am the developer of https://nowplayi.ng/ (https://github.com/busybox11/NowPlaying-for-Spotify), a live-updating music visualizer website, that was originally designed for Spotify.

Turns out I've been getting multiple requests from many people to make it support other players. Unfortunately Spotify is the only service that has a public API that permits you to fetch the current playing state (albeit being forced to make use of polling).

Local players would technically be possible (also many people today are using web-based players anyway, YT Music for instance was one of my biggest requests).

This extension would be a great fit for my project, because I wouldn't have to make any desktop client or anything, the extension-based implementation would be basically seamless. I also don't have much time and wouldn't be able to do any heavy development, this extension sounds perfect for me.

keifufu commented 9 months ago

Unfortunately it's impossible to use WebNowPlaying in a webpage. WebNowPlaying (the browser extension) connects to local adapters via WebSocket and as far as I know there is no way to create a WebSocket server in a webpage.

WebNowPlaying does support local players on Windows, but that's handled via SMTC in the library which handles the WebSocket server.

So to use WebNowPlaying you'd always have to have a local daemon of some sort running. If that's something you can work with, then please wait until I finish work on WebNowPlaying-Library, which replaces the C# and Python libraries.

busybox11 commented 9 months ago

Yeahhh it's more or less what I've figured. I started a local music API a while ago but abandoned it very quickly as the Windows implementation was giving me a huge headache lol.

For browser-based media sessions only though, would this be doable? By ignoring local players entirely? As far as I understand this extension is able to retrieve media sessions of the browser right? This was my initial intent - I am not good at communicating lol.

I was thinking of some kind of event-based messaging system. IIRC there is an API in the Chrome Extensions spec that permits this (though it might very well be deprecated with Manifest V3 and to be 100% honest with you I haven't looked into any of that in quite a while).

My website could try to listen on the event bus (or whatever this is), if it gets a response then I use the extension data, if not, I don't connect. It sounds possible.

Sorry, I'm once again not that great when it comes to communication and being clear overall lol - I'm sorry if it was the case. I also haven't gotten the time to take a deeper look at it yet unfortunately, my apologies.

Thank you for your response!

keifufu commented 9 months ago

I believe it would be possible even with MV3. While I don't necessarily plan on spending a bunch of time implementing something like this, I might play around with this and see how viable it would be.

keifufu commented 9 months ago

I was able to get something very simple to work, the only shortcoming is that it does not allow you to read all players, but only the "active" one.

The code is simple enough and self explanatory. wnp.js (A gist for now until I update the extension)

Note that this will not work until I update the extension, which will be whenever I finish work on other related projects.

Please look through the code and let me know if something like this would work for you or if it's missing anything.

keifufu commented 9 months ago

I updated the repo for once so you could build it and test it locally :3 Link to wnp.js

keifufu commented 8 months ago

@busybox11 bumping as the extension has since been updated and my earlier draft has been included. Feedback would be appreciated! :)

busybox11 commented 8 months ago

Hi! My apologies for not giving you any updates - I didn't have much time for personal projects lately.

I'll try to look into this next week, I will have some time to test it. I'll make sure to send you feedback!

Thanks a lot, this sounds awesome!

keifufu commented 3 months ago

bump.

busybox11 commented 3 months ago

Hi!

Sorry to give you an update this late. I have pretty bad ADHD and still don't have lots of time for personal projects. Took the time to update you on it tonight - my apologies, sincerely.

I initially wasn't able to get any data. It turns out it came from SoundCloud apparently? Tried with YouTube and everything looks fine now. Gotta have to investigate more, but overall this is really nice! Thank you for the follow-up and sorry for replying this late!

For now I don't have the time to look into typedefs and more in-depth API, but this looks really usable overall. Thank you for the awesome work.

I'm in the process of rewriting my simple AlpineJS page into a fully-fledged React app, with multiple providers and more features. It will take time but this will be my next priority as soon as I have some free time or time off. Won't be soon but I'll keep you updated if needed.

Thank you once again!

keifufu commented 3 months ago

Thank you for the update. Good luck with your rewrite!