Search code examples
sortinghttprequestvlc

Sorting VLC playlist using HTTP request based on their API


When i tried to sort the VLC media from browser based on their API it just returns me an invalid search key error.

This is their API.

VLC API

The http request i used to sort the playlist is :

HTTP request

After i send the request VLC returns me this error: enter image description here

This help would be a life saving


Solution

  • Introduction

    Let's consider VLC media player 3.0.13-8-g41878ff4f2 as the current version.

    HTTP interface: Sort playlist items

    Analysis

    It seems that, currently, the following documentation sources are outdated:

    It seems that the «Invalid search key» error is detected by the following piece of source code: vlc/playlist.c at f32f289264fd4a08c8b5f04d8395ea78f358f291 · videolan/vlc:

        /* allow setting the different sort keys */
        int i_mode = vlc_sort_key_from_string( luaL_checkstring( L, 1 ) );
        if( i_mode == -1 )
            return luaL_error( L, "Invalid search key." );
    

    Please, note that the vlc_sort_key_from_string() function validates the provided val parameter value.

    Solution

    The valid val parameter values may be found in the vlc_sort_key_from_string() function: vlc/playlist.c at f32f289264fd4a08c8b5f04d8395ea78f358f291 · videolan/vlc:

        static const struct
        {
            const char *psz_name;
            int i_key;
        } pp_keys[] =
            { { "id", SORT_ID },
              { "title", SORT_TITLE },
              { "title nodes first", SORT_TITLE_NODES_FIRST },
              { "artist", SORT_ARTIST },
              { "genre", SORT_GENRE },
              { "random", SORT_RANDOM },
              { "duration", SORT_DURATION },
              { "title numeric", SORT_TITLE_NUMERIC },
              { "album", SORT_ALBUM },
              { NULL, -1 } };
    

    I have run a quick check: performed an HTTP GET request to sort items in a random order:

    GET /requests/status.xml?command=pl_sort&id=0&val=random
    

    It has worked correctly: the order of the playlist items has been changed appropriately.

    Autosave playlist upon application exit: Absent feature

    This feature has been requested many times, but it has not been implemented yet:

    Please, note that it does not matter which type of user interface is used (for example, graphical user interface or HTTP interface).

    Workaround?

    It might be a case that a workaround for your particular use case may be implemented.

    For example, it seems to be possible to perform the following operations by using the HTTP interface:

    1. To get the playlist and its items (GET /requests/playlist.xml).
    2. To clear the playlist (GET /requests/status.xml?command=pl_empty).
    3. To enqueue an item into the playlist (GET /requests/status.xml?command=in_enqueue&input=<mrl>).

    Therefore, it looks like:

    • The operation #1 may be used to implement the playlist items export functionality.
    • The operations #2 and #2 may be used to implement the playlist items import functionality.

    Please, consider asking a separate question with the detailed use case description.