Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/utils/mediaUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ describe('utils/mediaUtils.ts', () => {
expect(isAttachedPic(validVideo)).toBe(false);
});

test('isAttachedPic should handle undefined or malformed codec_name safely', () => {
const malformedStream = {
index: 6,
codec_type: 'video',
codec_name: undefined
} as any;

expect(() => isAttachedPic(malformedStream)).not.toThrow();
expect(isAttachedPic(malformedStream)).toBe(false);
});

test('isGarbageStream should group image subtitles and cover art as garbage', () => {
expect(isGarbageStream(imageSubPGS)).toBe(true);
expect(isGarbageStream(coverArtAttached)).toBe(true);
Expand Down
5 changes: 4 additions & 1 deletion src/utils/mediaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export const isImageSubtitle = (codecName: string | undefined): boolean => {
};

export const isAttachedPic = (stream: Pick<MediaStream, 'disposition' | 'codec_name'>): boolean => {
return stream.disposition?.attached_pic === 1 || ATTACHED_PIC_CODECS.has(stream.codec_name.toLowerCase());
return (
stream.disposition?.attached_pic === 1 ||
(!!stream.codec_name && ATTACHED_PIC_CODECS.has(stream.codec_name.toLowerCase()))
);
};

export const isGarbageStream = (stream: MediaStream): boolean => {
Expand Down
Loading