1
0

envoi du script

This commit is contained in:
unfr
2025-02-01 22:23:51 +01:00
parent 189450fa23
commit dfcf1a5799
7 changed files with 711 additions and 0 deletions

130
autopost/analyzer.php Normal file
View File

@@ -0,0 +1,130 @@
<?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 = '/&quot;(.*?).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.
";
}
}
?>

29
autopost/common.sh Normal file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
source /home/$USER/autopost/conf.sh
# Couleurs de texte
NOIR='\e[30m'
ROUGE='\e[31m'
VERT='\e[32m'
JAUNE='\e[33m'
BLEU='\e[34m'
ROSE='\e[35m'
CYAN='\e[36m'
BLANC='\e[37m'
# Couleurs de fond
FOND_NOIR='\e[40m'
FOND_ROUGE='\e[41m'
FOND_VERT='\e[42m'
FOND_JAUNE='\e[43m'
FOND_BLEU='\e[44m'
FOND_ROSE='\e[45m'
FOND_CYAN='\e[46m'
FOND_BLANC='\e[47m'
# Effets
GRAS='\e[1m'
SOULIGNE='\e[4m'
CLIGNOTANT='\e[5m'
INVERSE='\e[7m'
NORMAL='\e[0m'

24
autopost/conf.sh Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
#CONFIG A MODIF
URL_API="A NOUS DEMANDER SUR DISCORD"
APIKEY="A RETROUVER DANS VOTRE PROFIL"
DB_FILE="/home/$USER/autopost/base_autopost.db"
DOSSIER_GLOBAL="/home/$USER/"
DOSSIER_NFO="/home/$USER/autopost/mediainfo/"
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=""
NG_USER=""
NG_PASS=""
NG_NBR_CONN=""

77
autopost/posteur.sh Normal file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
source /home/$USER/autopost/common.sh
# Vérification et création des dossiers
for dossier in "$DOSSIER_NFO" "$DOSSIER_NZB_ATTENTE" "$DOSSIER_NZB_FINAL"
do
if [ ! -d "$dossier" ]; then
echo -e "${ROUGE} Le dossier $dossier n'existe pas. Création... ${NORMAL}"
mkdir -p "$dossier"
fi
done
attente() {
for ((i=$1; i>0; i--)); do
echo -ne "Attente : $i secondes\r"
sleep 1
done
}
checkusenet(){
SERVICE="nyuu"
if pgrep -x "$SERVICE" >/dev/null
then
echo "$SERVICE EN COURS"
sleep 16
else
echo "$SERVICE OK"
fi
}
while true
do
verif=$(sqlite3 $DB_FILE "SELECT COUNT(ID) FROM release WHERE status = 0")
if [ $verif -ge 1 ]; then
verif=$(sqlite3 $DB_FILE "SELECT * FROM release WHERE status = '0' LIMIT 1")
id=$(echo $verif | awk -F "|" '{ print $1 }' | sed 's/^[ \t]*//;s/[ \t]*$//')
name=$(echo $verif | awk -F "|" '{ print $2 }' | sed 's/^[ \t]*//;s/[ \t]*$//')
FILESANSEXT=${name%.*}
echo -e ${VERT}"DEBUT DE TRAITEMENT DE" ${FILESANSEXT}${NORMAL}
echo -e ${CYAN}"CREATION DES PAR2"${NORMAL}
parpar -s10M -r20%+2 -m4096M -p1l -o ${FILESANSEXT}.par2 ${name}
echo -e ${VERT}"UPLOAD SUR USENET" ${NORMAL}
checkusenet
nyuu -h ${NG_HOST} -P ${NG_PORT} -S -u ${NG_USER} -p ${NG_PASS} -n ${NG_NBR_CONN} -g alt.binaries.boneless -o "{fnamebase}.nzb" --nzb-title "${FILESANSEXT}" -f "{rand(14)} {rand(14)}@{rand(5)}.{rand(3)}" --message-id "{rand(32)}@{rand(8)}.{rand(3)}" --subject "{rand(32)}" --nzb-subject "{filename}" --obfuscate-articles ${FILESANSEXT}.*
mv ${FILESANSEXT}.nzb ${DOSSIER_NZB_ATTENTE}
if [ -e "${DOSSIER_NFO}""${FILESANSEXT}".json ]; then
echo -e ${JAUNE}"VERIF DU NZB"${NORMAL}
nzbsizebit=$(php ${ANALYZER} ${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb | jq '.Taillebit')
echo -e "NZB_SIZE :"${nzbsizebit}
jsonsizebit=$(cat ${DOSSIER_NFO}${FILESANSEXT}.json | jq -r '.media.track[] | select(.["@type"] == "General") | .FileSize')
echo -e "MEDIAINFO_SIZE :"${jsonsizebit}
if [[ ${nzbsizebit} -le ${jsonsizebit} ]] || [[ ${nzbsizebit} = "NAN" ]]; then
echo -e "$ROUGE""PROBLEME TAILLE NZB""$NORMAL"
rm ${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb ${FILESANSEXT}.par2 ${FILESANSEXT}.vol*
sqlite3 $DB_FILE "UPDATE release SET status = '2' WHERE id = ${id}"
else
echo -e ${CYAN}"ENVOI SUR LE SITE"${NORMAL}
curl -s -k -L -m 60 --output /dev/null -F rlsname=${FILESANSEXT} -F generated_nfo_json=@${DOSSIER_NFO}${FILESANSEXT}.json -F nzb=@${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb -F upload=upload "${URL_API}${APIKEY}"
first_char=$(echo "${name:0:1}" | tr '[:lower:]' '[:upper:]')
if [ ! -d ${DOSSIER_NZB_FINAL}${first_char} ]; then
mkdir ${DOSSIER_NZB_FINAL}${first_char}
fi
mv ${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb ${DOSSIER_NZB_FINAL}${first_char}/
rm -rf ${FILESANSEXT}*
#rm ${DOSSIER_NFO}${FILESANSEXT}.json
sqlite3 $DB_FILE "UPDATE release SET status = '1' WHERE id = ${id}"
echo -e ${VERT}"FIN DE TRAITEMENT DE" ${FILESANSEXT}${NORMAL}
fi
else
echo -e ${ROUGE}"ENVOI SUR LE SITE IMPOSSIBLE NFO MANQUANT"${NORMAL}
fi
fi
attente 10 # Attente de 10 secondes
done