[artwork] Add handler for playlist local artwork (for http items)

- ref https://www.raspberrypi.org/forums/viewtopic.php?p=1090166#p1090166
This commit is contained in:
ejurgensen 2017-01-04 23:20:59 +01:00
parent b7c4256df4
commit 27946a472b
3 changed files with 107 additions and 15 deletions

View File

@ -145,6 +145,7 @@ static int source_item_embedded_get(struct artwork_ctx *ctx);
static int source_item_own_get(struct artwork_ctx *ctx);
static int source_item_stream_get(struct artwork_ctx *ctx);
static int source_item_spotify_get(struct artwork_ctx *ctx);
static int source_item_ownpl_get(struct artwork_ctx *ctx);
/* List of sources that can provide artwork for a group (i.e. usually an album
* identified by a persistentid). The source handlers will be called in the
@ -206,6 +207,12 @@ static struct artwork_source artwork_item_source[] =
.data_kinds = (1 << DATA_KIND_SPOTIFY),
.cache = ON_SUCCESS,
},
{
.name = "playlist own",
.handler = source_item_ownpl_get,
.data_kinds = (1 << DATA_KIND_HTTP),
.cache = ON_SUCCESS | ON_FAILURE,
},
{
.name = NULL,
.handler = NULL,
@ -1285,6 +1292,60 @@ source_item_spotify_get(struct artwork_ctx *ctx)
}
#endif
/* First looks of the mfi->path is in any playlist, and if so looks in the dir
* of the playlist file (m3u et al) to see if there is any artwork. So if the
* playlist is /foo/bar.m3u it will look for /foo/bar.png and /foo/bar.jpg.
*/
static int
source_item_ownpl_get(struct artwork_ctx *ctx)
{
struct query_params qp;
struct db_playlist_info dbpli;
char filter[PATH_MAX + 64];
char *mfi_path;
int format;
int ret;
ret = snprintf(filter, sizeof(filter), "(filepath = '%s')", ctx->dbmfi->path);
if ((ret < 0) || (ret >= sizeof(filter)))
{
DPRINTF(E_LOG, L_ART, "Artwork path exceeds PATH_MAX (%s)\n", ctx->dbmfi->path);
return ART_E_ERROR;
}
memset(&qp, 0, sizeof(struct query_params));
qp.type = Q_FIND_PL;
qp.filter = filter;
ret = db_query_start(&qp);
if (ret < 0)
{
DPRINTF(E_LOG, L_ART, "Could not start ownpl query\n");
return ART_E_ERROR;
}
mfi_path = ctx->dbmfi->path;
format = ART_E_NONE;
while (((ret = db_query_fetch_pl(&qp, &dbpli, 1)) == 0) && (dbpli.id) && (format == ART_E_NONE))
{
if (!dbpli.path)
continue;
ctx->dbmfi->path = dbpli.path;
format = source_item_own_get(ctx);
}
ctx->dbmfi->path = mfi_path;
if ((ret < 0) || (format < 0))
format = ART_E_ERROR;
db_query_end(&qp);
return format;
}
/* --------------------------- SOURCE PROCESSING --------------------------- */

View File

@ -1045,6 +1045,32 @@ db_build_query_pls(struct query_params *qp)
return db_build_query_check(qp, count, query);
}
static char *
db_build_query_find_pls(struct query_params *qp)
{
struct query_clause *qc;
char *count;
char *query;
if (!qp->filter)
{
DPRINTF(E_LOG, L_DB, "Bug! Playlist find called without search criteria\n");
return NULL;
}
qc = db_build_query_clause(qp);
if (!qc)
return NULL;
// Use qp->filter because qc->where has a f.disabled which is not a column in playlistitems
count = sqlite3_mprintf("SELECT COUNT(*) FROM playlists f WHERE f.id IN (SELECT playlistid FROM playlistitems WHERE %s);", qp->filter);
query = sqlite3_mprintf("SELECT f.* FROM playlists f WHERE f.id IN (SELECT playlistid FROM playlistitems WHERE %s) %s %s;", qp->filter, qc->order, qc->index);
db_free_query_clause(qc);
return db_build_query_check(qp, count, query);
}
static char *
db_build_query_plitems_plain(struct query_params *qp)
{
@ -1296,6 +1322,10 @@ db_query_start(struct query_params *qp)
query = db_build_query_pls(qp);
break;
case Q_FIND_PL:
query = db_build_query_find_pls(qp);
break;
case Q_PLITEMS:
query = db_build_query_plitems(qp);
break;

View File

@ -37,21 +37,22 @@ enum sort_type {
enum query_type {
Q_ITEMS = 1,
Q_PL = 2,
Q_PLITEMS = 3,
Q_BROWSE_ARTISTS = Q_F_BROWSE | 4,
Q_BROWSE_ALBUMS = Q_F_BROWSE | 5,
Q_BROWSE_GENRES = Q_F_BROWSE | 6,
Q_BROWSE_COMPOSERS = Q_F_BROWSE | 7,
Q_GROUP_ALBUMS = 8,
Q_GROUP_ARTISTS = 9,
Q_GROUP_ITEMS = 10,
Q_GROUP_DIRS = Q_F_BROWSE | 11,
Q_BROWSE_YEARS = Q_F_BROWSE | 12,
Q_COUNT_ITEMS = 13,
Q_BROWSE_DISCS = Q_F_BROWSE | 14,
Q_BROWSE_TRACKS = Q_F_BROWSE | 15,
Q_BROWSE_VPATH = Q_F_BROWSE | 16,
Q_BROWSE_PATH = Q_F_BROWSE | 17,
Q_FIND_PL = 3,
Q_PLITEMS = 4,
Q_GROUP_ALBUMS = 5,
Q_GROUP_ARTISTS = 6,
Q_GROUP_ITEMS = 7,
Q_COUNT_ITEMS = 8,
Q_BROWSE_ARTISTS = Q_F_BROWSE | 1,
Q_BROWSE_ALBUMS = Q_F_BROWSE | 2,
Q_BROWSE_GENRES = Q_F_BROWSE | 3,
Q_BROWSE_COMPOSERS = Q_F_BROWSE | 4,
Q_GROUP_DIRS = Q_F_BROWSE | 5,
Q_BROWSE_YEARS = Q_F_BROWSE | 6,
Q_BROWSE_DISCS = Q_F_BROWSE | 7,
Q_BROWSE_TRACKS = Q_F_BROWSE | 8,
Q_BROWSE_VPATH = Q_F_BROWSE | 9,
Q_BROWSE_PATH = Q_F_BROWSE | 10,
};
#define ARTWORK_UNKNOWN 0