diff --git a/src/cli.cc b/src/cli.cc index a5601a4..595066b 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -402,7 +402,7 @@ static void output_cover(const ot::opus_tags& tags, const ot::options &opt) { std::optional cover = extract_cover(tags); if (!cover) { - fputs("warning: no cover found.\n", stderr); + fputs("warning: No cover found.\n", stderr); return; } diff --git a/src/opus.cc b/src/opus.cc index 36b4772..df36bad 100644 --- a/src/opus.cc +++ b/src/opus.cc @@ -149,6 +149,9 @@ ot::picture::picture(std::string block) picture_data = std::string_view(reinterpret_cast(bytes + pic_offset + 4), pic_size); } +/** + * \todo Take into account the picture types (first 4 bytes of the tag value). + */ std::optional ot::extract_cover(const ot::opus_tags& tags) { static const std::string_view prefix = "METADATA_BLOCK_PICTURE="sv; @@ -157,6 +160,11 @@ std::optional ot::extract_cover(const ot::opus_tags& tags) if (cover_tag == tags.comments.end()) return {}; // No cover art. + auto extra_cover_tag = std::find_if(std::next(cover_tag), tags.comments.end(), is_cover); + if (extra_cover_tag != tags.comments.end()) + fputs("warning: Found multiple covers; only the first will be extracted." + " Please report your use case if you need a finer selection.\n", stderr); + std::string_view cover_value = *cover_tag; cover_value.remove_prefix(prefix.size()); return picture(decode_base64(cover_value)); diff --git a/t/opus.cc b/t/opus.cc index cb83bea..fdeed6b 100644 --- a/t/opus.cc +++ b/t/opus.cc @@ -148,7 +148,7 @@ static void extract_cover() "\x00\x00\x00\x0C" "Picture data"; ot::opus_tags tags; - tags.comments.push_front("METADATA_BLOCK_PICTURE=" + ot::encode_base64(picture_data)); + tags.comments = { "METADATA_BLOCK_PICTURE=" + ot::encode_base64(picture_data) }; std::optional cover = ot::extract_cover(tags); if (!cover) throw failure("could not extract the cover"); @@ -158,7 +158,7 @@ static void extract_cover() throw failure("bad extracted picture data"); std::string_view truncated_data = picture_data.substr(0, picture_data.size() - 1); - tags.comments.push_front("METADATA_BLOCK_PICTURE=" + ot::encode_base64(truncated_data)); + tags.comments = { "METADATA_BLOCK_PICTURE=" + ot::encode_base64(truncated_data) }; try { ot::extract_cover(tags); throw failure("accepted a bad picture block");