#!/bin/bash
# -----------------------
# CONFIGURATION
# -----------------------
HLS_DIR="/var/www/videos/hls"
TOKENS_DIR="/var/www/videos/hls_tokens"
OUTPUT_FILE="/var/www/html/iframes_embed.txt"
BASE_URL="https://videos.xslug.com"
# Crée le dossier tokens s'il n'existe pas
mkdir -p "$TOKENS_DIR"
# Fichier temporaire
TMP_FILE=$(mktemp)
# -----------------------
# FONCTION : IFRAME FIXE PAR VIDÉO
# -----------------------
generate_iframe_fixed() {
local key="$1"
# Hash MD5 basé sur le token → iframe unique mais fixe
local hash
hash=$(echo -n "$key" | md5sum | awk '{print $1}')
echo ""
}
# -----------------------
# PARCOURS DES DOSSIERS HLS
# -----------------------
for dir in "$HLS_DIR"/*; do
[ -d "$dir" ] || continue
folder=$(basename "$dir")
# Vérifie fichiers requis
if [[ ! -f "$dir/index.m3u8" || ! -f "$dir/trailer.mp4" || ! -f "$dir/thumbnail.jpg" ]]; then
echo "⚠️ Ignoré (fichiers manquants) : $folder"
continue
fi
# Cherche un token existant
token=""
for link in "$TOKENS_DIR"/*; do
[ -L "$link" ] || continue
target=$(readlink "$link")
if [[ "$target" == "$dir" ]]; then
token=$(basename "$link")
break
fi
done
# Si aucun token, en créer un
if [[ -z "$token" ]]; then
token=$(openssl rand -hex 32)
ln -s "$dir" "$TOKENS_DIR/$token"
echo "✅ Nouveau token créé pour $folder : $token"
fi
# Génère l'iframe fixe basé sur le token
iframe=$(generate_iframe_fixed "$token")
# Écrit dans le fichier temporaire
echo "$folder" >> "$TMP_FILE"
echo "$BASE_URL/hls_tokens/$token/trailer.mp4" >> "$TMP_FILE"
echo "$BASE_URL/hls_tokens/$token/thumbnail.jpg" >> "$TMP_FILE"
echo "$BASE_URL/hls_tokens/$token/index.m3u8" >> "$TMP_FILE"
echo "$iframe" >> "$TMP_FILE"
echo "" >> "$TMP_FILE"
done
# -----------------------
# REMPLACE L’ANCIEN FICHIER + FIX PERMISSIONS
# -----------------------
mv "$TMP_FILE" "$OUTPUT_FILE"
chown videosftp:videosftp "$OUTPUT_FILE"
chmod 644 "$OUTPUT_FILE"
echo "🎉 Fichier généré et permissions fixées : $OUTPUT_FILE"
Warning: Cannot modify header information - headers already sent by (output started at /home/xslugcom/public_html/wp-content/plugins/import-videos-html-2.php:1) in /home/xslugcom/public_html/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /home/xslugcom/public_html/wp-content/plugins/import-videos-html-2.php:1) in /home/xslugcom/public_html/wp-includes/pluggable.php on line 1453