Add duration
All checks were successful
ci / Image build (push) Successful in 2m12s
ci / Deployment (push) Successful in 20s

This commit is contained in:
Joris Bertomeu
2025-08-26 11:45:31 +02:00
parent 478e154d5d
commit 6faebd723d

View File

@@ -353,6 +353,29 @@ const extractPercentage = (line) => {
return Math.max(...percentages.filter((p) => p < 100)); return Math.max(...percentages.filter((p) => p < 100));
} }
const formatDuration = (seconds) => {
if (isNaN(seconds) || seconds < 0) {
return 'Invalid input';
}
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const secs = seconds % 60;
const parts = [];
if (hours > 0) {
parts.push(`${hours}h`);
}
if (minutes > 0) {
parts.push(`${minutes}m`);
}
if (secs > 0) {
parts.push(`${secs}s`);
}
return parts.join(', ') || '0 secondes';
}
const parseMPDStream = async (mpdUrl) => { const parseMPDStream = async (mpdUrl) => {
const mpdResponse = await axios({ const mpdResponse = await axios({
url: mpdUrl, url: mpdUrl,
@@ -404,7 +427,9 @@ const parseMPDStream = async (mpdUrl) => {
resolution: { resolution: {
width: parsedManifest.playlists?.[i]?.attributes?.RESOLUTION?.width, width: parsedManifest.playlists?.[i]?.attributes?.RESOLUTION?.width,
height: parsedManifest.playlists?.[i]?.attributes?.RESOLUTION?.height height: parsedManifest.playlists?.[i]?.attributes?.RESOLUTION?.height
} },
duration: parsedManifest.playlists?.[i]?.targetDuration,
formatedDuration: formatDuration(parsedManifest.playlists?.[i]?.targetDuration || 0)
}); });
} }
obj.videoTracks = obj.videoTracks.sort((a, b) => b.resolution.width - a.resolution.width); obj.videoTracks = obj.videoTracks.sort((a, b) => b.resolution.width - a.resolution.width);