summaryrefslogtreecommitdiff
path: root/lib/rbcodec/metadata/asf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/metadata/asf.c')
-rw-r--r--lib/rbcodec/metadata/asf.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/lib/rbcodec/metadata/asf.c b/lib/rbcodec/metadata/asf.c
index d90487b36b..82873a43a6 100644
--- a/lib/rbcodec/metadata/asf.c
+++ b/lib/rbcodec/metadata/asf.c
@@ -437,6 +437,18 @@ static int asf_parse_header(int fd, struct mp3entry* id3,
437 read_uint16le(fd, &count); 437 read_uint16le(fd, &count);
438 bytesleft -= 2; 438 bytesleft -= 2;
439 //DEBUGF("extended metadata count = %u\n",count); 439 //DEBUGF("extended metadata count = %u\n",count);
440 enum
441 {
442 eWM_TrackNumber, eWM_Genre, eWM_AlbumTitle,
443 eWM_AlbumArtist, eWM_Composer, eWM_Year,
444 eWM_MusicBrainz_Track_Id, eWM_Picture
445 };
446
447 static const char *tagops[] =
448 { "WM/TrackNumber", "WM/Genre", "WM/AlbumTitle",
449 "WM/AlbumArtist", "WM/Composer", "WM/Year",
450 "MusicBrainz/Track Id", "WM/Picture", NULL
451 };
440 452
441 for (i=0; i < count; i++) { 453 for (i=0; i < count; i++) {
442 uint16_t length, type; 454 uint16_t length, type;
@@ -450,7 +462,9 @@ static int asf_parse_header(int fd, struct mp3entry* id3,
450 read_uint16le(fd, &type); 462 read_uint16le(fd, &type);
451 read_uint16le(fd, &length); 463 read_uint16le(fd, &length);
452 464
453 if (!strcmp("WM/TrackNumber",utf8buf)) { 465 int itag = string_option(utf8buf, tagops, false);
466
467 if (itag == eWM_TrackNumber) {
454 if (type == 0) { 468 if (type == 0) {
455 id3->track_string = id3buf; 469 id3->track_string = id3buf;
456 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 470 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
@@ -460,19 +474,19 @@ static int asf_parse_header(int fd, struct mp3entry* id3,
460 } else { 474 } else {
461 lseek(fd, length, SEEK_CUR); 475 lseek(fd, length, SEEK_CUR);
462 } 476 }
463 } else if ((!strcmp("WM/Genre", utf8buf)) && (type == 0)) { 477 } else if ((itag == eWM_Genre) && (type == 0)) {
464 id3->genre_string = id3buf; 478 id3->genre_string = id3buf;
465 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 479 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
466 } else if ((!strcmp("WM/AlbumTitle", utf8buf)) && (type == 0)) { 480 } else if ((itag == eWM_AlbumTitle) && (type == 0)) {
467 id3->album = id3buf; 481 id3->album = id3buf;
468 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 482 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
469 } else if ((!strcmp("WM/AlbumArtist", utf8buf)) && (type == 0)) { 483 } else if ((itag == eWM_AlbumArtist) && (type == 0)) {
470 id3->albumartist = id3buf; 484 id3->albumartist = id3buf;
471 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 485 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
472 } else if ((!strcmp("WM/Composer", utf8buf)) && (type == 0)) { 486 } else if ((itag == eWM_Composer) && (type == 0)) {
473 id3->composer = id3buf; 487 id3->composer = id3buf;
474 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 488 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
475 } else if (!strcmp("WM/Year", utf8buf)) { 489 } else if (itag == eWM_Year) {
476 if (type == 0) { 490 if (type == 0) {
477 id3->year_string = id3buf; 491 id3->year_string = id3buf;
478 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 492 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
@@ -482,15 +496,11 @@ static int asf_parse_header(int fd, struct mp3entry* id3,
482 } else { 496 } else {
483 lseek(fd, length, SEEK_CUR); 497 lseek(fd, length, SEEK_CUR);
484 } 498 }
485 } else if (!strncmp("replaygain_", utf8buf, 11)) { 499 } else if (itag == eWM_MusicBrainz_Track_Id) {
486 char *value = id3buf;
487 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
488 parse_replaygain(utf8buf, value, id3);
489 } else if (!strcmp("MusicBrainz/Track Id", utf8buf)) {
490 id3->mb_track_id = id3buf; 500 id3->mb_track_id = id3buf;
491 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); 501 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
492#ifdef HAVE_ALBUMART 502#ifdef HAVE_ALBUMART
493 } else if (!strcmp("WM/Picture", utf8buf)) { 503 } else if (itag == eWM_Picture) {
494 uint32_t datalength = 0; 504 uint32_t datalength = 0;
495 uint32_t strlength; 505 uint32_t strlength;
496 /* Expected is either "01 00 xx xx 03 yy yy yy yy" or 506 /* Expected is either "01 00 xx xx 03 yy yy yy yy" or
@@ -521,13 +531,23 @@ static int asf_parse_header(int fd, struct mp3entry* id3,
521 asf_utf16LEdecode(fd, 32, &utf8, &utf8length); 531 asf_utf16LEdecode(fd, 32, &utf8, &utf8length);
522 strlength = (strlen(utf8buf) + 2) * 2; 532 strlength = (strlen(utf8buf) + 2) * 2;
523 lseek(fd, strlength-32, SEEK_CUR); 533 lseek(fd, strlength-32, SEEK_CUR);
524 if (!strcmp("image/jpeg", utf8buf)) { 534
535 static const char *aa_options[] = {"image/jpeg",
536 "image/jpg","image/png", NULL};
537 int aa_op = string_option(utf8buf, aa_options, false);
538
539 if (aa_op == 0) /*image/jpeg*/
540 {
525 id3->albumart.type = AA_TYPE_JPG; 541 id3->albumart.type = AA_TYPE_JPG;
526 } else if (!strcmp("image/jpg", utf8buf)) { 542 }
543 else if (aa_op == 1) /*image/jpg*/
544 {
527 /* image/jpg is technically invalid, 545 /* image/jpg is technically invalid,
528 * but it does occur in the wild */ 546 * but it does occur in the wild */
529 id3->albumart.type = AA_TYPE_JPG; 547 id3->albumart.type = AA_TYPE_JPG;
530 } else if (!strcmp("image/png", utf8buf)) { 548 }
549 else if (aa_op == 2) /*image/png*/
550 {
531 id3->albumart.type = AA_TYPE_PNG; 551 id3->albumart.type = AA_TYPE_PNG;
532 } else { 552 } else {
533 id3->albumart.type = AA_TYPE_UNKNOWN; 553 id3->albumart.type = AA_TYPE_UNKNOWN;
@@ -543,6 +563,10 @@ static int asf_parse_header(int fd, struct mp3entry* id3,
543 563
544 lseek(fd, datalength, SEEK_CUR); 564 lseek(fd, datalength, SEEK_CUR);
545#endif 565#endif
566 } else if (!strncmp("replaygain_", utf8buf, 11)) {
567 char *value = id3buf;
568 asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining);
569 parse_replaygain(utf8buf, value, id3);
546 } else { 570 } else {
547 lseek(fd, length, SEEK_CUR); 571 lseek(fd, length, SEEK_CUR);
548 } 572 }