Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: fb2k API questions (Read 15435 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.
Microsoft Windows: We can't script here, this is bat country.

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 #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)

Re: fb2k API questions

Reply #43
@Peter,
another small question =)

Scenario:
- component has a custom `input_impl` implemented.
- user requests properties of multiple tracks (e.g. via selecting all those tracks and ALT-Enter).
- `input_impl::open` is called.

Questions:
- Is there any interface/callback/etc that would make it possible to process multiple tracks at once instead of one by one?
- If not, is it possible to force these to be executed parallely? I.e. several threads that would call `input_impl::open` simultaneously, so that it would be possible to batch requests manually inside the `input_impl::open` implementation.

Reason:
Operations performed in this custom `input_impl::open` are pretty slow, but they can be performed in batch for multiple tracks at the same cost as a single track.

Re: fb2k API questions

Reply #44
@Peter, another small question: is it possible to add component in run-time? At least for the purpose of updates and stuff in the components settings section.

Scenario: a C++ component is used as a host/loader/proxy for .NET components (I doubt there will be more than one though xD). Everything SDK related (callback registration and etc) is handled by the host C++ component. But I want users to be able to interact just as usual even with said .NET components (check for updates/add/delete and etc).

Re: fb2k API questions

Reply #45
Probably not, for the same reason it's currently not possible to remove a component at run-time. All callback services must finish executing and be removed from registration. All input services currently decoding files must be removed from registration and cease operation. Basically every service that could be registered must be released by every other still-running service so it isn't referenced again. And things like initquit services must be called to simulate app shutdown for that component, in case the component relies on it for things like saving configuration.

Component configuration variables must also be serialized for saving on shutdown and removal of the component as well.

In the current SDK design, the player literally has no idea what components a particular service belongs to. And it completely randomizes the order of that global service table on every startup, to provoke possible race conditions from components that expect a deterministic load order to work.

Re: fb2k API questions

Reply #46
@kode54 , thanks for the answer!
I've found that it's possible to at least display such "external" components in Preferences components tab (like this >url<). Do you think that the version update check will work if I add those components to the fb2k component repo? I.e. without automatic download/update/removal, just the version check so that users can be notified when new version appears.

Since I'd rather avoid reimplementing fb2k component manager as much as possible :D

Re: fb2k API questions

Reply #47
The app does report newer component releases from the repository, but I don't know if it can simply open a web page with updates for newer versions if only a link is supplied, or if it requires an explicit package to be uploaded to the site.


Re: fb2k API questions

Reply #49
@Peter, a small API question: is >http client interface< thread-safe? I.e. can it be called from different threads without additional synchronization?