add movie compatibility
This commit is contained in:
parent
b0978b0a65
commit
fd0bb18304
@ -1,12 +1,12 @@
|
||||
#!/bin/bash -x
|
||||
#!/bin/bash
|
||||
|
||||
# ----------------------------------
|
||||
# Configuration des chemins et du fichier de log
|
||||
# ----------------------------------
|
||||
ORG_PATH="/home/**********/downloads/rtorrent"
|
||||
FINAL_PATH="/home/************"
|
||||
LOG_FILE="/home/**********/postprocess.log"
|
||||
BIN_PATH="/home/***********/bin"
|
||||
ORG_PATH="/home/************/downloads/rtorrent"
|
||||
FINAL_PATH="/home/***********"
|
||||
LOG_FILE="/home/*************/torrentend_debug.log"
|
||||
BIN_PATH="/home/************/bin"
|
||||
|
||||
# ----------------------------------
|
||||
# Couleurs pour l'affichage (facultatif)
|
||||
@ -41,13 +41,8 @@ log "DEBUT DE TRAITEMENT"
|
||||
# Nettoyage du répertoire : suppression des samples et renommage des espaces
|
||||
# ----------------------------------
|
||||
clean_dir() {
|
||||
local dir="$1"
|
||||
|
||||
# Supprime tous les répertoires ou fichiers avec "sample" (n'importe quelle casse)
|
||||
find "$dir" -maxdepth 1 -iname '*sample*' -exec rm -rf {} +
|
||||
|
||||
# Renommage des espaces
|
||||
rename 's/ /_/g' "$dir"/* 2>/dev/null || true
|
||||
rm -rf "${1}"/*sample*
|
||||
rename 's/ /_/g' "${1}"/* 2>/dev/null || true
|
||||
}
|
||||
|
||||
# ----------------------------------
|
||||
@ -79,11 +74,20 @@ sanitize_name() {
|
||||
local filename="$(basename "$filepath")"
|
||||
local ext="${filename##*.}"
|
||||
local name="${filename%.*}"
|
||||
# Si le nom de fichier est entièrement en minuscules, on utilise le dossier parent
|
||||
if [[ "$name" == "${name,,}" ]]; then
|
||||
|
||||
# Calculer le nombre d'espaces dans le nom
|
||||
local no_space
|
||||
no_space=$(printf '%s' "$name" | tr -d ' ')
|
||||
local space_count=$(( ${#name} - ${#no_space} ))
|
||||
|
||||
# Si le nom est entièrement en minuscules
|
||||
# OU contient au moins 2 espaces (pas forcément contigus),
|
||||
# on bascule sur le dossier parent
|
||||
if [[ "$name" == "${name,,}" ]] || (( space_count >= 2 )); then
|
||||
local parent="$(basename "$(dirname "$filepath")")"
|
||||
name="$(remove_accents "$parent")"
|
||||
fi
|
||||
|
||||
# Translit accents
|
||||
name="$(remove_accents "$name")"
|
||||
# Normalisation des séparateurs
|
||||
@ -94,27 +98,49 @@ sanitize_name() {
|
||||
local total=${#parts[@]}
|
||||
local keep=()
|
||||
local i j k
|
||||
local marker_index=-1
|
||||
local pattern
|
||||
|
||||
# Parcours des segments pour trouver e.g. S01E02
|
||||
for ((i=0;i<total;i++)); do
|
||||
keep+=("${parts[i]}")
|
||||
if [[ ${parts[i]} =~ ^[Ss][0-9]{2}[Ee][0-9]{2}$ ]]; then
|
||||
# trouver marqueur qualite/langue
|
||||
for ((j=i+1;j<total;j++)); do
|
||||
tag="${parts[j]^^}"
|
||||
if [[ "$tag" =~ ^(REPACK|PROPER|INTERNAL|FINAL|SUBFRENCH|TRUEFRENCH|FRENCH|MULTI|VOSTFR)$ ]] || [[ "$tag" =~ ^[0-9]{3,4}P$ ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
# conserver la suite
|
||||
for ((k=j;k<total;k++)); do
|
||||
keep+=("${parts[k]}")
|
||||
done
|
||||
# --- 1) d'abord, on regarde si on a un SxxEyy quelque part ---
|
||||
for ((i=0; i<total; i++)); do
|
||||
if [[ "${parts[i]}" =~ ^[Ss][0-9]{2}[Ee][0-9]{2}$ ]]; then
|
||||
marker_index=$i
|
||||
pattern='^[Ss][0-9]{2}[Ee][0-9]{2}$'
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# construire base nettoyée
|
||||
# --- 2) si pas de série, on cherche une année (film) ---
|
||||
if (( marker_index < 0 )); then
|
||||
for ((i=0; i<total; i++)); do
|
||||
if [[ "${parts[i]}" =~ ^(19|20)[0-9]{2}$ ]]; then
|
||||
marker_index=$i
|
||||
pattern='^(19|20)[0-9]{2}$'
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# --- 3) si on a trouvé un marqueur, on construit keep[] ---
|
||||
if (( marker_index >= 0 )); then
|
||||
# on garde tout jusqu'au marqueur inclus
|
||||
keep=("${parts[@]:0:marker_index+1}")
|
||||
# on cherche ensuite le premier tag qualité/langue
|
||||
for ((j=marker_index+1; j<total; j++)); do
|
||||
tag="${parts[j]^^}"
|
||||
if [[ "$tag" =~ ^(REPACK|PROPER|INTERNAL|FINAL|SUBFRENCH|TRUEFRENCH|FRENCH|MULTI|VOSTFR)$ ]] \
|
||||
|| [[ "$tag" =~ ^[0-9]{3,4}P$ ]]; then
|
||||
# on ajoute tout à partir de ce tag
|
||||
keep+=("${parts[@]:j}")
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
# si pas de marqueur du tout, on garde tout
|
||||
keep=("${parts[@]}")
|
||||
fi
|
||||
|
||||
# reconstruire la base nettoyée
|
||||
local out
|
||||
out=$(IFS='.'; echo "${keep[*]}")
|
||||
|
||||
@ -126,17 +152,18 @@ sanitize_name() {
|
||||
out=${out//.MULTI./.MULTi.}
|
||||
out=${out//.FINAL./.FiNAL.}
|
||||
out=${out//.INTERNAL./.iNTERNAL.}
|
||||
|
||||
|
||||
# Préfixe du dernier segment par un tiret uniquement si aucune autre tiret interne
|
||||
local last="${out##*.}"
|
||||
if [[ "$last" != *-* ]]; then
|
||||
out="${out%.*}-$last"
|
||||
fi
|
||||
|
||||
|
||||
# Ajout de l'extension
|
||||
printf "%s.%s" "$out" "$ext"
|
||||
}
|
||||
|
||||
|
||||
# ----------------------------------
|
||||
# Traitement des .mkv uniquement
|
||||
# ----------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user