Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SRT support in Transcript component #446

Merged
merged 2 commits into from
Mar 12, 2024
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
508 changes: 508 additions & 0 deletions public/lunchroom_manners/lunchroom_manners.srt

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions public/manifests/dev/lunchroom_manners.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,22 @@
}
},
"target": "http://localhost:3003/dev/lunchroom_manners/canvas/1"
},
{
"id": "http://localhost:3003/dev/lunchroom_manners/canvas/1/annotation/srt",
"type": "Annotation",
"motivation": "supplementing",
"body": {
"id": "http://localhost:3003/lunchroom_manners/lunchroom_manners.srt",
"type": "Text",
"format": "application/x-subrip",
"label": {
"en": [
"SRT Transcript (machine-generated)"
]
}
},
"target": "http://localhost:3003/dev/lunchroom_manners/canvas/1"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions public/manifests/dev/playlist-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
"body": {
"id": "http://localhost:3003/volleyball-for-boys/volleyball.txt",
"type": "Text",
"format": "plain/txt",
"format": "text/plain",
"label": {
"en": [
"External Text Transcript (machine-generated)"
Expand Down Expand Up @@ -356,4 +356,4 @@
]
}
]
}
}
4 changes: 2 additions & 2 deletions public/manifests/dev/volleyball-for-boys.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"body": {
"id": "http://localhost:6060/volleyball-for-boys/volleyball.txt",
"type": "Text",
"format": "plain/txt",
"format": "text/plain",
"label": {
"en": [
"External Text Transcript (machine-generated)"
Expand All @@ -62,4 +62,4 @@
]
}
]
}
}
16 changes: 16 additions & 0 deletions public/manifests/prod/lunchroom_manners.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@
}
},
"target": "https://iiif-react-media-player.netlify.app/prod/lunchroom_manners/canvas/1"
},
{
"id": "https://iiif-react-media-player.netlify.app/prod/lunchroom_manners/canvas/1/annotation/srt",
"type": "Annotation",
"motivation": "supplementing",
"body": {
"id": "https://iiif-react-media-player.netlify.app/lunchroom_manners/lunchroom_manners.srt",
"type": "Text",
"format": "application/x-subrip",
"label": {
"en": [
"SRT Transcript (machine-generated)"
]
}
},
"target": "https://iiif-react-media-player.netlify.app/prod/lunchroom_manners/canvas/1"
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/Transcript/Transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'lodash';
import TanscriptSelector from './TranscriptMenu/TranscriptSelector';
import { autoScroll, checkSrcRange, getMediaFragment, timeToHHmmss } from '@Services/utility-helpers';
import {
getSupplementingAnnotations,
readSupplementingAnnotations,
parseTranscriptData,
sanitizeTranscripts,
TRANSCRIPT_TYPES,
Expand Down Expand Up @@ -143,7 +143,7 @@ const Transcript = ({ playerID, manifestUrl, transcripts = [] }) => {
allTranscripts = await sanitizeTranscripts(transcripts);
} else if (manifestUrl) {
// Read supplementing annotations from the given manifest
allTranscripts = await getSupplementingAnnotations(manifestUrl);
allTranscripts = await readSupplementingAnnotations(manifestUrl);
}
setTranscriptsList(allTranscripts);
initTranscriptData(allTranscripts);
Expand Down Expand Up @@ -206,7 +206,7 @@ const Transcript = ({ playerID, manifestUrl, transcripts = [] }) => {
// set isEmpty flag to render transcripts UI
setIsEmpty(false);

const { id, title, filename, url, isMachineGen } = transcript;
const { id, title, filename, url, isMachineGen, format } = transcript;

// Check cached transcript data
const cached = cachedTranscripts.filter(
Expand All @@ -220,7 +220,7 @@ const Transcript = ({ playerID, manifestUrl, transcripts = [] }) => {
} else {
// Parse new transcript data from the given sources
await Promise.resolve(
parseTranscriptData(url, canvasIndexRef.current)
parseTranscriptData(url, canvasIndexRef.current, format)
).then(function (value) {
if (value != null) {
const { tData, tUrl, tType, tFileExt } = value;
Expand Down
6 changes: 6 additions & 0 deletions src/components/Transcript/Transcript.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Transcript component displays any available transcript data in a given IIIF mani
- Word document (.docx)
- Plain text file
- WebVTT
- SRT

`transcripts` prop has a default value of an empty array.

Expand Down Expand Up @@ -68,6 +69,11 @@ import config from '../../../env.js';
title: 'Invalid transcript',
url: `${config.url}/manifests/${config.env}/invalid-annotation.json`, // URL of the manifest
},
{
// SRT file
title: 'SRT Transcript',
url: `${config.url}/lunchroom_manners/lunchroom_manners.srt`,
},
],
},
]}
Expand Down
18 changes: 9 additions & 9 deletions src/components/Transcript/Transcript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ describe('Transcript component', () => {
]
}
];
const getSupplementingAnnotationsMock = jest
.spyOn(transcriptParser, 'getSupplementingAnnotations')
const readSupplementingAnnotationsMock = jest
.spyOn(transcriptParser, 'readSupplementingAnnotations')
.mockReturnValue(transcriptsList);

const parseTranscriptMock = jest
Expand All @@ -573,7 +573,7 @@ describe('Transcript component', () => {
await act(() => Promise.resolve());

await waitFor(() => {
expect(getSupplementingAnnotationsMock).toHaveBeenCalledTimes(1);
expect(readSupplementingAnnotationsMock).toHaveBeenCalledTimes(1);
expect(parseTranscriptMock).toHaveBeenCalledTimes(1);
expect(screen.queryByTestId('transcript-selector')).toBeInTheDocument();
expect(screen.queryByTestId('transcript_content_1')).toBeInTheDocument();
Expand All @@ -593,8 +593,8 @@ describe('Transcript component', () => {
manifestUrl: 'http://example.com/manifest.json'
};

const getSupplementingAnnotationsMock = jest
.spyOn(transcriptParser, 'getSupplementingAnnotations')
const readSupplementingAnnotationsMock = jest
.spyOn(transcriptParser, 'readSupplementingAnnotations')
.mockReturnValue([]);

const parseTranscriptMock = jest
Expand All @@ -610,7 +610,7 @@ describe('Transcript component', () => {
await act(() => Promise.resolve());

await waitFor(() => {
expect(getSupplementingAnnotationsMock).toHaveBeenCalledTimes(1);
expect(readSupplementingAnnotationsMock).toHaveBeenCalledTimes(1);
expect(parseTranscriptMock).not.toHaveBeenCalled();
expect(screen.queryByTestId('transcript-selector')).not.toBeInTheDocument();
expect(screen.queryByTestId('transcript_content_0')).toBeInTheDocument();
Expand All @@ -631,8 +631,8 @@ describe('Transcript component', () => {
}],
};

const getSupplementingAnnotationsMock = jest
.spyOn(transcriptParser, 'getSupplementingAnnotations');
const readSupplementingAnnotationsMock = jest
.spyOn(transcriptParser, 'readSupplementingAnnotations');

render(
<React.Fragment>
Expand All @@ -643,7 +643,7 @@ describe('Transcript component', () => {
await act(() => Promise.resolve());

await waitFor(() => {
expect(getSupplementingAnnotationsMock).not.toHaveBeenCalled();
expect(readSupplementingAnnotationsMock).not.toHaveBeenCalled();
expect(screen.queryByTestId('transcript-selector')).not.toBeInTheDocument();
expect(screen.queryByTestId('transcript_content_0')).toBeInTheDocument();
expect(screen.queryByTestId('no-transcript')).toBeInTheDocument();
Expand Down
Loading