From 33a7b8a2dc3a28b51c1db9a713c1f6c7785e1e00 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve <hugo@hugovil.com> Date: Thu, 5 Jan 2023 16:44:56 -0500 Subject: [PATCH] Add playlists menu --- htdocs/index.html | 1 + htdocs/js/mpd.js | 21 +++++++++++++++++++++ src/mpd_client.c | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/htdocs/index.html b/htdocs/index.html index 57ca034..9ec53b4 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -45,6 +45,7 @@ </div> <div class="collapse navbar-collapse"> <ul id="nav_links" class="nav navbar-nav"> + <li id="playlists"><a href="#/playlists/0/">Playlists</a></li> <li id="queue"><a href="#/">Queue</a></li> <li id="browse"><a href="#/browse/0/">Browse</a></li> <li> diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index 708aaa9..8b571e2 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -62,6 +62,27 @@ var app = $.sammy(function () { runBrowse(); }); + this.get(/\#\/playlists\/(\d+)\/(.*)/, function () { + prepare(); + browsepath = this.params['splat'][1]; + pagination = parseInt(this.params['splat'][0]); + current_app = 'browse'; + $('#breadcrump').addClass('hide'); + $('#salamisandwich').removeClass('hide').find('tr:gt(0)').remove(); + $('#filter').addClass('hide'); + $('#filter').empty(); + socket.send( + 'MPD_API_GET_BROWSE,' + + pagination + + ',' + + (browsepath ? browsepath : '/') + ); + + $('#panel-heading').text('Playlists'); + $('#panel-heading-info').empty(); + $('#playlists').addClass('active'); + }); + this.get(/\#\/browse\/(\d+)\/(.*)/, function () { prepare(); browsepath = this.params['splat'][1]; diff --git a/src/mpd_client.c b/src/mpd_client.c index ac594bc..c3601ee 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -232,12 +232,13 @@ int callback_mpd(struct mg_connection *c) { if (strcmp(strtok(p_charbuf, ","), "MPD_API_ADD_PLAYLIST")) goto out_playlist; + uint_buf = strtoul(strtok(NULL, ","), NULL, 10); if ((token = strtok(NULL, ",")) == NULL) goto out_playlist; free(p_charbuf); p_charbuf = strdup(c->content); - mpd_run_load(mpd.conn, get_arg1(p_charbuf)); + n = mpd_put_playlist(mpd.buf, get_arg2(p_charbuf), uint_buf); out_playlist: free(p_charbuf); break; -- 2.20.1