Fix relative to missing subtiles issue
This commit is contained in:
57
index.js
57
index.js
@@ -334,17 +334,22 @@ const parseMPDStream = async (mpdUrl) => {
|
||||
rootProp: 'SUBTITLES',
|
||||
subProp: 'subs',
|
||||
targetProp: 'subtitles'
|
||||
}]
|
||||
}];
|
||||
|
||||
|
||||
toParse.forEach(({ rootProp, subProp, targetProp }) => {
|
||||
for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) {
|
||||
for (let i = 0; i < value.playlists.length; i++) {
|
||||
obj[targetProp].push({
|
||||
name: key,
|
||||
language: value.language,
|
||||
attributes: value.playlists[i].attributes
|
||||
});
|
||||
try {
|
||||
for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) {
|
||||
for (let i = 0; i < value.playlists.length; i++) {
|
||||
obj[targetProp].push({
|
||||
name: key,
|
||||
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++) {
|
||||
@@ -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}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user