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,17 +334,22 @@ const parseMPDStream = async (mpdUrl) => {
rootProp: 'SUBTITLES', rootProp: 'SUBTITLES',
subProp: 'subs', subProp: 'subs',
targetProp: 'subtitles' targetProp: 'subtitles'
}] }];
toParse.forEach(({ rootProp, subProp, targetProp }) => { toParse.forEach(({ rootProp, subProp, targetProp }) => {
for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) { try {
for (let i = 0; i < value.playlists.length; i++) { for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) {
obj[targetProp].push({ for (let i = 0; i < value.playlists.length; i++) {
name: key, obj[targetProp].push({
language: value.language, name: key,
attributes: value.playlists[i].attributes language: value.language,
}); attributes: value.playlists[i].attributes
});
}
} }
} catch(e) {
console.log(`No ${targetProp} found in manifest`);
} }
}); });
for (let i = 0; i < parsedManifest.playlists.length; i++) { for (let i = 0; i < parsedManifest.playlists.length; i++) {
@@ -374,7 +379,35 @@ app.post('/processMPD', async (req, res, next) => {
app.use((err, req, res, next) => { app.use((err, req, res, next) => {
res.status(500).json({ error: err.message || err.toString() || 'An error occured' }); 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 // Processus de la file d'attente
videoQueue.process((job) => { videoQueue.process((job) => {
@@ -464,11 +497,15 @@ videoQueue.process((job) => {
let counter = 1; let counter = 1;
for (const file of subFiles) { for (const file of subFiles) {
if (file.startsWith(`${mp4Filename}_encrypted`) && file.endsWith('.srt')) { 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++; counter++;
} }
} }
// Nettoyage (commenté pour correspondre au script original) // Nettoyage (commenté pour correspondre au script original)
await runCommand(`rm -fr ${workdir}`); await runCommand(`rm -fr ${workdir}`);

View File

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