ref: f2b2f57fb540795814ef66e95eb7aaf1434e8e47
parent: e6b63eabaef2185b7c788d6cbb7df939328267c6
author: qwx <qwx@sciops.net>
date: Sun Jan 12 11:24:00 EST 2020
add file-opus: ogg/opus detection, differentiation from ogg/vorbis
--- /dev/null
+++ b/file-opus
@@ -1,0 +1,58 @@
+diff -r d6c26034ff13 sys/src/cmd/file.c
+--- a/sys/src/cmd/file.c Sun Jan 12 00:19:39 2020 +0100
++++ b/sys/src/cmd/file.c Sun Jan 12 17:12:40 2020 +0100
+@@ -153,6 +153,8 @@
+ int istga(void);
+ int ismp3(void);
+ int ismp4(void);
++int isoggvorbis(void);
++int isoggopus(void);
+ int ismung(void);
+ int isp9bit(void);
+ int isp9font(void);
+@@ -203,6 +205,8 @@
+ istga,
+ ismp3,
+ ismp4,
++ isoggvorbis,
++ isoggopus,
+
+ /* last resorts */
+ ismung, /* entropy compressed/encrypted */
+@@ -838,7 +842,6 @@
+ "\033%-12345X", "HPJCL file", 9, "application/hpjcl",
+ "\033Lua", "Lua bytecode", 4, OCTET,
+ "ID3", "mp3 audio with id3", 3, "audio/mpeg",
+- "OggS", "ogg audio", 4, "audio/ogg",
+ ".snd", "sun audio", 4, "audio/basic",
+ "\211PNG", "PNG image", 4, "image/png",
+ "P1\n", "ppm", 3, "image/ppm",
+@@ -1262,6 +1265,28 @@
+ return 0;
+ }
+
++int
++isoggvorbis(void)
++{
++ if(memcmp(&buf[0], "OggS", 4) != 0)
++ return 0;
++ if(memcmp(&buf[29], "vorbis", 6) != 0)
++ return 0;
++ print("%s\n", mime ? "audio/ogg;codecs=vorbis" : "ogg audio");
++ return 1;
++}
++
++int
++isoggopus(void)
++{
++ if(memcmp(&buf[0], "OggS", 4) != 0)
++ return 0;
++ if(memcmp(&buf[28], "OpusHead", 8) != 0)
++ return 0;
++ print("%s\n", mime ? "audio/ogg;codecs=opus" : "ogg audio");
++ return 1;
++}
++
+ /*
+ * low entropy means encrypted
+ */