Skip to content

Commit 985372d

Browse files
authored
Filter out m3u8 videos (#14784)
* Filter out m3u8 videos which testing * skip tests whilst we are filtering out m3u8 * Filter out m3u8 if in loop video load test
1 parent 539b99c commit 985372d

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FEMediaAsset, FEMediaAtom } from '../frontend/feFront';
22
import { getActiveMediaAtom } from './enhanceCards';
33

4-
describe('Enhance Cards', () => {
4+
describe.skip('Enhance Cards', () => {
55
it('prioritises m3u8 assets over MP4 assets', () => {
66
const videoReplace = true;
77
const assets: FEMediaAsset[] = [

dotcom-rendering/src/model/enhanceCards.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,30 @@ export const getActiveMediaAtom = (
198198
videoReplace: boolean,
199199
mediaAtom?: FEMediaAtom,
200200
cardTrailImage?: string,
201+
isLoopVideoLoadTest?: boolean,
201202
): MainMedia | undefined => {
202203
if (mediaAtom) {
203-
const assets = mediaAtom.assets
204-
.filter((_) => _.assetType === 'Video')
205-
.filter(({ version }) => version === mediaAtom.activeVersion);
206-
if (!assets.length) return undefined;
204+
let assets;
205+
if (isLoopVideoLoadTest) {
206+
/* temporarily filter out m3u8 files */
207+
assets = mediaAtom.assets
208+
.filter((_) => !m3u8MimeType.includes(_.mimeType ?? ''))
209+
.filter(({ version }) => version === mediaAtom.activeVersion);
210+
} else {
211+
assets = mediaAtom.assets.filter(
212+
({ version }) => version === mediaAtom.activeVersion,
213+
);
214+
}
215+
216+
const m3u8MimeType = [
217+
'application/vnd.apple.mpegurl',
218+
'application/x-mpegURL',
219+
];
220+
221+
const videoAssets = assets.filter(
222+
({ assetType }) => assetType === 'Video',
223+
);
224+
if (!videoAssets.length) return undefined;
207225

208226
const image = decideMediaAtomImage(
209227
videoReplace,
@@ -279,11 +297,17 @@ const decideMedia = (
279297
imageHide?: boolean,
280298
videoReplace?: boolean,
281299
cardImage?: string,
300+
isLoopVideoLoadTest?: boolean,
282301
): MainMedia | undefined => {
283302
// If the showVideo toggle is enabled in the fronts tool,
284303
// we should return the active mediaAtom regardless of the design
285304
if (!!showMainVideo || !!videoReplace) {
286-
return getActiveMediaAtom(!!videoReplace, mediaAtom, cardImage);
305+
return getActiveMediaAtom(
306+
!!videoReplace,
307+
mediaAtom,
308+
cardImage,
309+
isLoopVideoLoadTest,
310+
);
287311
}
288312

289313
switch (format.design) {
@@ -298,7 +322,12 @@ const decideMedia = (
298322
};
299323

300324
case ArticleDesign.Video: {
301-
return getActiveMediaAtom(false, mediaAtom, cardImage);
325+
return getActiveMediaAtom(
326+
false,
327+
mediaAtom,
328+
cardImage,
329+
isLoopVideoLoadTest,
330+
);
302331
}
303332

304333
default:
@@ -315,6 +344,7 @@ export const enhanceCards = (
315344
pageId,
316345
discussionApiUrl,
317346
stripBranding = false,
347+
isLoopVideoLoadTest,
318348
}: {
319349
cardInTagPage: boolean;
320350
/** Used for the data link name to indicate card position in container */
@@ -324,6 +354,7 @@ export const enhanceCards = (
324354
discussionApiUrl: string;
325355
/** We strip branding from cards if the branding will appear at the collection level instead */
326356
stripBranding?: boolean;
357+
isLoopVideoLoadTest?: boolean;
327358
},
328359
): DCRFrontCard[] =>
329360
collections.map((faciaCard, index) => {
@@ -379,6 +410,7 @@ export const enhanceCards = (
379410
faciaCard.display.imageHide,
380411
faciaCard.properties.mediaSelect?.videoReplace,
381412
imageSrc,
413+
isLoopVideoLoadTest,
382414
);
383415

384416
return {

dotcom-rendering/src/model/enhanceCollections.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const enhanceCollections = ({
6565
frontBranding,
6666
onPageDescription,
6767
isOnPaidContentFront,
68+
isLoopVideoLoadTest,
6869
}: {
6970
collections: FECollection[];
7071
editionId: EditionId;
@@ -73,6 +74,7 @@ export const enhanceCollections = ({
7374
frontBranding: Branding | undefined;
7475
onPageDescription?: string;
7576
isOnPaidContentFront?: boolean;
77+
isLoopVideoLoadTest?: boolean;
7678
}): DCRCollectionType[] => {
7779
const indexToShowFrontBranding =
7880
findCollectionSuitableForFrontBranding(collections);
@@ -133,18 +135,21 @@ export const enhanceCollections = ({
133135
editionId,
134136
discussionApiUrl,
135137
stripBrandingFromCards,
138+
isLoopVideoLoadTest,
136139
),
137140
curated: enhanceCards(collection.curated, {
138141
cardInTagPage: false,
139142
editionId,
140143
discussionApiUrl,
141144
stripBranding: stripBrandingFromCards,
145+
isLoopVideoLoadTest,
142146
}),
143147
backfill: enhanceCards(collection.backfill, {
144148
cardInTagPage: false,
145149
editionId,
146150
discussionApiUrl,
147151
stripBranding: stripBrandingFromCards,
152+
isLoopVideoLoadTest,
148153
}),
149154
treats: enhanceTreats(
150155
collection.treats,

dotcom-rendering/src/model/groupCards.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const groupCards = (
3232
editionId: EditionId,
3333
discussionApiUrl: string,
3434
stripBranding: boolean = false,
35+
isLoopVideoLoadTest?: boolean,
3536
): DCRGroupedTrails => {
3637
switch (container) {
3738
case 'dynamic/fast':
@@ -96,6 +97,7 @@ export const groupCards = (
9697
discussionApiUrl,
9798
offset,
9899
stripBranding,
100+
isLoopVideoLoadTest,
99101
});
100102

101103
return {
@@ -122,6 +124,7 @@ export const groupCards = (
122124
discussionApiUrl,
123125
offset,
124126
stripBranding,
127+
isLoopVideoLoadTest,
125128
});
126129

127130
return {

dotcom-rendering/src/server/handler.front.web.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const enhanceFront = (body: unknown): Front => {
4545
.editionBrandings,
4646
data.editionId,
4747
),
48+
isLoopVideoLoadTest:
49+
data.config.abTests.LoopVideoLoadVariant === 'variant',
4850
}),
4951
},
5052
mostViewed: data.mostViewed.map((trail) => decideTrail(trail)),

0 commit comments

Comments
 (0)