(url: string)
| 35 | } |
| 36 | |
| 37 | async function probeOne(url: string): Promise<MediaProbeResult | null> { |
| 38 | const mb = await loadMediabunny(); |
| 39 | if (!mb) return null; |
| 40 | |
| 41 | const input = new mb.Input({ |
| 42 | source: new mb.UrlSource(url), |
| 43 | formats: mb.ALL_FORMATS, |
| 44 | }); |
| 45 | try { |
| 46 | const duration = await input.getDurationFromMetadata(); |
| 47 | if (duration == null || !Number.isFinite(duration) || duration <= 0) return null; |
| 48 | |
| 49 | const videoTrack = await input.getPrimaryVideoTrack(); |
| 50 | const audioTracks = await input.getAudioTracks(); |
| 51 | |
| 52 | const result: MediaProbeResult = { |
| 53 | duration, |
| 54 | width: videoTrack?.displayWidth, |
| 55 | height: videoTrack?.displayHeight, |
| 56 | hasVideo: videoTrack != null, |
| 57 | hasAudio: audioTracks.length > 0, |
| 58 | }; |
| 59 | return result; |
| 60 | } catch { |
| 61 | return null; |
| 62 | } finally { |
| 63 | input.dispose(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | function getCachedProbe(url: string): MediaProbeResult | undefined { |
| 68 | return cache.get(normalizeUrl(url)); |
no test coverage detected