diff --git a/package-lock.json b/package-lock.json index b02be99ba17..1a1fb12f97f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,6 +6,9 @@ "": { "name": "hls.js", "license": "Apache-2.0", + "dependencies": { + "ci": "^2.3.0" + }, "devDependencies": { "@babel/core": "7.23.7", "@babel/helper-module-imports": "7.22.15", @@ -25,7 +28,7 @@ "@rollup/plugin-replace": "5.0.5", "@rollup/plugin-terser": "0.4.4", "@rollup/plugin-typescript": "11.1.6", - "@svta/common-media-library": "0.6.2", + "@svta/common-media-library": "^0.6.2", "@types/chai": "4.3.11", "@types/chart.js": "2.9.41", "@types/mocha": "10.0.6", @@ -5060,6 +5063,17 @@ "node": ">=18" } }, + "node_modules/ci": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/ci/-/ci-2.3.0.tgz", + "integrity": "sha512-0MGXkzJKkwV3enG7RUxjJKdiAkbaZ7visCjitfpCN2BQjv02KGRMxCHLv4RPokkjJ4xR33FLMAXweS+aQ0pFSQ==", + "bin": { + "ci": "dist/cli.js" + }, + "funding": { + "url": "https://github.com/privatenumber/ci?sponsor=1" + } + }, "node_modules/cli-cursor": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", @@ -16974,6 +16988,11 @@ "tcp-port-used": "^1.0.2" } }, + "ci": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/ci/-/ci-2.3.0.tgz", + "integrity": "sha512-0MGXkzJKkwV3enG7RUxjJKdiAkbaZ7visCjitfpCN2BQjv02KGRMxCHLv4RPokkjJ4xR33FLMAXweS+aQ0pFSQ==" + }, "cli-cursor": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", diff --git a/package.json b/package.json index 6f393047834..d5afb60bfb8 100644 --- a/package.json +++ b/package.json @@ -129,5 +129,8 @@ "typescript": "5.3.3", "url-toolkit": "2.2.5", "wrangler": "3.24.0" + }, + "dependencies": { + "ci": "^2.3.0" } } diff --git a/tests/unit/demuxer/id3.ts b/tests/unit/demuxer/id3.ts index fc070780e87..0584d3d27a1 100644 --- a/tests/unit/demuxer/id3.ts +++ b/tests/unit/demuxer/id3.ts @@ -1,7 +1,27 @@ +import { canParseId3 } from '@svta/common-media-library/id3/canParseId3'; +import { Id3Frame } from '@svta/common-media-library/id3/Id3Frame'; +import { isId3Header } from '@svta/common-media-library/id3/util/isId3Header'; import { expect } from 'chai'; import { utf8ArrayToStr } from '../../../src/demux/id3'; +import { decodeId3TextFrame } from '@svta/common-media-library/id3/util/decodeId3TextFrame'; describe('ID3 tests', function () { + const mockID3Header = Uint8Array.from([ + 73, 68, 51, 4, 0, 0, 0, 0, 0, 63, 80, 82, 73, 86, 0, 0, 0, 53, 0, 0, 99, + 111, 109, 46, 97, 112, 112, 108, 101, 46, 115, 116, 114, 101, 97, 109, 105, + 110, 103, 46, 116, 114, 97, 110, 115, 112, 111, 114, 116, 83, 116, 114, 101, + 97, 109, 84, 105, 109, 101, 115, 116, 97, 109, 112, 0, 0, 0, 0, 0, 0, 13, + 198, 135, + ]); + const mockID3HeaderMissingLeadingByte = mockID3Header.slice( + 8, + mockID3Header.length, + ); + const mockID3HeaderMissingTrailingByte = mockID3Header.slice( + 0, + mockID3Header.length - 8, + ); + it('utf8ArrayToStr', function (done) { const aB = new Uint8Array([97, 98]); const aNullBNullC = new Uint8Array([97, 0, 98, 0, 99]); @@ -12,4 +32,28 @@ describe('ID3 tests', function () { done(); }); + it('Properly parses ID3 Headers', function () { + expect(isId3Header(mockID3HeaderMissingLeadingByte, 0)).to.equal(false); + expect(isId3Header(mockID3HeaderMissingTrailingByte, 0)).to.equal(true); + expect(isId3Header(mockID3Header, 0)).to.equal(true); + }); + it('Properly parses ID3 Info', function () { + expect(canParseId3(mockID3Header, 0)).to.equal(true); + expect(canParseId3(mockID3HeaderMissingLeadingByte, 0)).to.equal(false); + expect(canParseId3(mockID3HeaderMissingTrailingByte, 0)).to.equal(false); + }); + + it('should decode a TXXX frame', function () { + const frame = { + type: 'TXXX', + data: new Uint8Array([0, 102, 111, 111, 0, 97, 98, 99]), + size: 2, // required by the _decodeTextFrame function + }; + + const result: Id3Frame | undefined = decodeId3TextFrame(frame); + expect(result).to.exist; + expect(result!.key).to.equal('TXXX'); + expect(result!.info).to.equal('foo'); + expect(result!.data).to.equal('abc'); + }); });