[mpd] Try to read metadata and add to queue if path is not in the
library
This commit is contained in:
parent
e6f49b721f
commit
8381b7489e
41
src/mpd.c
41
src/mpd.c
|
@ -1504,6 +1504,13 @@ mpd_command_stop(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add media file item with given virtual path to the queue
|
||||
*
|
||||
* @param path The virtual path
|
||||
* @param recursive If 0 add only item with exact match, otherwise add all items virtual path start with the given path
|
||||
* @return The queue item id of the last inserted item or -1 on failure
|
||||
*/
|
||||
static int
|
||||
mpd_queue_add(char *path, int recursive)
|
||||
{
|
||||
|
@ -1546,6 +1553,7 @@ mpd_queue_add(char *path, int recursive)
|
|||
static int
|
||||
mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
{
|
||||
struct media_file_info mfi;
|
||||
int ret;
|
||||
|
||||
if (argc < 2)
|
||||
|
@ -1566,6 +1574,22 @@ mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||
return ACK_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
// Given path is not in the library, check if it is possible to add as a non-library queue item
|
||||
ret = library_scan_media(argv[1], &mfi);
|
||||
if (ret != METADATA_OK)
|
||||
{
|
||||
ret = asprintf(errmsg, "Failed to add song '%s' to playlist (unkown path)", argv[1]);
|
||||
if (ret < 0)
|
||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||
return ACK_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
library_add_queue_item(&mfi);
|
||||
free_mfi(&mfi, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1578,6 +1602,7 @@ mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||
static int
|
||||
mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
{
|
||||
struct media_file_info mfi;
|
||||
int ret;
|
||||
|
||||
if (argc < 2)
|
||||
|
@ -1596,6 +1621,22 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||
|
||||
ret = mpd_queue_add(argv[1], 0);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
// Given path is not in the library, directly add it as a new queue item
|
||||
ret = library_scan_media(argv[1], &mfi);
|
||||
if (ret != METADATA_OK)
|
||||
{
|
||||
ret = asprintf(errmsg, "Failed to add song '%s' to playlist (unkown path)", argv[1]);
|
||||
if (ret < 0)
|
||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||
return ACK_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
ret = library_add_queue_item(&mfi);
|
||||
free_mfi(&mfi, 1);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = asprintf(errmsg, "Failed to add song '%s' to playlist", argv[1]);
|
||||
|
|
Loading…
Reference in New Issue