Volumio API with youtube2 plugin

I was just playing around with the volumio API requests for another project and thought of a way to request songs via title over the API and then being able to select one of a few. which would be played.
How would I go about asking the youtube2 plugin via API for 10 songs and then add them to the queue? I already did figured out volume, getQueue, repeat etc. but can’t seem to find a solution for that.
I appreciate any help!

Volumio Information

Volumio Version: v2.909
Hardware: Raspberry Pi 3b+
DAC: I just use the headphone jack

this is something you would probably get more answers from in the “volumio-development/development-talks” sections, I’ll try to move it

oh thank you :smiley:

I found one command: volumio.local/api/v1/search?query=MusicTitle
but cant seem to filter for service etc. so I only get that one service

I don’t think you can search within a particular service with the REST API, although IMO it should have allowed this (it’s trivial to implement).

The Websocket API on the other hand allows you to do this by specifying the service type in the search message, but the problem with this is the API will return the search results in a pushBrowseLibrary response, and you would have no way in knowing whether this is a response to your search request or just some ordinary browse action. Other clients also won’t know that this response is specific to your request and could update their UI to show the search results (which is probably not what you want).

For the youtube2 plugin, I can add a REST endpoint such as youtube2.search , then you can call this through the REST API’s pluginEndpoint. This shouldn’t be difficult to implement, but I still feel that Volumio’s REST API itself should provide the ability to search within a particular service, instead of requiring a plugin to add a separate endpoint for the purpose…

I would be really grateful if you would add that feature!

Ok, will do. But you would have to wait till the end of the week ~

@patrickkfkan if you add that … alter the size of the image too please :wink: patrick

It’s been a while since I’ve touched this plugin, but looking at the code again it’s actually not necessary to add a REST endpoint. You can obtain search results within youtube2 through the browse endpoint.

First, you need a Search URI which is formatted as follows:

| Search    | URI format                             |
| ----------| -------------------------------------- |
| Videos    | youtube2/videos@search={MusicTitle}    |
| Channels  | youtube2/channels@search={MusicTitle}  |
| Playlists | youtube2/playlists@search={MusicTitle} |
  • MusicTitle must be URI-encoded. E.g. Taylor Swift becomes Taylor%20Swift.

    In Javascript, you can call encodeURIComponent('Taylor Swift')

  • Search results are limited to the number you specify under “Items Per Page” in the plugin settings.

  • In the plugin settings, there is also an “Item Count in Combined Search Results” field. To limit search results to this number, append @combinedSearch=1 to the URI (e.g. youtube2/videos@search={MusicTitle}@combinedSearch=1)

Once you have the Search URI, you can pass it to the REST browse endpoint which has the following form:

http://volumio.local/api/v1/browse?uri={encodedURI}

  • encodedURI is the URI-encoded value of the Search URI you want to pass to the endpoint (use encodeURIComponent() in Javascript).

Example

You want to search ‘Taylor Swift’ videos:

  1. Search URI: youtube2/videos@search=Taylor%20Swift
  2. Encode URI to pass to browse endpoint, so the Search URI becomes youtube2%2Fvideos%40search%3DTaylor%2520Swift
  3. Call the browse endpoint:
    http://volumio.local/api/v1/browse?uri=youtube2%2Fvideos%40search%3DTaylor%2520Swift

The response will contain the list of matching videos as well as navigational elements like list title that Volumio uses to display the results. You can copy-and-paste the response into an online JSON formatter for easy viewing and determine the properties that you need. Take special note of the last element in the list of found items, as it could be of type youtubeNextPageItem. This item is a link to the next set of results.

love you lol