correct application of playlists rules

This commit is contained in:
Gabriel Radureau
2025-10-16 17:18:58 +02:00
parent d2e2028610
commit 78313ffbef
17 changed files with 1098 additions and 247 deletions

View File

@@ -2,11 +2,49 @@
set -euo pipefail
IFS=$'\n\t'
# === Gestion des arguments ===
PROCESS_ALL=false
PRINT_ERR=false
# Fonction pour afficher l'aide
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"
exit 1
}
# Traitement des arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--all|-a)
PROCESS_ALL=true
shift
;;
--help|-h)
usage
;;
--print-err)
PRINT_ERR=true
shift
;;
*)
echo "Option inconnue : $1" >&2
usage
;;
esac
done
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"
# Initialiser le fichier temporaire
> "$TEMP_FILE"
sanitize_name() {
local name="$1"
@@ -17,6 +55,8 @@ sanitize_name() {
}
export -f sanitize_name
source $SCRIPTS_DIR/append_with_lock.sh
# Fonction pour vérifier et déplacer un fichier
check_and_move() {
local fichier="$1"
@@ -28,6 +68,9 @@ check_and_move() {
if [ "$taille1" -eq "$taille2" ] && [ "$taille2" -gt 0 ]; then
echo "Déplacement de $(basename "$fichier")"
rsync -av --remove-source-files "$fichier" "$DOSSIER_DESTINATION_RAW/$(sanitize_name "$(basename "$fichier")")"
if ! append_with_lock "$DOSSIER_DESTINATION_RAW/$(sanitize_name "$(basename "$fichier")")" "$TEMP_FILE"; then
echo "Échec de l'écriture dans $TEMP_FILE (timeout)" >&2
fi
else
echo "Fichier $(basename "$fichier") encore en cours de réception."
fi
@@ -90,6 +133,10 @@ process_raw_file() {
local ct weekday duration lat lon address
IFS="|" read -r ct weekday duration lat lon address <<<"$(process_video "$raw")"
# récupérer les infos eventuelles dans la BDD
# si fichier videos existent toujours ingorer, sinon écraser
# TODO
local dir=$(mp4_dir $raw $weekday "$address")
local thumbnail=${dir}/thumbnail.jpg
@@ -124,19 +171,53 @@ whatsapp_video() {
export -f whatsapp_video
convert_raws() {
if $PROCESS_ALL; then
# ##_##.mov
find "$DOSSIER_DESTINATION_RAW" -type f \
-name "*.mov" \
-print0 | parallel -0 -j 4 iphone_video
find "$DOSSIER_DESTINATION_RAW" -type f \
-name "*.mov" \
-print0 | parallel -0 -j 4 iphone_video
find "$DOSSIER_DESTINATION_RAW" -type f \
-name "screenrecording*.mp4" \
-print0 | parallel -0 -j 4 screen_video
find "$DOSSIER_DESTINATION_RAW" -type f \
-name "screenrecording*.mp4" \
-print0 | parallel -0 -j 4 screen_video
find "$DOSSIER_DESTINATION_RAW" -type f \
-name '*[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]*.mp4' \
-print0 | parallel -0 -j 4 whatsapp_video
find "$DOSSIER_DESTINATION_RAW" -type f \
-name '*[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]*.mp4' \
-print0 | parallel -0 -j 4 whatsapp_video
else
if [ -f "$TEMP_FILE" ]; then
while IFS= read -r file || [ -n "$file" ]; do
file=$(echo "$file" | tr -d '\r' | xargs)
# Ignorer les lignes vides
if [ -z "$file" ]; then
continue
fi
echo "Dealing with $file"
local filename=$(basename "$file")
if [[ "$filename" == *.mov ]]; then
iphone_video "$file"
elif [[ "$filename" == screenrecording*.mp4 ]]; then
screen_video "$file"
elif [[ "$filename" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.mp4$ ]]; then
whatsapp_video "$file"
else
echo "$file didn't match any pattern"
fi
done < "$TEMP_FILE"
fi
fi
}
convert_raws
$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
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)
fi