Skip to main content
Topic: fb2k API questions (Read 5646 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: fb2k API questions

Reply #25
1. Is it possible to create a custom auto-playlist, i.e. an auto-playlist that is managed by component?
Scenario: Spotify (a music streaming service) provides a playlist interface via an url. So ideally, a user could pass such link to the component, which would create an playlist that would be periodically synchronized with the Spotify service.
Considering that the component is responsible for periodically populating the playlist, you can easily reproduce such a scenario, if you set a playlist lock (playlist.h, playlist_lock) to the target playlist, which will be only deactivated during populating the playlist.

Re: fb2k API questions

Reply #26
Autoplaylists are internally implemented via playlist locks. It's not that pretty but works.

Current autoplaylist API only filters Media Library content, rather than providing its own content.

Re: Add Location - it's meant for remote resources... subsongs are not supported for such in general. You'd have to parse the location as a playlist instead.

Re: fb2k API questions

Reply #27
@fbuser , @Peter , thanks for the answers!

Considering that the component is responsible for periodically populating the playlist (...)

But is it possible to somehow `assign` a playlist to the component? I would not want to edit a random user-playlist if they decide to name it the same as component-managed-playlist =)

You'd have to parse the location as a playlist instead.
Could you, plz, point to the appropriate API for that?

Re: fb2k API questions

Reply #28
But is it possible to somehow `assign` a playlist to the component? I would not want to edit a random user-playlist if they decide to name it the same as component-managed-playlist =)
Yes, you could mark that playlist with playlist_manager_v2::playlist_set_property() so you can distinguish this playlist from a user-playlist with the same name.

Re: fb2k API questions

Reply #29
Could you, plz, point to the appropriate API for that?

You already have this implemented as plman.AddLocations in SMP using process_locations_notify and playlist_incoming_item_filter_v2 - >process_locations_async

Re: fb2k API questions

Reply #30
@snotlicker , I'm not sure that these are applicable for my case: AFAIK these are used to handle callbacks *after* `FIle`>`Add location...` was invoked. And in my scenario I need to override the default behaviour of `Add location...` to generate the list of items first.

I've found `playlist_loader` API which looks exactly like the thing I need, but it doesn't work reliably for all cases and it can't handle arbitrary strings. E.g. `https://open.spotify.com/playlist/191UV79Bhgy1mBJOVfIpeS` fails with error `Object not found` for some reason. While `https://open.spotify.com/album/06bbY7KesJd8be5vQOMBxw` works fine :\


Re: fb2k API questions

Reply #32
@Peter , would it be possible to make `playlist_loader` receive a path even if it's not recognized by fb2k? E.g. pass smth like `unrecognized` to `playlist_loader::is_our_content_type()`

Re: fb2k API questions

Reply #33
The previous component was able to differentiate the different url types here??

https://github.com/stengerh/foo_input_spotify/blob/master/foo_input_spotify/input_spotify.cpp#L103L117

I guess libspotify did all the work but for whatever reason, the user playlist handling is borked while track/album urls load just fine. Isn't this where you need to step and in and make your web request to the spotify API and generate a list of track urls which libspotify can then open/play??

Re: fb2k API questions

Reply #34
The previous component implemented everything via `input` interface: `album` and `playlist` objects would be handled as a multi-track file (like CUE files). Such behaviour has a lot of limitations, that's why I'm trying to use `playlist` interface instead and use `input` only for single tracks.

Isn't this where you need to step and in and make your web request to the spotify API and generate a list of track urls which libspotify can then open/play??
That's actually what I'm trying to do =)
It's all fine and dandy for `album` urls, but for some reason fb2k discards spotify `playlist` urls, making it impossible to generate a playable item set... There are no such limitations for `input` interface though.

Re: fb2k API questions

Reply #35
Add your own main menu entry/input box. Now you have full control over how urls are handled.

Re: fb2k API questions

Reply #36
Add your own main menu entry/input box.
That's my Plan B =)
But I would rather use (and integrate in) standard fb2k interface as much as possible.

Re: fb2k API questions

Reply #37
Then you won't be able to take over arbitrary URLs. For the standard Open Location prompt, you can only control either whole schemas, or the MIME type that the server returns when the file is retrieved using foobar's built-in HTTP/S handler.

Re: fb2k API questions

Reply #38
you can only control either whole schemas
Sorry, I don't understand what you mean by that (most likely due my lack of knowledge). `MIME type` is controlled via playlist_loader::is_our_content_type. Is there a similar interface to handle the `schema` (w/e it means in this context)?

(...)when the file is retrieved using foobar's built-in HTTP/S handler.
Any tips why this handler would reject a valid url?

Re: fb2k API questions

Reply #39
It accepts it, if it understands what file type it is. You have to register a playlist handler that accepts the exact MIME type your file returns. Otherwise, it will reject it.

Also, if it requires a login, there's no way to pass the login cookie or session to the URL handler, because every URL request handled this way explicitly passes zero cookies and only the exact information contained within the URL string.

As for the schema, you would have to register your own filesystem handler for a new protocol name, something like httpspotify or whatever, and you'd have to handle your own URL requests, or forward them to the existing https handler by modifying the URL and opening it directly yourself.

Re: fb2k API questions

Reply #40
Thanks for the info!
I've tried fetching the Spotify playlist url via curl with a plain GET request and it does indeed return a 404 error for some reason (it is accessible in browser without logging in though)... Not sure what's the deal with that (and why it works in browser), but it's clearly not the fault of fb2k.

As for the schema, you would have to register your own filesystem handler for a new protocol name
Would it work properly if I implement a new handler that tries to handle `http(/s)`? I.e. would it conflict with the built-in one? Or would such approach be not recommened/too hacky/error-prone/unstable or w/e?

Re: fb2k API questions

Reply #41
Darn... This problem affects drag-n-drop functionality as well: if the GET request for the link returns 404, fb2k prevents further item processing with "Object not found" message =(

Re: fb2k API questions

Reply #42
I've figured it out why URL returns 404: it requires a proper user agent header (e.g. "User-Agent: Firefox/79.0").
Google says there are quite a few of websites that refuse to work (by returning 404) with empty or non-browser-specific user-agents...

@Peter , @kode54 , would it be possible to attach some user agent when resolving links? (perhaps configurable via Advanced Preferences)

 
SimplePortal 1.0.0 RC1 © 2008-2020