Skip to content

Commit e3f75f5

Browse files
committed
Feat: Downloading: Add opus audio metadata tags
This adds a simple timestamp to downloaded opus files in the form of a COMMENT tag.
1 parent cd056a7 commit e3f75f5

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

app/src/main/java/org/schabi/newpipe/streams/OggFromWebMWriter.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414
import java.nio.ByteBuffer;
1515
import java.nio.ByteOrder;
16+
import java.time.OffsetDateTime;
1617

1718
/**
1819
* @author kapodamy
@@ -272,11 +273,24 @@ private int makePacketheader(final long granPos, @NonNull final ByteBuffer buffe
272273
@Nullable
273274
private byte[] makeMetadata() {
274275
if ("A_OPUS".equals(webmTrack.codecId)) {
275-
return new byte[]{
276+
final var commentFormat = "COMMENT=Downloaded using NewPipe on %s";
277+
final var commentStr = String.format(commentFormat, OffsetDateTime.now().toString());
278+
final var comment = commentStr.getBytes();
279+
final var head = ByteBuffer.allocate(20 + comment.length);
280+
head.order(ByteOrder.LITTLE_ENDIAN);
281+
head.put(new byte[]{
282+
// Byte order is LE, i.e. LSB first
276283
0x4F, 0x70, 0x75, 0x73, 0x54, 0x61, 0x67, 0x73, // "OpusTags" binary string
277-
0x00, 0x00, 0x00, 0x00, // writing application string size (not present)
278-
0x00, 0x00, 0x00, 0x00 // additional tags count (zero means no tags)
279-
};
284+
0x00, 0x00, 0x00, 0x00, // vendor string of length 0
285+
0x01, 0x00, 0x00, 0x00, // additional tags count
286+
287+
// + 4 bytes for the comment string length
288+
// + N bytes for the comment string itself
289+
});
290+
head.putInt(comment.length);
291+
head.put(comment);
292+
293+
return head.array();
280294
} else if ("A_VORBIS".equals(webmTrack.codecId)) {
281295
return new byte[]{
282296
0x03, // ¿¿¿???

0 commit comments

Comments
 (0)