Skip to content

Commit 312404f

Browse files
committed
Filter out subtitles asset type
1 parent a2590a5 commit 312404f

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

apps-rendering/src/atoms.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ describe('parseAtom', () => {
653653
let atoms: Atoms;
654654
let media: Atom;
655655
let mediaAtom: MediaAtom;
656+
const assetVersion = new Int64(1);
656657

657658
beforeEach(() => {
658659
blockElement.contentAtomTypeData = {
@@ -662,10 +663,16 @@ describe('parseAtom', () => {
662663
mediaAtom = {
663664
title: '',
664665
assets: [
666+
{
667+
assetType: AssetType.SUBTITLES,
668+
id: 'subtitles-asset-id',
669+
version: assetVersion,
670+
platform: Platform.YOUTUBE,
671+
},
665672
{
666673
assetType: AssetType.VIDEO,
667-
id: 'asset-id',
668-
version: new Int64(1),
674+
id: 'video-asset-id',
675+
version: assetVersion,
669676
platform: Platform.YOUTUBE,
670677
},
671678
],
@@ -726,7 +733,7 @@ describe('parseAtom', () => {
726733
posterUrl: 'poster-url',
727734
caption: some(frag),
728735
duration: some(1000),
729-
videoId: 'asset-id',
736+
videoId: 'video-asset-id',
730737
id: atomId,
731738
title: '',
732739
}),

apps-rendering/src/atoms.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { isValidDate } from 'date';
88
import type { Int64 } from 'thrift';
99
import type { DocParser } from 'parserContext';
1010
import { Result } from 'result';
11+
import type { MediaAtom } from '@guardian/content-atom-model/media/mediaAtom';
12+
import { AssetType } from '@guardian/content-atom-model/media/assetType';
1113

1214
interface TimelineEvent {
1315
title: string;
@@ -248,9 +250,13 @@ function parseAtom(
248250
return Result.err(`No atom matched this id: ${id}`);
249251
}
250252

253+
const mediaAtom: MediaAtom = atom.data.media;
251254
const { posterUrl, duration, assets, activeVersion, title } =
252-
atom.data.media;
253-
const videoId = assets.find(
255+
mediaAtom;
256+
const videoAssets = assets.filter(
257+
(asset) => asset.assetType === AssetType.VIDEO,
258+
);
259+
const videoId = videoAssets.find(
254260
(asset) =>
255261
asset.version.toNumber() === activeVersion?.toNumber(),
256262
)?.id;

apps-rendering/src/video.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ describe('parseVideo', () => {
2222
let mediaAtom: MediaAtom;
2323
const atomId = 'atomId2';
2424
const posterUrl = 'poster-url';
25-
const assetId = 'asset-id';
25+
const videoAssetId = 'video-asset-id';
26+
const subtitlesAssetId = 'subtitles-asset-id';
2627
const mediaAtomTitle = 'mediaTitle';
2728
const assetVersion = new Int64(2);
2829

@@ -43,9 +44,15 @@ describe('parseVideo', () => {
4344

4445
mediaAtom = {
4546
assets: [
47+
{
48+
assetType: AssetType.SUBTITLES,
49+
id: subtitlesAssetId,
50+
version: assetVersion,
51+
platform: Platform.YOUTUBE,
52+
},
4653
{
4754
assetType: AssetType.VIDEO,
48-
id: assetId,
55+
id: videoAssetId,
4956
version: assetVersion,
5057
platform: Platform.YOUTUBE,
5158
},
@@ -79,7 +86,7 @@ describe('parseVideo', () => {
7986
test('returns video', () => {
8087
const expected = Optional.some({
8188
posterUrl: posterUrl,
82-
videoId: assetId,
89+
videoId: videoAssetId,
8390
duration: undefined,
8491
atomId: atomId,
8592
title: mediaAtomTitle,

apps-rendering/src/video.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Atoms } from '@guardian/content-api-models/v1/atoms';
22
import type { BlockElement } from '@guardian/content-api-models/v1/blockElement';
33
import { Optional } from 'optional';
4+
import type { MediaAtom } from '@guardian/content-atom-model/media/mediaAtom';
5+
import { AssetType } from '@guardian/content-atom-model/media/assetType';
46

57
interface Video {
68
posterUrl: string;
@@ -23,10 +25,12 @@ const parseVideo =
2325
if (atom?.data.kind !== 'media') {
2426
return Optional.none();
2527
}
26-
27-
const { posterUrl, duration, assets, activeVersion, title } =
28-
atom.data.media;
29-
const videoId = assets.find(
28+
const mediaAtom: MediaAtom = atom.data.media;
29+
const { posterUrl, duration, assets, activeVersion, title } = mediaAtom;
30+
const videoAssets = assets.filter(
31+
(asset) => asset.assetType === AssetType.VIDEO,
32+
);
33+
const videoId = videoAssets.find(
3034
(asset) => asset.version.toNumber() === activeVersion?.toNumber(),
3135
)?.id;
3236

dotcom-rendering/src/model/enhanceCards.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ describe('Enhance Cards', () => {
55
it('filters out m3u8 assets until supported by DCR', () => {
66
const videoReplace = true;
77
const assets: FEMediaAsset[] = [
8+
{
9+
id: 'https://guim-example.co.uk/atomID-1.vtt',
10+
version: 1,
11+
platform: 'Url',
12+
mimeType: 'text/vtt',
13+
assetType: 'Subtitles',
14+
},
815
{
916
id: 'https://guim-example.co.uk/atomID-1.m3u8',
1017
version: 1,

dotcom-rendering/src/model/enhanceCards.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export const getActiveMediaAtom = (
200200
if (mediaAtom) {
201201
const m3u8MimeType = 'application/vnd.apple.mpegurl';
202202
const asset = mediaAtom.assets
203+
.filter((_) => _.assetType === 'Video')
203204
// filter out m3u8 assets, as these are not yet supported by DCR
204205
.filter((_) => _.mimeType !== m3u8MimeType)
205206
.find(({ version }) => version === mediaAtom.activeVersion);

0 commit comments

Comments
 (0)