From 0759a82ae40706269aa3c88e9a175bf8ce7a2f54 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Wed, 11 Jan 2023 09:19:44 +0100 Subject: [PATCH] feat: use "audio/ogg; codecs=opus" as the MIME type for OPUS audio Fix #1473 --- src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java | 2 +- src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java | 8 ++++++++ .../resources-cmt-audio-opus-valid/EPUB/content_001.xhtml | 4 +++- .../files/resources-cmt-audio-opus-valid/EPUB/package.opf | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java index 9fc249562..0338efa64 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java @@ -565,7 +565,7 @@ public static boolean isAudioType(String type) public static boolean isBlessedAudioType(String type) { - return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.equals("audio/opus"); + return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.matches("audio/ogg\\s*;\\s*codecs=opus"); } public static boolean isVideoType(String type) diff --git a/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java b/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java index 290a042ae..7e481440c 100644 --- a/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java +++ b/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java @@ -644,6 +644,14 @@ protected String checkMimetypeMatches(URL resource, String mimetype) // remove any params from the given MIME type string mimetype = MIMEType.removeParams(mimetype); + // hack: remove the codecs parameter in the resource type for OPUS audio + // so that the equality check works + // TODO remove this when we implement proper MIME type parsing + if (resourceMimetype != null && resourceMimetype.matches("audio/ogg\\s*;\\s*codecs=opus")) + { + resourceMimetype = "audio/ogg"; + } + // report any MIME type mismatch as a warning if (resourceMimetype != null && !resourceMimetype.equals(mimetype)) { diff --git a/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml b/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml index b25c450ea..a48e30a94 100644 --- a/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml +++ b/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml @@ -7,6 +7,8 @@

Loomings

Call me Ishmael.

-