MCPcopy
hub / github.com/midrender/revideo / detectFileType

Method detectFileType

packages/2d/src/lib/components/Video.ts:331–396  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

329 }
330
331 private detectFileType() {
332 return DependencyContext.collectPromise(
333 (async () => {
334 const src = this.src();
335 const extension = src.split('?')[0].split('.').pop()?.toLowerCase();
336
337 if (
338 extension === 'mp4' ||
339 extension === 'webm' ||
340 extension === 'mov'
341 ) {
342 this.detectedFileType = extension;
343 this.fileTypeWasDetected = true;
344 return;
345 }
346
347 if (extension === 'm3u8') {
348 this.detectedFileType = 'hls';
349 this.fileTypeWasDetected = true;
350 return;
351 }
352
353 if (!src.startsWith('http://') && !src.startsWith('https://')) {
354 this.handleUnknownFileType(src);
355 return;
356 }
357
358 const response = await fetch(src, {method: 'HEAD'});
359 const contentType = response.headers.get('Content-Type');
360
361 if (!contentType) {
362 this.handleUnknownFileType(src);
363 return;
364 }
365
366 if (contentType.includes('video/mp4')) {
367 this.detectedFileType = 'mp4';
368 this.fileTypeWasDetected = true;
369 return;
370 }
371
372 if (contentType.includes('video/webm')) {
373 this.detectedFileType = 'webm';
374 this.fileTypeWasDetected = true;
375 return;
376 }
377
378 if (contentType.includes('video/quicktime')) {
379 this.detectedFileType = 'mov';
380 this.fileTypeWasDetected = true;
381 return;
382 }
383
384 if (
385 contentType.includes('application/vnd.apple.mpegurl') ||
386 contentType.includes('application/x-mpegURL')
387 ) {
388 this.detectedFileType = 'hls';

Callers 1

seekFunctionMethod · 0.95

Calls 5

handleUnknownFileTypeMethod · 0.95
collectPromiseMethod · 0.80
includesMethod · 0.80
splitMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected