id3-ts-lib
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -5,15 +5,42 @@ #!/usr/bin/env node | ||
// Turn the first argument into a id3 tag | ||
if (process.argv[2]) { | ||
const args = process.argv.slice(2); | ||
let videoPidIndex = args.indexOf('-v') | ||
if (videoPidIndex === -1) { | ||
videoPidIndex = args.indexOf('--video-pid'); | ||
} | ||
const videoPid = videoPidIndex !== -1 ? args.splice(videoPidIndex, 2)[1] || null : null; | ||
let audioPidIndex = args.indexOf('-a'); | ||
if (audioPidIndex === -1) { | ||
audioPidIndex = args.indexOf('--audio-pid'); | ||
} | ||
const audioPid = audioPidIndex !== -1 ? args.splice(audioPidIndex, 2)[1] || null : null; | ||
let id3PtsIndex = args.indexOf('-p'); | ||
if (id3PtsIndex === -1) { | ||
id3PtsIndex = args.indexOf('--id3-pts'); | ||
} | ||
const id3PTS = id3PtsIndex !== -1 ? Number(args.splice(id3PtsIndex, 2)[1]) || 282743 : 282743; | ||
const data = args.pop(); | ||
if (data) { | ||
const options = { | ||
pmtPid: 0x100, | ||
id3Pid: 0x103, | ||
videoPid: null, | ||
audioPid: null, | ||
id3PTS: 282743, | ||
data: process.argv[2], | ||
id3PTS, | ||
videoPid, | ||
audioPid, | ||
data | ||
}; | ||
generateID3Segment(options).then((segment) => { | ||
process.stdout.write(segment); | ||
}); | ||
} else { | ||
console.error('Please add some data'); | ||
} |
@@ -175,3 +175,3 @@ const { generatePATPacket } = require('./lib/pat'); | ||
const id3Length = calculateId3TagLength(data.length); | ||
const id3Length = calculateId3TagLength(Buffer.byteLength(data)); | ||
const pesPacketLength = id3Length + sizeOf.PES_HEADER + sizeOf.PTS; | ||
@@ -203,3 +203,3 @@ const paddingNeeded = Math.ceil(pesPacketLength / MAX_TS_PAYLOAD) * MAX_TS_PAYLOAD - pesPacketLength; | ||
const generateSegment = (options) => { | ||
const outputLength = calculateOutputBufferLength(options.data.length); | ||
const outputLength = calculateOutputBufferLength(Buffer.byteLength(options.data)); | ||
const outputBuffer = Buffer.allocUnsafe(outputLength); | ||
@@ -206,0 +206,0 @@ |
{ | ||
"name": "id3-ts-lib", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "An ID3-only MPEG2TS segment generator library.", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"bin": { | ||
"id3-ts": "./bin/index.js" | ||
"id3-ts": "bin/index.js" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
@@ -33,5 +33,6 @@ const generateSegment = require('../../'); | ||
// Verify the last packet - the PES | ||
const dataBuffer = Buffer.from(options.data); | ||
const lastPacket = b.slice(376); | ||
const pesHeader = lastPacket.slice(4); | ||
const id3TagLength = 10 + 12 + options.data.length + 1; | ||
const id3TagLength = 10 + 12 + dataBuffer.length + 1; | ||
const paddingLength = 184 - (id3TagLength + 14); | ||
@@ -41,3 +42,3 @@ const id3StartByte = 4 + 14 + paddingLength; | ||
verifyPesHeader(pesHeader, options.id3PTS, id3TagLength, paddingLength); | ||
veryifyId3(lastPacket.slice(id3StartByte), options.data); | ||
veryifyId3(lastPacket.slice(id3StartByte), dataBuffer); | ||
}); | ||
@@ -65,5 +66,6 @@ | ||
// Verify the last packet - the PES | ||
const dataBuffer = Buffer.from(options.data); | ||
const lastPacket = b.slice(376); | ||
const pesHeader = lastPacket.slice(4); | ||
const id3TagLength = 10 + 12 + options.data.length + 1; | ||
const id3TagLength = 10 + 12 + dataBuffer.length + 1; | ||
const paddingLength = 184 - (id3TagLength + 14); | ||
@@ -73,3 +75,3 @@ const id3StartByte = 4 + 14 + paddingLength; | ||
verifyPesHeader(pesHeader, options.id3PTS, id3TagLength, paddingLength); | ||
veryifyId3(lastPacket.slice(id3StartByte), options.data); | ||
veryifyId3(lastPacket.slice(id3StartByte), dataBuffer); | ||
}); | ||
@@ -98,5 +100,6 @@ }); | ||
// Verify the third packet - the PES | ||
const dataBuffer = Buffer.from(options.data); | ||
const thirdPacket = b.slice(376); | ||
const pesHeader = thirdPacket.slice(4); | ||
const id3TagLength = 10 + 12 + options.data.length + 1; | ||
const id3TagLength = 10 + 12 + dataBuffer.length + 1; | ||
const paddingLength = 368 - (id3TagLength + 14); | ||
@@ -113,3 +116,3 @@ const id3StartByte = 376 + 4 + 14 + paddingLength; | ||
]); | ||
veryifyId3(id3Tag, options.data); | ||
veryifyId3(id3Tag, dataBuffer); | ||
@@ -141,5 +144,6 @@ // Verify the last packet - the PES (cont.) | ||
// Verify the third packet - the PES | ||
const dataBuffer = Buffer.from(options.data); | ||
const thirdPacket = b.slice(376); | ||
const pesHeader = thirdPacket.slice(4); | ||
const id3TagLength = 10 + 12 + options.data.length + 1; | ||
const id3TagLength = 10 + 12 + dataBuffer.length + 1; | ||
const paddingLength = 368 - (id3TagLength + 14); | ||
@@ -152,3 +156,3 @@ const id3StartByte = 4 + 14 + paddingLength + 4; | ||
veryifyId3(thirdPacket.slice(id3StartByte), options.data); | ||
veryifyId3(thirdPacket.slice(id3StartByte), dataBuffer); | ||
@@ -159,2 +163,49 @@ // Verify the last packet - the PES (cont.) | ||
}); | ||
it('should generate a unicode-encoded segment', () => { | ||
const options = { | ||
pmtPid: 0x101, | ||
id3Pid: 0x180, | ||
id3PTS: 1234567890, | ||
data: ` | ||
The quick brown fox jumps over the lazy dog. | ||
Falsches Üben von Xylophonmusik quält jeden größeren Zwerg. | ||
Съешь же ещё этих мягких французских булок да выпей чаю. | ||
זה כיף סתם לשמוע איך תנצח קרפד עץ טוב בגן. | ||
`, | ||
}; | ||
const b = generateSegment.sync(options); | ||
// First, make sure it's exactly 4 TS packets long | ||
assert.equal(b.length, 752); | ||
// Verify the first packet - the PAT | ||
verifyPat(b, options.pmtPid); | ||
// Verify the second packet - the PMT | ||
const secondPacket = b.slice(188); | ||
verifyPmt(secondPacket, options.pmtPid, options.id3Pid); | ||
// Verify the third packet - the PES | ||
const dataBuffer = Buffer.from(options.data); | ||
const thirdPacket = b.slice(376); | ||
const pesHeader = thirdPacket.slice(4); | ||
const id3TagLength = 10 + 12 + dataBuffer.length + 1; | ||
const paddingLength = 368 - (id3TagLength + 14); | ||
const id3StartByte = 376 + 4 + 14 + paddingLength; | ||
verifyTs(thirdPacket, options.id3Pid, 0, true); | ||
verifyPesHeader(pesHeader, options.id3PTS, id3TagLength, paddingLength); | ||
// console.log(thirdPacket.slice(id3StartByte).toString('hex').replace(/(\w\w)/g, '0x$1, ')); | ||
const id3Tag = Buffer.concat([ | ||
b.slice(id3StartByte, 564), | ||
b.slice(568), | ||
]); | ||
veryifyId3(id3Tag, dataBuffer); | ||
// Verify the last packet - the PES (cont.) | ||
const lastPacket = b.slice(564); | ||
verifyTs(lastPacket, options.id3Pid, 1, false); | ||
}); | ||
}); |
@@ -163,3 +163,3 @@ const assert = require('assert'); | ||
const verifyPayload = (b, expectedPayload) => { | ||
assert.equal(b.toString('utf8'), expectedPayload); | ||
assert.deepStrictEqual(b, expectedPayload); | ||
} | ||
@@ -166,0 +166,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
65215
1616
1