Some cleaning up of ICY artwork retrieval

This commit is contained in:
ejurgensen 2015-04-09 22:22:42 +02:00
parent 94f94b03fe
commit e72447954a
5 changed files with 35 additions and 22 deletions

View File

@ -695,6 +695,18 @@ artwork_get(struct evbuffer *evbuf, char *path, int max_w, int max_h)
return ret;
}
/*
* Downloads the artwork pointed to by the ICY metadata tag in an internet radio
* stream (the StreamUrl tag). The path will be converted back to the id, which
* is given to the player. If the id is currently being played, and there is a
* valid ICY metadata artwork URL available, it will be returned to this
* function, which will then use the http client to get the artwork. Notice: No
* rescaling is done.
*
* @param evbuf the event buffer that will contain the (scaled) image
* @param path path to the item we are getting artwork for
* @return ART_FMT_* on success, 0 on error and nothing found
*/
static int
artwork_get_player_image(struct evbuffer *evbuf, char *path)
{
@ -702,6 +714,7 @@ artwork_get_player_image(struct evbuffer *evbuf, char *path)
struct keyval *kv;
const char *content_type;
char *url;
int id;
int len;
int ret;
@ -709,7 +722,11 @@ artwork_get_player_image(struct evbuffer *evbuf, char *path)
ret = 0;
player_icy_artwork_url(&url, path);
id = db_file_id_bypath(path);
if (!id)
return 0;
url = player_get_icy_artwork_url(id);
if (!url)
return 0;

View File

@ -135,7 +135,7 @@ struct item_range
struct icy_artwork
{
char *stream_url;
uint32_t id;
char *artwork_url;
};
@ -175,7 +175,7 @@ struct player_command
int intval;
int ps_pos[2];
struct item_range item_range;
struct icy_artwork icy_artwork;
struct icy_artwork icy;
} arg;
int ret;
@ -2628,15 +2628,13 @@ now_playing(struct player_command *cmd)
static int
artwork_url_get(struct player_command *cmd)
{
DPRINTF(E_DBG, L_PLAYER, "ICY artwork url call\n");
cmd->arg.icy.artwork_url = NULL;
cmd->arg.icy_artwork.artwork_url = NULL;
/* Not playing a stream */
if (!cur_playing || cur_playing->type != SOURCE_HTTP || !cur_playing->ctx)
/* Check that we are playing a viable stream, and that it has the requested id */
if (!cur_streaming || cur_streaming->id != cmd->arg.icy.id || cur_streaming->type != SOURCE_HTTP || !cur_streaming->ctx)
return -1;
transcode_metadata_artwork_url(cur_playing->ctx, &cmd->arg.icy_artwork.artwork_url, cmd->arg.icy_artwork.stream_url);
transcode_metadata_artwork_url(cur_streaming->ctx, &cmd->arg.icy.artwork_url);
return 0;
}
@ -4296,8 +4294,8 @@ player_now_playing(uint32_t *id)
return ret;
}
int
player_icy_artwork_url(char **artwork_url, char *stream_url)
char *
player_get_icy_artwork_url(uint32_t id)
{
struct player_command cmd;
int ret;
@ -4306,18 +4304,19 @@ player_icy_artwork_url(char **artwork_url, char *stream_url)
cmd.func = artwork_url_get;
cmd.func_bh = NULL;
cmd.arg.icy_artwork.stream_url = stream_url;
cmd.arg.icy.id = id;
if (pthread_self() != tid_player)
ret = sync_command(&cmd);
else
ret = artwork_url_get(&cmd);
*artwork_url = cmd.arg.icy_artwork.artwork_url;
command_deinit(&cmd);
return ret;
if (ret < 0)
return NULL;
else
return cmd.arg.icy.artwork_url;
}
/*

View File

@ -133,8 +133,8 @@ player_get_status(struct player_status *status);
int
player_now_playing(uint32_t *id);
int
player_icy_artwork_url(char **artwork_url, char *stream_url);
char *
player_get_icy_artwork_url(uint32_t id);
void
player_speaker_enumerate(spk_enum_cb cb, void *arg);

View File

@ -926,7 +926,7 @@ transcode_metadata(struct transcode_ctx *ctx, struct http_icy_metadata **metadat
}
void
transcode_metadata_artwork_url(struct transcode_ctx *ctx, char **artwork_url, char *stream_url)
transcode_metadata_artwork_url(struct transcode_ctx *ctx, char **artwork_url)
{
struct http_icy_metadata *m;
@ -935,9 +935,6 @@ transcode_metadata_artwork_url(struct transcode_ctx *ctx, char **artwork_url, ch
if (!ctx->fmtctx || !ctx->fmtctx->filename)
return;
if (strcmp(ctx->fmtctx->filename, stream_url) != 0)
return;
m = http_icy_metadata_get(ctx->fmtctx, 1);
if (!m)
return;

View File

@ -30,6 +30,6 @@ void
transcode_metadata(struct transcode_ctx *ctx, struct http_icy_metadata **metadata, int *changed);
void
transcode_metadata_artwork_url(struct transcode_ctx *ctx, char **artwork_url, char *stream_url);
transcode_metadata_artwork_url(struct transcode_ctx *ctx, char **artwork_url);
#endif /* !__TRANSCODE_H__ */