Fix relative to missing subtiles issue
All checks were successful
ci / Image build (push) Successful in 2m11s
ci / Deployment (push) Successful in 22s

This commit is contained in:
Joris Bertomeu
2025-08-25 14:48:59 +02:00
parent aba85207e7
commit fc8e9ebc48
2 changed files with 51 additions and 14 deletions

View File

@@ -334,9 +334,11 @@ const parseMPDStream = async (mpdUrl) => {
rootProp: 'SUBTITLES',
subProp: 'subs',
targetProp: 'subtitles'
}]
}];
toParse.forEach(({ rootProp, subProp, targetProp }) => {
try {
for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) {
for (let i = 0; i < value.playlists.length; i++) {
obj[targetProp].push({
@@ -346,6 +348,9 @@ const parseMPDStream = async (mpdUrl) => {
});
}
}
} catch(e) {
console.log(`No ${targetProp} found in manifest`);
}
});
for (let i = 0; i < parsedManifest.playlists.length; i++) {
obj.videoTracks.push({
@@ -374,7 +379,35 @@ app.post('/processMPD', async (req, res, next) => {
app.use((err, req, res, next) => {
res.status(500).json({ error: err.message || err.toString() || 'An error occured' });
})
});
const safeMove = async (source, destination) => {
try {
const destDir = path.dirname(destination);
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
fs.renameSync(source, destination);
console.log(`✓ Moved: ${path.basename(source)} -> ${destination}`);
} catch (error) {
if (error.code === 'EXDEV') {
console.log(`⚠️ Cross-device detected, copying: ${path.basename(source)}`);
fs.copyFileSync(source, destination);
fs.unlinkSync(source);
console.log(`✓ Copied: ${path.basename(source)} -> ${destination}`);
} else if (error.code === 'ENOENT') {
console.error(`❌ Source file not found: ${source}`);
throw new Error(`Source file not found: ${source}`);
} else {
console.error(`❌ Move failed:`, error);
throw error;
}
}
};
// Processus de la file d'attente
videoQueue.process((job) => {
@@ -464,11 +497,15 @@ videoQueue.process((job) => {
let counter = 1;
for (const file of subFiles) {
if (file.startsWith(`${mp4Filename}_encrypted`) && file.endsWith('.srt')) {
fs.renameSync(`${workdir}/${file}`, `${finalPath}/${mp4Filename}_${counter}.srt`);
const sourcePath = `${workdir}/${file}`;
const destPath = `${finalPath}/${mp4Filename}_${counter}.srt`;
await safeMove(sourcePath, destPath);
counter++;
}
}
// Nettoyage (commenté pour correspondre au script original)
await runCommand(`rm -fr ${workdir}`);

View File

@@ -9,11 +9,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.7.7",
"bull": "^4.16.4",
"cheerio": "^1.0.0",
"axios": "^1.11.0",
"bull": "^4.16.5",
"cheerio": "^1.1.2",
"cors": "^2.8.5",
"express": "^4.21.1",
"express": "^5.1.0",
"fs": "^0.0.1-security",
"mpd-parser": "^1.3.1",
"path": "^0.12.7",