ColinDuquesnoy / MellowPlayer

Moved to gitlab
https://gitlab.com/ColinDuquesnoy/MellowPlayer
GNU General Public License v2.0
233 stars 26 forks source link

Loading Album information in the Spotify plugin #273

Open mariusor opened 6 years ago

mariusor commented 6 years ago

Description:

A followup to #272.

Unfortunately I haven't found any simple way of extracting the album information from the player web-page.

Is it possible to reuse the web-player authenticated session to actually execute an API request?

For example the hyperlink of the anchor representing the title of the song contains the album id. Which we could use to execute an API request1 GET https://api.spotify.com/v1/albums/{id}

Basically my questions are:

  1. Does the plugin support a mechanism for creating an XHR request ?
  2. Does the plugin support triggering this request without interfering with the rest of the functionality?
  3. Does the plugin support reusing the authenticated user session of the player?

Additional Information:

[1] https://developer.spotify.com/documentation/web-api/reference/albums/get-album/

mariusor commented 6 years ago

OK, so I managed to solve the first two questions.

The only problem is to extract a valid Authorization: Bearer XXX header from the other requests. Does anyone have any advice?

mariusor commented 6 years ago

Update.

I have a working version of the Spotify plugin which loads the data from the API, but the only missing part is the Authorization header which needs to be intercepted from the other requests.

Since there isn't any way to intercept them at DOM level, I was thinking that maybe it's possible to use QWebEngineUrlRequestInterceptor from the Qt code to extract this header and then make it available it in the spotify plugin script.

@CDuquesnoy is this a feasable option? (I'm asking because my Qt is very rusty, and the new QWebView APIs are completely foreign to me)

ColinDuquesnoy commented 6 years ago

Everything is possible, but I don't like the idea to add c++ code specifically for a plugin. I'd prefer if plugin specific code would remain in the plugin itself.

I've never done that but wouldn't it be possible to simply redefine the prototype of HttpRequest.open? This blog post might help you get started: https://dmitripavlutin.com/catch-the-xmlhttp-request-in-plain-javascript/

ColinDuquesnoy commented 5 years ago

This issue has been moved to our new gitlab issue tracker.

The github repository will be archived soon and this issue will become read-only. We suggest you continue the discussion and follow the progress on this issue at gitlab.