1
0

Compare commits

..

3 Commits

2 changed files with 41 additions and 15 deletions

View File

@ -69,7 +69,11 @@ while true; do
echo -e "${JAUNE}VERIF DU NZB${NORMAL}"
nzbsizebit=$(bash ${ANALYZER} "${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb" | jq '.Taillebit')
echo -e "NZB_SIZE : ${nzbsizebit}"
if [[ "${name}" =~ \.(iso)$ ]]; then
jsonsizebit=$(du -b -c "${name}" | grep total | awk '{ print $1 }')
else
jsonsizebit=$(jq -r '.media.track[] | select(."@type" == "General") | .FileSize' "${DOSSIER_NFO}${FILESANSEXT}.json")
fi
echo -e "MEDIAINFO_SIZE : ${jsonsizebit}"
if [[ ${nzbsizebit} -le ${jsonsizebit} ]] || [[ ${nzbsizebit} = "NAN" ]]; then

View File

@ -178,7 +178,7 @@ autopostRouter.get('/', async (req, res) => {
? ' | <a href="#" class="log-link text-blue-400 hover:underline" data-filename="'+row.nom+'">Log</a>'
: '';
let mediainfoLink = (parseInt(row.status) === 0 || parseInt(row.status) === 1 || parseInt(row.status) === 2)
? ' | <a href="#" class="mediainfo-link text-blue-400 hover:underline" data-filename="'+row.nom+'">Mediainfo</a>'
? ' | <a href="#" class="mediainfo-link text-blue-400 hover:underline" data-filename="'+row.nom+'">MediaInfo/BDInfo</a>'
: '';
let dlLink = row.status === 1
? ` | <a href="/autopost/dl?name=${encodeURIComponent(row.nom)}" class="dl-link text-blue-400 hover:underline">DL</a>`
@ -490,13 +490,34 @@ autopostRouter.get('/mediainfo', (req, res) => {
if (!filename) {
return res.status(400).json({ error: "Nom du fichier non spécifié." });
}
let base = filename.includes('.') ? filename.split('.').slice(0, -1).join('.') : filename;
const mediainfoFilePath = path.join(config.infodirectory, base + '.json');
fs.readFile(mediainfoFilePath, 'utf8', (err, data) => {
const base = filename.includes('.') ? filename.split('.').slice(0, -1).join('.') : filename;
const jsonPath = path.join(config.infodirectory, base + '.json');
const bdinfoPath = path.join(config.infodirectory, base + '.bdinfo.txt');
// Vérifie lequel des deux existe, priorité au .json
fs.access(jsonPath, fs.constants.F_OK, (errJson) => {
if (!errJson) {
// .json existe
readAndSend(jsonPath);
} else {
// .json n'existe pas, on essaie .bdinfo.txt
fs.access(bdinfoPath, fs.constants.F_OK, (errBdinfo) => {
if (!errBdinfo) {
readAndSend(bdinfoPath);
} else {
res.status(404).json({ error: "Aucun fichier mediainfo trouvé." });
}
});
}
});
function readAndSend(filePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(err.message);
return res.status(500).json({ error: "Erreur lors du chargement du fichier mediainfo." });
}
// Essaie de prettifier si JSON
try {
const obj = JSON.parse(data);
const pretty = JSON.stringify(obj, null, 2);
@ -505,6 +526,7 @@ autopostRouter.get('/mediainfo', (req, res) => {
res.json({ content: data });
}
});
}
});
// --------------------------- Download -----------------------------