Add duration
This commit is contained in:
27
index.js
27
index.js
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user