Give alias and random suffix for whatsapp videos without created timestamp

This commit is contained in:
Gabriel Radureau
2025-10-16 17:28:26 +02:00
parent 78313ffbef
commit fbe3c01de7
10 changed files with 131 additions and 25 deletions

View File

@@ -10,8 +10,9 @@ PRINT_ERR=false
usage() {
echo "Usage: $0 [--all|-a]"
echo "Options:"
echo " --all, -a Traiter tous les fichiers (ignore la liste de fichiers)"
echo " --help, -h Afficher cette aide"
echo " --all, -a Traiter tous les fichiers (ignore la liste de fichiers)"
echo " --help, -h Afficher cette aide"
echo " --print-err, -e Afficher les erreurs en stderr et non dans le fichier de logs"
exit 1
}
@@ -25,7 +26,7 @@ while [[ $# -gt 0 ]]; do
--help|-h)
usage
;;
--print-err)
--print-err|-e)
PRINT_ERR=true
shift
;;
@@ -41,7 +42,7 @@ SCRIPTS_DIR=$(dirname `realpath ${BASH_SOURCE[0]}`)
# === CONFIGURATION ===
export DOSSIER_SOURCE="${HOME}/Downloads"
export DOSSIER_DESTINATION_RAW="${HOME}/Documents/.DanceVideos/raw"
export TEMP_FILE="/tmp/dancevideos_moved_files.txt"
export TEMP_FILE="/tmp/dancevideos_moved_files_$RANDOM.txt"
# Initialiser le fichier temporaire
> "$TEMP_FILE"
@@ -108,7 +109,6 @@ mp4_dir() {
local dir=$DOSSIER_DESTINATION_MP4
dir=$dir/$(date -jf "%Y-%m-%dT%H:%M:%S" "$(get_creation_time $raw)" +%Y%m%d_%H%M%S)
dir=${dir}_${weekday}_${address}
mkdir -p $dir
echo $dir
}
export -f mp4_dir
@@ -127,8 +127,42 @@ write_mp4() {
}
export -f write_mp4
generate_funny_suffix() {
local file="$1"
# Grande liste de suffixes uniques et lisibles
local funny_names=(
"pamplemousse" "canard" "yolo" "flan" "tortue" "biscotte" "poney" "baguette"
"chaussette" "banane" "hippopotame" "tuba" "bretzel" "chocolatine" "carambar"
"frometon" "krokmou" "gnocchi" "clafoutis" "capybara" "choubidou" "pingouin"
"maracas" "raclette" "saucisson" "pistache" "chamallow" "boomerang" "pirouette"
"moustache" "abricot" "falafel" "pouet" "zouzou" "cornichon" "gnouf" "mouette"
"paprika" "crouton" "galipette" "gratin" "pouliche" "brocoli" "nugget"
)
# Calcul du hash MD5 compatible macOS
local hash_val
hash_val=$(md5 -q "$file" 2>/dev/null)
# Fallback si le hash échoue (ex: fichier non lisible)
if [[ -z "$hash_val" ]]; then
echo "default"
return
fi
# Extraire les 8 derniers caractères hexadécimaux pour faire un modulo fiable
local short_hex="${hash_val: -8}"
# Convertir en entier et choisir un mot dans la liste
local index=$(( 0x$short_hex % ${#funny_names[@]} ))
echo "${funny_names[$index]}"
}
export -f generate_funny_suffix
process_raw_file() {
local raw="$1"
local dir_suffixe="${2:-}"
local ct weekday duration lat lon address
IFS="|" read -r ct weekday duration lat lon address <<<"$(process_video "$raw")"
@@ -138,6 +172,8 @@ process_raw_file() {
# TODO
local dir=$(mp4_dir $raw $weekday "$address")
[ -n "$dir_suffixe" ] && dir=${dir}_${dir_suffixe} || :
mkdir -p $dir
local thumbnail=${dir}/thumbnail.jpg
$(write_thumbnail $raw $thumbnail)
@@ -166,7 +202,8 @@ export -f screen_video
whatsapp_video() {
local raw="$1"
echo whatsapp $raw
process_raw_file $raw
local suffixe=$(generate_funny_suffix $raw)
process_raw_file $raw $suffixe
}
export -f whatsapp_video
@@ -215,9 +252,17 @@ $PRINT_ERR || exec 2> /tmp/DanceVideos.stderr
convert_raws
set -x
if [ 0 -lt $(wc -l /tmp/dancevideos_moved_files.txt | awk '{print $1}') ]; then
if [ 0 -lt $(wc -l $TEMP_FILE | awk '{print $1}') ]; then
STREAMLIT_PID=$(ps aux | grep streamlit | grep -v 'grep' | awk '{print $2}'); [ ! -z "$STREAMLIT_PID" ] && kill $STREAMLIT_PID
(cd $SCRIPTS_DIR/..; source .venv/bin/activate; streamlit run app/app.py -- --unlabeled)
set +o pipefail
STREAMLIT_PID="$(ps aux | grep streamlit | grep -v 'grep' | awk '{print $2}')"
set -o pipefail
if [ ! -z "$STREAMLIT_PID" ]; then
kill $STREAMLIT_PID
fi
# (cd $SCRIPTS_DIR/..; source .venv/bin/activate; streamlit run app/app.py -- --unlabeled &)
ROOT=$(realpath $SCRIPTS_DIR/..)
source $ROOT/.venv/bin/activate
streamlit run $ROOT/app/app.py -- --unlabeled &
fi