Merge pull request #2226 from zutroy97/queue-next-track-id

Add MQTT queue_next command and fix track_id byte order.
This commit is contained in:
Mike Brady
2026-07-06 12:47:02 +02:00
committed by GitHub
+28 -4
View File
@@ -1,3 +1,4 @@
#include <ctype.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@@ -70,7 +71,8 @@ void on_message(__attribute__((unused)) struct mosquitto *mosq,
char *commands[] = {"command", "beginff", "beginrew", "mutetoggle",
"nextitem", "previtem", "pause", "playpause",
"play", "stop", "playresume", "shuffle_songs",
"volumedown", "volumeup", "disconnect", NULL};
"volumedown", "volumeup", "disconnect", "queue_next",
NULL};
int it = 0;
@@ -82,6 +84,25 @@ void on_message(__attribute__((unused)) struct mosquitto *mosq,
if (strcmp(commands[it], "disconnect") == 0) {
debug(2, "[MQTT]: Disconnect Command: %s\n", commands[it]);
stop_play(); // stop any current session and don't replace it
} else if (strcmp(commands[it], "queue_next") == 0) {
// payload is "queue_next <track_id>", where <track_id> is the hex track_id
// string as published by shairport-sync itself (see the "mper"/"track_id" handling
// above), e.g. "queue_next 1A2B3C4D5E6F7"
char *track_id = payload + strlen(commands[it]);
while (*track_id == ' ' || *track_id == '\t')
track_id++;
size_t track_id_len = strlen(track_id);
while (track_id_len > 0 && isspace((unsigned char)track_id[track_id_len - 1]))
track_id[--track_id_len] = '\0';
if (track_id_len == 0) {
warn("[MQTT]: queue_next command received with no track_id -- ignoring.");
} else {
char dacp_command[256];
snprintf(dacp_command, sizeof(dacp_command),
"cue?command=add&query='dmap.persistentid:0x%s'&mode=3", track_id);
debug(2, "[MQTT]: Queue Next Command: %s\n", dacp_command);
send_simple_dacp_command(dacp_command);
}
} else {
debug(2, "[MQTT]: DACP Command: %s\n", commands[it]);
#ifdef CONFIG_DACP_CLIENT
@@ -301,7 +322,6 @@ void mqtt_process_metadata(uint32_t type, uint32_t code, char *data, uint32_t le
if (config.mqtt_publish_parsed) {
if (type == 'core') {
int32_t r;
uint64_t trackid;
char trackidstring[32];
switch (code) {
@@ -321,8 +341,12 @@ void mqtt_process_metadata(uint32_t type, uint32_t code, char *data, uint32_t le
mqtt_publish("title", data, length);
break;
case 'mper':
trackid = *(uint64_t *)(data);
r = snprintf(trackidstring, sizeof(trackidstring), "%" PRIX64 "", trackid);
// publish the raw persistent-id bytes as hex, in the order received --
// no byte-order or integer conversion, so this can't reverse the value.
r = 0;
for (uint32_t i = 0; i < length && r < (int32_t)sizeof(trackidstring) - 2; i++)
r += snprintf(trackidstring + r, sizeof(trackidstring) - (size_t)r, "%02X",
(unsigned char)data[i]);
mqtt_publish("track_id", trackidstring, r);
}
} else if (type == 'ssnc') {