Fix relative to missing subtiles issue
This commit is contained in:
43
index.js
43
index.js
@@ -334,9 +334,11 @@ 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 }) => {
|
||||||
|
try {
|
||||||
for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) {
|
for (const [key, value] of Object.entries(parsedManifest?.mediaGroups?.[rootProp]?.[subProp])) {
|
||||||
for (let i = 0; i < value.playlists.length; i++) {
|
for (let i = 0; i < value.playlists.length; i++) {
|
||||||
obj[targetProp].push({
|
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++) {
|
for (let i = 0; i < parsedManifest.playlists.length; i++) {
|
||||||
obj.videoTracks.push({
|
obj.videoTracks.push({
|
||||||
@@ -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}`);
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user