Artwork support for iTunes 11 (credit @torta) and related improvements

This commit is contained in:
ejurgensen 2013-12-25 23:06:41 +01:00
parent 8fc4b759b7
commit 02a73e3638
4 changed files with 56 additions and 35 deletions

View File

@ -594,7 +594,14 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
need_rescale = 1;
if ((src->width <= max_w) && (src->height <= max_h)) /* Smaller than target */
if ((max_w <= 0) || (max_h <= 0)) /* No valid dimensions, use original */
{
need_rescale = 0;
target_w = src->width;
target_h = src->height;
}
else if ((src->width <= max_w) && (src->height <= max_h)) /* Smaller than target */
{
need_rescale = 0;
@ -614,13 +621,13 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
DPRINTF(E_DBG, L_ART, "Raw destination width %d height %d\n", target_w, target_h);
if (target_h > max_h)
if ((target_h > max_h) && (max_h > 0))
target_h = max_h;
/* PNG prefers even row count */
target_w += target_w % 2;
if (target_w > max_w)
if ((target_w > max_w) && (max_w > 0))
target_w = max_w - (max_w % 2);
DPRINTF(E_DBG, L_ART, "Destination width %d height %d\n", target_w, target_h);

View File

@ -392,11 +392,13 @@ dmap_encode_file_metadata(struct evbuffer *songlist, struct evbuffer *song, stru
int32_t val;
int want_mikd;
int want_asdk;
int want_ased;
int i;
int ret;
want_mikd = 0;
want_asdk = 0;
want_ased = 0;
i = -1;
while (1)
@ -426,6 +428,13 @@ dmap_encode_file_metadata(struct evbuffer *songlist, struct evbuffer *song, stru
dfm = dmap_fields[i].dfm;
}
/* Extradata not in media_file_info but flag for reply */
if (dfm == &dfm_dmap_ased)
{
want_ased = 1;
continue;
}
/* Not in struct media_file_info */
if (dfm->mfi_offset < 0)
continue;
@ -496,6 +505,13 @@ dmap_encode_file_metadata(struct evbuffer *songlist, struct evbuffer *song, stru
DPRINTF(E_SPAM, L_DAAP, "Done with meta tag %s (%s)\n", df->desc, *strval);
}
/* Required for artwork in iTunes, set songartworkcount (asac) = 1 */
if (want_ased)
{
dmap_add_short(song, "ased", 1);
dmap_add_short(song, "asac", 1);
}
if (sort_tags)
{
dmap_add_string(song, "assn", dbmfi->title_sort);

View File

@ -64,6 +64,7 @@ static const struct dmap_field_map dfm_dmap_adbs = { -1,
static const struct dmap_field_map dfm_dmap_asal = { dbmfi_offsetof(album), -1, -1 };
static const struct dmap_field_map dfm_dmap_asai = { dbmfi_offsetof(songalbumid), -1, -1 };
static const struct dmap_field_map dfm_dmap_asaa = { dbmfi_offsetof(album_artist), -1, dbgri_offsetof(songalbumartist) };
static const struct dmap_field_map dfm_dmap_asac = { -1, -1, -1 };
static const struct dmap_field_map dfm_dmap_asar = { dbmfi_offsetof(artist), -1, -1 };
static const struct dmap_field_map dfm_dmap_asri = { dbmfi_offsetof(songartistid), -1, -1 };
static const struct dmap_field_map dfm_dmap_asbt = { dbmfi_offsetof(bpm), -1, -1 };
@ -76,6 +77,7 @@ static const struct dmap_field_map dfm_dmap_asdm = { dbmfi_offsetof(time_modifie
static const struct dmap_field_map dfm_dmap_asdc = { dbmfi_offsetof(total_discs), -1, -1 };
static const struct dmap_field_map dfm_dmap_asdn = { dbmfi_offsetof(disc), -1, -1 };
static const struct dmap_field_map dfm_dmap_asdb = { dbmfi_offsetof(disabled), -1, -1 };
static const struct dmap_field_map dfm_dmap_ased = { -1, -1, -1 };
static const struct dmap_field_map dfm_dmap_aseq = { -1, -1, -1 };
static const struct dmap_field_map dfm_dmap_asfm = { dbmfi_offsetof(type), -1, -1 };
static const struct dmap_field_map dfm_dmap_asgn = { dbmfi_offsetof(genre), -1, -1 };
@ -175,6 +177,7 @@ struct dmap_field;
"daap.resolveinfo", "arif", &dfm_dmap_arif, DMAP_TYPE_LIST
"daap.resolve", "arsv", &dfm_dmap_arsv, DMAP_TYPE_LIST
"daap.songalbumartist", "asaa", &dfm_dmap_asaa, DMAP_TYPE_STRING
"daap.songartworkcount", "asac", &dfm_dmap_asac, DMAP_TYPE_USHORT
"daap.songalbumid", "asai", &dfm_dmap_asai, DMAP_TYPE_ULONG
"daap.songalbum", "asal", &dfm_dmap_asal, DMAP_TYPE_STRING
"daap.songartist", "asar", &dfm_dmap_asar, DMAP_TYPE_STRING
@ -196,6 +199,7 @@ struct dmap_field;
"daap.songdatemodified", "asdm", &dfm_dmap_asdm, DMAP_TYPE_DATE
"daap.songdiscnumber", "asdn", &dfm_dmap_asdn, DMAP_TYPE_USHORT
"daap.songdescription", "asdt", &dfm_dmap_asdt, DMAP_TYPE_STRING
"daap.songextradata", "ased", &dfm_dmap_ased, DMAP_TYPE_USHORT
"daap.songeqpreset", "aseq", &dfm_dmap_aseq, DMAP_TYPE_STRING
"daap.songformat", "asfm", &dfm_dmap_asfm, DMAP_TYPE_STRING
"daap.songgenre", "asgn", &dfm_dmap_asgn, DMAP_TYPE_STRING
@ -293,7 +297,6 @@ struct dmap_field;
"daap.songbookmark", "asbo", &dfm_dmap_asbo, DMAP_TYPE_UINT
"daap.songdatepurchased", "asdp", &dfm_dmap_asdp, DMAP_TYPE_DATE
"daap.songdatereleased", "asdr", &dfm_dmap_asdr, DMAP_TYPE_DATE
"daap.songextradata", "ased", &dfm_dmap_ased, DMAP_TYPE_USHORT
"daap.songgapless", "asgp", &dfm_dmap_asgp, DMAP_TYPE_UBYTE
"daap.songhasbeenplayed", "ashp", &dfm_dmap_ashp, DMAP_TYPE_UBYTE
"daap.songlongsize", "asls", &dfm_dmap_asls, DMAP_TYPE_ULONG

View File

@ -667,7 +667,7 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
passwd = cfg_getstr(lib, "password");
name = cfg_getstr(lib, "name");
len = 157 + strlen(name);
len = 167 + strlen(name);
ret = evbuffer_expand(evbuf, len);
if (ret < 0)
@ -701,6 +701,7 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
dmap_add_int(evbuf, "mpro", mpro); /* 12 */
dmap_add_string(evbuf, "minm", name); /* 8 + strlen(name) */
dmap_add_int(evbuf, "apro", apro); /* 12 */
dmap_add_short(evbuf, "ated", 1); /* 10 daap.supportsextradata */
dmap_add_char(evbuf, "mslr", 1); /* 9 */
dmap_add_int(evbuf, "mstm", DAAP_SESSION_TIMEOUT_CAPABILITY); /* 12 */
@ -1131,7 +1132,7 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
transcode = transcode_needed(req->input_headers, dbmfi.codectype);
ret = dmap_encode_file_metadata(songlist, song, &dbmfi, meta, nmeta, 1, transcode);
ret = dmap_encode_file_metadata(songlist, song, &dbmfi, meta, nmeta, sort_headers, transcode);
if (ret < 0)
{
DPRINTF(E_LOG, L_DAAP, "Failed to encode song metadata\n");
@ -2032,40 +2033,34 @@ daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char *
return;
}
param = evhttp_find_header(query, "mw");
if (!param)
if (evhttp_find_header(query, "mw") && evhttp_find_header(query, "mh"))
{
DPRINTF(E_LOG, L_DAAP, "Request for artwork without mw parameter\n");
param = evhttp_find_header(query, "mw");
ret = safe_atoi32(param, &max_w);
if (ret < 0)
{
DPRINTF(E_LOG, L_DAAP, "Could not convert mw parameter to integer\n");
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
return;
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
return;
}
param = evhttp_find_header(query, "mh");
ret = safe_atoi32(param, &max_h);
if (ret < 0)
{
DPRINTF(E_LOG, L_DAAP, "Could not convert mh parameter to integer\n");
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
return;
}
}
ret = safe_atoi32(param, &max_w);
if (ret < 0)
else
{
DPRINTF(E_LOG, L_DAAP, "Could not convert mw parameter to integer\n");
DPRINTF(E_DBG, L_DAAP, "Request for artwork without mw/mh parameter\n");
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
return;
}
param = evhttp_find_header(query, "mh");
if (!param)
{
DPRINTF(E_LOG, L_DAAP, "Request for artwork without mh parameter\n");
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
return;
}
ret = safe_atoi32(param, &max_h);
if (ret < 0)
{
DPRINTF(E_LOG, L_DAAP, "Could not convert mh parameter to integer\n");
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
return;
max_w = 0;
max_h = 0;
}
if (strcmp(uri[2], "groups") == 0)