Skip to content

Commit 0759a82

Browse files
committed
feat: use "audio/ogg; codecs=opus" as the MIME type for OPUS audio
Fix #1473
1 parent 873d4f5 commit 0759a82

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public static boolean isAudioType(String type)
565565

566566
public static boolean isBlessedAudioType(String type)
567567
{
568-
return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.equals("audio/opus");
568+
return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.matches("audio/ogg\\s*;\\s*codecs=opus");
569569
}
570570

571571
public static boolean isVideoType(String type)

src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,14 @@ protected String checkMimetypeMatches(URL resource, String mimetype)
644644
// remove any params from the given MIME type string
645645
mimetype = MIMEType.removeParams(mimetype);
646646

647+
// hack: remove the codecs parameter in the resource type for OPUS audio
648+
// so that the equality check works
649+
// TODO remove this when we implement proper MIME type parsing
650+
if (resourceMimetype != null && resourceMimetype.matches("audio/ogg\\s*;\\s*codecs=opus"))
651+
{
652+
resourceMimetype = "audio/ogg";
653+
}
654+
647655
// report any MIME type mismatch as a warning
648656
if (resourceMimetype != null && !resourceMimetype.equals(mimetype))
649657
{

src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<body>
88
<h1>Loomings</h1>
99
<p>Call me Ishmael.</p>
10-
<audio src="audio.opus" />
10+
<audio>
11+
<source src="audio.opus" type="audio/ogg; codecs=opus"/>
12+
</audio>
1113
</body>
1214
</html>

src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/package.opf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<manifest>
1010
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
1111
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12-
<item id="audio" href="audio.opus" media-type="audio/opus"/>
12+
<item id="audio" href="audio.opus" media-type="audio/ogg ; codecs=opus"/>
1313
</manifest>
1414
<spine>
1515
<itemref idref="content_001" />

0 commit comments

Comments
 (0)