mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-29 00:23:23 -05:00
Merge pull request #161 from chme/mpdplchanges
Support for mpd command plchanges
This commit is contained in:
commit
70fea7e459
5
src/db.c
5
src/db.c
@ -287,6 +287,7 @@ static const char *sort_clause[] =
|
|||||||
"ORDER BY f.composer_sort ASC",
|
"ORDER BY f.composer_sort ASC",
|
||||||
"ORDER BY f.disc ASC",
|
"ORDER BY f.disc ASC",
|
||||||
"ORDER BY f.track ASC",
|
"ORDER BY f.track ASC",
|
||||||
|
"ORDER BY f.virtual_path ASC",
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *db_path;
|
static char *db_path;
|
||||||
@ -1529,6 +1530,10 @@ db_query_start(struct query_params *qp)
|
|||||||
ret = db_build_query_browse(qp, "track", "track", &query);
|
ret = db_build_query_browse(qp, "track", "track", &query);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Q_BROWSE_VPATH:
|
||||||
|
ret = db_build_query_browse(qp, "virtual_path", "virtual_path", &query);
|
||||||
|
break;
|
||||||
|
|
||||||
case Q_COUNT_ITEMS:
|
case Q_COUNT_ITEMS:
|
||||||
ret = db_build_query_count_items(qp, &query);
|
ret = db_build_query_count_items(qp, &query);
|
||||||
break;
|
break;
|
||||||
|
32
src/db.h
32
src/db.h
@ -27,26 +27,28 @@ enum sort_type {
|
|||||||
S_COMPOSER,
|
S_COMPOSER,
|
||||||
S_DISC,
|
S_DISC,
|
||||||
S_TRACK,
|
S_TRACK,
|
||||||
|
S_VPATH,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define Q_F_BROWSE (1 << 15)
|
#define Q_F_BROWSE (1 << 15)
|
||||||
|
|
||||||
enum query_type {
|
enum query_type {
|
||||||
Q_ITEMS = (1 << 0),
|
Q_ITEMS = 1,
|
||||||
Q_PL = (1 << 1),
|
Q_PL = 2,
|
||||||
Q_PLITEMS = (1 << 2),
|
Q_PLITEMS = 3,
|
||||||
Q_BROWSE_ARTISTS = Q_F_BROWSE | (1 << 3),
|
Q_BROWSE_ARTISTS = Q_F_BROWSE | 4,
|
||||||
Q_BROWSE_ALBUMS = Q_F_BROWSE | (1 << 4),
|
Q_BROWSE_ALBUMS = Q_F_BROWSE | 5,
|
||||||
Q_BROWSE_GENRES = Q_F_BROWSE | (1 << 5),
|
Q_BROWSE_GENRES = Q_F_BROWSE | 6,
|
||||||
Q_BROWSE_COMPOSERS = Q_F_BROWSE | (1 << 6),
|
Q_BROWSE_COMPOSERS = Q_F_BROWSE | 7,
|
||||||
Q_GROUP_ALBUMS = (1 << 7),
|
Q_GROUP_ALBUMS = 8,
|
||||||
Q_GROUP_ARTISTS = (1 << 8),
|
Q_GROUP_ARTISTS = 9,
|
||||||
Q_GROUP_ITEMS = (1 << 9),
|
Q_GROUP_ITEMS = 10,
|
||||||
Q_GROUP_DIRS = Q_F_BROWSE | (1 << 10),
|
Q_GROUP_DIRS = Q_F_BROWSE | 11,
|
||||||
Q_BROWSE_YEARS = Q_F_BROWSE | (1 << 11),
|
Q_BROWSE_YEARS = Q_F_BROWSE | 12,
|
||||||
Q_COUNT_ITEMS = (1 << 12),
|
Q_COUNT_ITEMS = 13,
|
||||||
Q_BROWSE_DISCS = Q_F_BROWSE | (1 << 13),
|
Q_BROWSE_DISCS = Q_F_BROWSE | 14,
|
||||||
Q_BROWSE_TRACKS = Q_F_BROWSE | (1 << 14),
|
Q_BROWSE_TRACKS = Q_F_BROWSE | 15,
|
||||||
|
Q_BROWSE_VPATH = Q_F_BROWSE | 16,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ARTWORK_UNKNOWN 0
|
#define ARTWORK_UNKNOWN 0
|
||||||
|
77
src/mpd.c
77
src/mpd.c
@ -1797,10 +1797,49 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Command handler function for 'plchanges'
|
||||||
|
* Lists all changed songs in the queue since the given playlist version in argv[1].
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_MPD, "Ignore command %s\n", argv[0]);
|
struct player_queue *queue;
|
||||||
|
int pos_pl;
|
||||||
|
int i;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* forked-daapd does not keep track of changes in the queue based on the playlist version,
|
||||||
|
* therefor plchanges returns all songs in the queue as changed ignoring the given version.
|
||||||
|
*/
|
||||||
|
queue = player_queue_get(0, -1, 0);
|
||||||
|
|
||||||
|
if (!queue)
|
||||||
|
{
|
||||||
|
// Queue is emtpy
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos_pl = queue->start_pos;
|
||||||
|
for (i = 0; i < queue->count; i++)
|
||||||
|
{
|
||||||
|
ret = mpd_add_mediainfo_byid(evbuf, queue->queue[i], pos_pl);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ret = asprintf(errmsg, "Error adding media info for file with id: %d", queue->queue[i]);
|
||||||
|
|
||||||
|
queue_free(queue);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||||
|
return ACK_ERROR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos_pl++;
|
||||||
|
}
|
||||||
|
|
||||||
|
queue_free(queue);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2151,6 +2190,14 @@ mpd_get_query_params_find(int argc, char **argv, struct query_params *qp)
|
|||||||
else
|
else
|
||||||
c1 = sqlite3_mprintf("(f.track = %d)", num);
|
c1 = sqlite3_mprintf("(f.track = %d)", num);
|
||||||
}
|
}
|
||||||
|
else if (0 == strcasecmp(argv[i], "date"))
|
||||||
|
{
|
||||||
|
ret = safe_atou32(argv[i + 1], &num);
|
||||||
|
if (ret < 0)
|
||||||
|
c1 = sqlite3_mprintf("(f.year = 0 OR f.year IS NULL)");
|
||||||
|
else
|
||||||
|
c1 = sqlite3_mprintf("(f.year = %d)", num);
|
||||||
|
}
|
||||||
else if (i == 0 && argc == 1)
|
else if (i == 0 && argc == 1)
|
||||||
{
|
{
|
||||||
// Special case: a single token is allowed if listing albums for an artist
|
// Special case: a single token is allowed if listing albums for an artist
|
||||||
@ -2392,6 +2439,12 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
qp.sort = S_TRACK;
|
qp.sort = S_TRACK;
|
||||||
type = "Track: ";
|
type = "Track: ";
|
||||||
}
|
}
|
||||||
|
else if (0 == strcasecmp(argv[1], "file"))
|
||||||
|
{
|
||||||
|
qp.type = Q_BROWSE_VPATH;
|
||||||
|
qp.sort = S_VPATH;
|
||||||
|
type = "file: ";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_MPD, "Unsupported type argument for command 'list': %s\n", argv[1]);
|
DPRINTF(E_WARN, L_MPD, "Unsupported type argument for command 'list': %s\n", argv[1]);
|
||||||
@ -2417,6 +2470,19 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (qp.type & Q_F_BROWSE)
|
if (qp.type & Q_F_BROWSE)
|
||||||
|
{
|
||||||
|
if (qp.type == Q_BROWSE_VPATH)
|
||||||
|
{
|
||||||
|
while (((ret = db_query_fetch_string_sort(&qp, &browse_item, &sort_item)) == 0) && (browse_item))
|
||||||
|
{
|
||||||
|
// Remove the first "/" from the virtual_path
|
||||||
|
evbuffer_add_printf(evbuf,
|
||||||
|
"%s%s\n",
|
||||||
|
type,
|
||||||
|
(browse_item + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
while (((ret = db_query_fetch_string_sort(&qp, &browse_item, &sort_item)) == 0) && (browse_item))
|
while (((ret = db_query_fetch_string_sort(&qp, &browse_item, &sort_item)) == 0) && (browse_item))
|
||||||
{
|
{
|
||||||
@ -2426,6 +2492,7 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
browse_item);
|
browse_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while ((ret = db_query_fetch_group(&qp, &dbgri)) == 0)
|
while ((ret = db_query_fetch_group(&qp, &dbgri)) == 0)
|
||||||
@ -2624,6 +2691,14 @@ mpd_get_query_params_search(int argc, char **argv, struct query_params *qp)
|
|||||||
else
|
else
|
||||||
c1 = sqlite3_mprintf("(f.track = %d)", num);
|
c1 = sqlite3_mprintf("(f.track = %d)", num);
|
||||||
}
|
}
|
||||||
|
else if (0 == strcasecmp(argv[i], "date"))
|
||||||
|
{
|
||||||
|
ret = safe_atou32(argv[i + 1], &num);
|
||||||
|
if (ret < 0)
|
||||||
|
c1 = sqlite3_mprintf("(f.year = 0 OR f.year IS NULL)");
|
||||||
|
else
|
||||||
|
c1 = sqlite3_mprintf("(f.year = %d)", num);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_MPD, "Parameter '%s' is not supported by forked-daapd and will be ignored\n", argv[i]);
|
DPRINTF(E_WARN, L_MPD, "Parameter '%s' is not supported by forked-daapd and will be ignored\n", argv[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user