Remplacement de analyzer.php par analyzer.sh permet de retirer la dependances à php et de passer en full bash
This commit is contained in:
parent
437932dacd
commit
1bba50c678
@ -1,130 +0,0 @@
|
||||
<?php
|
||||
function formatBytesnzb($size, $precision = 2) {
|
||||
$base = log($size, 1024);
|
||||
$suffixes = array('', 'Ko', 'Mo', 'Go', 'To');
|
||||
return round(pow(1024, $base - floor($base)), $precision) . ' ' . $suffixes[floor($base)];
|
||||
}
|
||||
|
||||
// Charger le fichier NZB
|
||||
$nzbFilePath = $argv[1];
|
||||
if (!file_exists($nzbFilePath)) {
|
||||
die('Fichier NZB non trouvé.');
|
||||
}
|
||||
|
||||
// Charger le contenu du fichier NZB
|
||||
$xmlContent = file_get_contents($nzbFilePath);
|
||||
if ($xmlContent === false) {
|
||||
die('Impossible de lire le fichier NZB.');
|
||||
}
|
||||
|
||||
// Vérifier si le fichier contient <meta type="password"> pour choisir la méthode d'analyse
|
||||
if (strpos($xmlContent, '<meta type="password">') !== false) {
|
||||
// Analyse via Regex (approche nzbanal.php)
|
||||
$rename = '/"(.*?).par2/';
|
||||
preg_match($rename, $xmlContent, $matchesname);
|
||||
$ngname = $matchesname[1];
|
||||
|
||||
if (empty($ngname)) {
|
||||
$rename = '/subject="(.*?).par2/';
|
||||
preg_match($rename, $xmlContent, $matchesname);
|
||||
$ngname = $matchesname[1];
|
||||
}
|
||||
|
||||
// Récupération du mot de passe
|
||||
$repass = '/<meta type="password">(.*?)<\/meta>/';
|
||||
preg_match($repass, $xmlContent, $matchespass);
|
||||
$password = $matchespass[1];
|
||||
|
||||
// Récupération de la date
|
||||
$redate = '/date="(.*?)"/';
|
||||
preg_match($redate, $xmlContent, $matchesdate);
|
||||
$update = $matchesdate[1];
|
||||
$update = date('d/m/Y', $update);
|
||||
|
||||
// Calcul de la taille des fichiers RAR/ISO/MKV/MP4
|
||||
$regexsize = '/(rar|iso|mkv|mp4).*\(\d+\/\d+\) (\d+)/';
|
||||
preg_match_all($regexsize, $xmlContent, $matchessize, PREG_PATTERN_ORDER, 0);
|
||||
|
||||
$filesize = formatBytesnzb(array_sum($matchessize[2]));
|
||||
|
||||
// Extraction des groupes
|
||||
$regroup = '/<group>(.*?)<\/group>/';
|
||||
preg_match_all($regroup, $xmlContent, $matchesgroup, PREG_PATTERN_ORDER, 0);
|
||||
$resultgroup = array_unique($matchesgroup[1]);
|
||||
|
||||
$GROUP = '';
|
||||
$i = '0';
|
||||
foreach ($resultgroup as $group) {
|
||||
$GROUP .= $group;
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Création de l'objet JSON pour cette approche
|
||||
$myObj = new stdClass();
|
||||
$myObj->Name = $ngname;
|
||||
$myObj->Pass = $password;
|
||||
$myObj->Date = $update;
|
||||
$myObj->Groupes = $GROUP;
|
||||
$myObj->Taille = $filesize;
|
||||
$myObj->Taillebit = array_sum($matchessize[2]);
|
||||
|
||||
$myJSON = json_encode($myObj);
|
||||
echo $myJSON;
|
||||
} else {
|
||||
// Analyse via XML (approche nzbanal_obs.php)
|
||||
$password = 'Aucun';
|
||||
$xml = @simplexml_load_string($xmlContent, null, 0, "http://www.newzbin.com/DTD/2003/nzb");
|
||||
|
||||
if ($xml === false) {
|
||||
die('Erreur lors de l\'analyse du fichier NZB en tant que XML.');
|
||||
}
|
||||
|
||||
$maxSegmentsFile = null;
|
||||
$maxSegmentsCount = 0;
|
||||
|
||||
foreach ($xml->file as $file) {
|
||||
$fileName = (string)$file->attributes()->subject;
|
||||
$fileDate = (string)$file->attributes()->date;
|
||||
$fileGroups = [];
|
||||
$totalSize = 0;
|
||||
$segmentCount = 0;
|
||||
|
||||
foreach ($file->groups->group as $group) {
|
||||
$fileGroups[] = (string)$group;
|
||||
}
|
||||
|
||||
foreach ($file->segments->segment as $segment) {
|
||||
$segmentSize = (int)$segment->attributes()->bytes;
|
||||
$totalSize += $segmentSize;
|
||||
$segmentCount++;
|
||||
}
|
||||
|
||||
if ($segmentCount > $maxSegmentsCount) {
|
||||
$maxSegmentsCount = $segmentCount;
|
||||
$maxSegmentsFile = [
|
||||
'name' => $fileName,
|
||||
'date' => $fileDate,
|
||||
'groups' => $fileGroups,
|
||||
'total_size' => $totalSize,
|
||||
'segment_count' => $segmentCount
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($maxSegmentsFile) {
|
||||
$myObj = new stdClass();
|
||||
$myObj->Name = $maxSegmentsFile['name'];
|
||||
$myObj->Pass = $password;
|
||||
$myObj->Date = date('Y-m-d H:i:s', (int)$maxSegmentsFile['date']);
|
||||
$myObj->Groupes = implode(', ', $maxSegmentsFile['groups']);
|
||||
$myObj->Taille = formatBytesnzb($maxSegmentsFile['total_size']);
|
||||
$myObj->Taillebit = $maxSegmentsFile['total_size'];
|
||||
|
||||
$myJSON = json_encode($myObj);
|
||||
echo $myJSON;
|
||||
} else {
|
||||
echo "Aucun fichier trouvé dans le NZB.
|
||||
";
|
||||
}
|
||||
}
|
||||
?>
|
||||
73
autopost/analyzer.sh
Executable file
73
autopost/analyzer.sh
Executable file
@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
# Vérification de la présence d'un argument
|
||||
if [ "$#" -lt 1 ]; then
|
||||
echo "Usage: $0 fichier.nzb" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nzbFilePath="$1"
|
||||
if [ ! -f "$nzbFilePath" ]; then
|
||||
echo "Fichier NZB non trouvé." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Fonction de formatage de taille en octets (avec unités)
|
||||
format_bytes() {
|
||||
size="$1"
|
||||
precision="${2:-2}"
|
||||
if [ "$size" -eq 0 ]; then
|
||||
echo "0"
|
||||
return
|
||||
fi
|
||||
# Calcul avec awk pour afficher la taille en Ko, Mo, Go, etc.
|
||||
awk -v size="$size" -v prec="$precision" 'BEGIN {
|
||||
suffixes[0] = "";
|
||||
suffixes[1] = "Ko";
|
||||
suffixes[2] = "Mo";
|
||||
suffixes[3] = "Go";
|
||||
suffixes[4] = "To";
|
||||
base = log(size)/log(1024);
|
||||
i = int(base);
|
||||
value = exp((base - i)*log(1024));
|
||||
format = "%." prec "f %s";
|
||||
printf format, value, suffixes[i];
|
||||
}'
|
||||
}
|
||||
|
||||
# Extraction du nom (ngname)
|
||||
# On essaie d'abord avec le motif " ... .par2, puis avec subject=" ... .par2
|
||||
ngname=$(grep -Po '"\K.*?(?=\.par2)' "$nzbFilePath" | head -n 1)
|
||||
if [ -z "$ngname" ]; then
|
||||
ngname=$(grep -Po 'subject="\K.*?(?=\.par2)' "$nzbFilePath" | head -n 1)
|
||||
fi
|
||||
|
||||
# Extraction du mot de passe
|
||||
password=$(grep -Po '<meta type="password">\K.*?(?=</meta>)' "$nzbFilePath" | head -n 1)
|
||||
|
||||
# Extraction de la date (en supposant un timestamp Unix dans l'attribut date)
|
||||
timestamp=$(grep -Po 'date="\K\d+' "$nzbFilePath" | head -n 1)
|
||||
if [ -n "$timestamp" ]; then
|
||||
# Format "YYYY-MM-DD HH:MM:SS"
|
||||
update=$(date -d @"$timestamp" +"%Y-%m-%d %H:%M:%S")
|
||||
else
|
||||
update=""
|
||||
fi
|
||||
|
||||
# Calcul de la taille totale en additionnant les valeurs des attributs "bytes" de chaque balise <segment>
|
||||
sizes=$(grep -Po '<segment bytes="\K\d+' "$nzbFilePath")
|
||||
totalSize=0
|
||||
if [ -n "$sizes" ]; then
|
||||
totalSize=$(echo "$sizes" | awk '{sum+=$1} END {printf "%.0f", sum}')
|
||||
fi
|
||||
filesize=$(format_bytes "$totalSize")
|
||||
|
||||
# Extraction et concaténation des groupes (uniques)
|
||||
groups=$(grep -Po '<group>\K.*?(?=</group>)' "$nzbFilePath")
|
||||
GROUP=$(echo "$groups" | sort -u | paste -sd "" -)
|
||||
|
||||
# Création de l'objet JSON
|
||||
# Attention : cette méthode simple avec printf ne gère pas l'échappement complet des caractères spéciaux
|
||||
json=$(printf '{"Name":"%s", "Pass":"%s", "Date":"%s", "Groupes":"%s", "Taille":"%s", "Taillebit":%s}' \
|
||||
"$ngname" "$password" "$update" "$GROUP" "$filesize" "$totalSize")
|
||||
|
||||
echo "$json"
|
||||
@ -1,6 +1,11 @@
|
||||
#!/bin/bash
|
||||
source /home/$USER/autopost/conf.sh
|
||||
|
||||
#CONFIG GLOBAL
|
||||
SCREEN_NAME="autopost"
|
||||
SCRIPT_PATH="/home/$USER/autopost/posteur.sh"
|
||||
ANALYZER="/home/$USER/autopost/analyzer.sh"
|
||||
|
||||
# Couleurs de texte
|
||||
NOIR='\e[30m'
|
||||
ROUGE='\e[31m'
|
||||
|
||||
@ -9,11 +9,6 @@ DOSSIER_LOGS="/home/$USER/autopost/logs/"
|
||||
DOSSIER_NZB_ATTENTE="/home/$USER/ATTENTE/"
|
||||
DOSSIER_NZB_FINAL="/home/$USER/FINIS/"
|
||||
|
||||
#CONFIG GLOBAL
|
||||
SCREEN_NAME="autopost"
|
||||
SCRIPT_PATH="/home/$USER/autopost/posteur.sh"
|
||||
ANALYZER="/home/$USER/autopost/analyzer.php"
|
||||
|
||||
#CONFIG FOURNISSEUR USENET DE POST
|
||||
NG_HOST=""
|
||||
NG_PORT=""
|
||||
|
||||
@ -46,7 +46,7 @@ if command -v mediainfo > /dev/null 2>&1; then
|
||||
else
|
||||
echo -e "${ROUGE}mediainfo est manquant. Installation en cours...${NORMAL}"
|
||||
curl -L -o "$BIN_DIR/mediainfo" "https://mediaarea.net/download/binary/mediainfo/20.09/mediainfo-20.09.glibc2.3-x86_64.AppImage"
|
||||
chmod +x "$BIN_DIR/mediainfo"
|
||||
chmod 777 "$BIN_DIR/mediainfo"
|
||||
LISTE_APPLIS+=("$BIN_DIR/mediainfo")
|
||||
echo -e "${VERT}mediainfo installé dans $BIN_DIR${NORMAL}"
|
||||
fi
|
||||
@ -61,7 +61,7 @@ else
|
||||
|
||||
# Recherche et déplacement du binaire sqlite3 uniquement
|
||||
find "$BIN_DIR" -type f -name "sqlite3" -exec mv {} "$BIN_DIR/sqlite3" \;
|
||||
chmod +x "$BIN_DIR/sqlite3"
|
||||
chmod 777 "$BIN_DIR/sqlite3"
|
||||
|
||||
# Nettoyage des fichiers inutiles
|
||||
rm -rf sqlite-tools.zip "$BIN_DIR/sqlite-tools-linux-x64-3480000" "$BIN_DIR/sqldiff" "$BIN_DIR/sqlite3_analyzer" "$BIN_DIR/sqlite3_rsync"
|
||||
@ -76,7 +76,7 @@ if command -v jq > /dev/null 2>&1; then
|
||||
else
|
||||
echo -e "${ROUGE}jq est manquant. Installation en cours...${NORMAL}"
|
||||
curl -L -o "$BIN_DIR/jq" "https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64"
|
||||
chmod +x "$BIN_DIR/jq"
|
||||
chmod 777 "$BIN_DIR/jq"
|
||||
LISTE_APPLIS+=("$BIN_DIR/jq")
|
||||
echo -e "${VERT}jq installé dans $BIN_DIR${NORMAL}"
|
||||
fi
|
||||
@ -113,7 +113,7 @@ echo -e "$BLEU""Téléchargement de autopost""$NORMAL"
|
||||
mkdir -p "$AUTOPOST_DIR"
|
||||
|
||||
# Télécharger les fichiers dans autopost
|
||||
wget -q -O "$AUTOPOST_DIR/analyzer.php" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.php"
|
||||
wget -q -O "$AUTOPOST_DIR/analyzer.php" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh"
|
||||
wget -q -O "$AUTOPOST_DIR/common.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh"
|
||||
wget -q -O "$AUTOPOST_DIR/posteur.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user