[Ogg Vorbis/Opus] Fix picture metadata handling

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
xcode15
Christopher Snowhill 2022-07-13 00:11:51 -07:00
parent 5238965534
commit 8c4f9a7123
2 changed files with 11 additions and 10 deletions

View File

@ -152,25 +152,26 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
char *name, *value;
if(FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry, &name, &value)) {
NSString *tagName = guess_encoding_of_string(name);
NSString *tagValue = guess_encoding_of_string(value);
free(name);
free(value);
tagName = [tagName lowercaseString];
if([tagName isEqualToString:@"metadata_block_picture"]) {
OpusPictureTag _pic = { 0 };
if(opus_picture_tag_parse(&_pic, [tagValue UTF8String]) >= 0) {
if(opus_picture_tag_parse(&_pic, value) >= 0) {
if(_pic.format == OP_PIC_FORMAT_PNG ||
_pic.format == OP_PIC_FORMAT_JPEG ||
_pic.format == OP_PIC_FORMAT_GIF) {
_pic.format == OP_PIC_FORMAT_GIF ||
_pic.format == OP_PIC_FORMAT_UNKNOWN) {
_albumArt = [NSData dataWithBytes:_pic.data length:_pic.data_length];
}
opus_picture_tag_clear(&_pic);
}
opus_picture_tag_clear(&_pic);
} else {
setDictionary(_metaDict, tagName, tagValue);
setDictionary(_metaDict, tagName, guess_encoding_of_string(value));
}
free(value);
}
}

View File

@ -132,14 +132,12 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
char *name, *value;
if(FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry, &name, &value)) {
NSString *tagName = guess_encoding_of_string(name);
NSString *tagValue = guess_encoding_of_string(value);
free(name);
free(value);
tagName = [tagName lowercaseString];
if([tagName isEqualToString:@"metadata_block_picture"]) {
flac_picture_t *picture = flac_picture_parse_from_base64([tagValue UTF8String]);
flac_picture_t *picture = flac_picture_parse_from_base64(value);
if(picture) {
if(picture->binary && picture->binary_length) {
_albumArt = [NSData dataWithBytes:picture->binary length:picture->binary_length];
@ -147,8 +145,10 @@ static void setDictionary(NSMutableDictionary *dict, NSString *tag, NSString *va
flac_picture_free(picture);
}
} else {
setDictionary(_metaDict, tagName, tagValue);
setDictionary(_metaDict, tagName, guess_encoding_of_string(value));
}
free(value);
}
}