suppression de vidéos
This commit is contained in:
@@ -11,6 +11,10 @@ def get_conn():
|
|||||||
conn.execute("PRAGMA foreign_keys = ON;")
|
conn.execute("PRAGMA foreign_keys = ON;")
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
def delete_video(file_name):
|
||||||
|
with get_conn() as conn:
|
||||||
|
conn.execute("DELETE FROM videos WHERE file_name = ?", (file_name,))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
def load_videos():
|
def load_videos():
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# video_views.py
|
# video_views.py
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
import db
|
import db
|
||||||
from models import Video
|
from models import Video
|
||||||
@@ -51,15 +52,25 @@ def show_video_row(
|
|||||||
|
|
||||||
st.caption(video.file_name or video.mp4_file_name)
|
st.caption(video.file_name or video.mp4_file_name)
|
||||||
|
|
||||||
c1, c2 = st.columns(2)
|
c1, c2, c3 = st.columns(3)
|
||||||
with c1:
|
with c1:
|
||||||
if st.button("▶️ Lire", key=f"play_{video.file_name}"):
|
if st.button("▶️", key=f"play_{video.file_name}"):
|
||||||
st.session_state[play_key] = True
|
st.session_state[play_key] = True
|
||||||
(st.rerun if hasattr(st, "rerun") else st.experimental_rerun)()
|
(st.rerun if hasattr(st, "rerun") else st.experimental_rerun)()
|
||||||
with c2:
|
with c2:
|
||||||
if st.button("⏸️ Stop", key=f"stop_{video.file_name}"):
|
if st.button("⏸️", key=f"stop_{video.file_name}"):
|
||||||
st.session_state[play_key] = False
|
st.session_state[play_key] = False
|
||||||
(st.rerun if hasattr(st, "rerun") else st.experimental_rerun)()
|
(st.rerun if hasattr(st, "rerun") else st.experimental_rerun)()
|
||||||
|
with c3:
|
||||||
|
if st.button("🗑️", key=f"del_{video.file_name}"):
|
||||||
|
st.session_state[play_key] = False
|
||||||
|
if os.path.exists(video.raw_file ):
|
||||||
|
os.remove(video.raw_file)
|
||||||
|
if os.path.exists(video.mp4_file):
|
||||||
|
shutil.rmtree(os.path.dirname(video.mp4_file))
|
||||||
|
db.delete_video(video.file_name)
|
||||||
|
st.warning("Vidéo supprimée.")
|
||||||
|
(st.rerun if hasattr(st, "rerun") else st.experimental_rerun)()
|
||||||
|
|
||||||
if st.session_state[play_key]:
|
if st.session_state[play_key]:
|
||||||
mp4_path = getattr(video, "mp4_file", None)
|
mp4_path = getattr(video, "mp4_file", None)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ usage() {
|
|||||||
echo "Usage: $0 [--all|-a]"
|
echo "Usage: $0 [--all|-a]"
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " --all, -a Traiter tous les fichiers (ignore la liste de fichiers)"
|
echo " --all, -a Traiter tous les fichiers (ignore la liste de fichiers)"
|
||||||
|
echo " --force, -f Traiter les fichiers ignorés"
|
||||||
echo " --help, -h Afficher cette aide"
|
echo " --help, -h Afficher cette aide"
|
||||||
echo " --print-err, -e Afficher les erreurs en stderr et non dans le fichier de logs"
|
echo " --print-err, -e Afficher les erreurs en stderr et non dans le fichier de logs"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -23,6 +24,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
PROCESS_ALL=true
|
PROCESS_ALL=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--force|-f)
|
||||||
|
PROCESS_IGNORED_FILES=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--help|-h)
|
--help|-h)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
@@ -206,6 +211,13 @@ whatsapp_video() {
|
|||||||
process_raw_file $raw $suffixe
|
process_raw_file $raw $suffixe
|
||||||
}
|
}
|
||||||
export -f whatsapp_video
|
export -f whatsapp_video
|
||||||
|
ignored_video() {
|
||||||
|
local raw="$1"
|
||||||
|
echo ignored "$raw"
|
||||||
|
local suffixe=$(generate_funny_suffix $raw)
|
||||||
|
process_raw_file $raw $suffixe
|
||||||
|
}
|
||||||
|
export -f ignored_video
|
||||||
|
|
||||||
convert_raws() {
|
convert_raws() {
|
||||||
|
|
||||||
@@ -245,6 +257,16 @@ convert_raws() {
|
|||||||
done < "$TEMP_FILE"
|
done < "$TEMP_FILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$PROCESS_IGNORED_FILES" ]]; then
|
||||||
|
set -x
|
||||||
|
for f in $(find "$DOSSIER_DESTINATION_RAW" -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.mov" \) -print); do
|
||||||
|
if [[ -z $(sqlite3 "$DANCE_VIDEOS_DB" "SELECT 1 FROM VIDEOS WHERE RAW_FILE='$f';") ]]; then
|
||||||
|
ignored_video "$f"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
set +x
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
$PRINT_ERR || exec 2> /tmp/DanceVideos.stderr
|
$PRINT_ERR || exec 2> /tmp/DanceVideos.stderr
|
||||||
|
|||||||
34
program2/check.sh
Executable file
34
program2/check.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
DANCE_VIDEOS_DB="${HOME}/Documents/.DanceVideos/db.sqlite"
|
||||||
|
RAW_VIDEOS_DIR="${HOME}/Documents/.DanceVideos/raw/"
|
||||||
|
|
||||||
|
check_registered_files_exist() {
|
||||||
|
sqlite3 -separator '|' "$DANCE_VIDEOS_DB" "
|
||||||
|
SELECT file_name, raw_file, mp4_file FROM videos;
|
||||||
|
" | while IFS='|' read -r file_name raw_file mp4_file; do
|
||||||
|
# Sauter l'en-tête
|
||||||
|
if [[ "$file_name" == "file_name" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ignorer les lignes vides
|
||||||
|
if [[ ! -e "$raw_file" || ! -e "$mp4_file" ]]; then
|
||||||
|
echo "$raw_file KO : $mp4_file" >&2
|
||||||
|
else
|
||||||
|
echo "$raw_file OK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
check_files_are_registered() {
|
||||||
|
for f in $(find "$RAW_VIDEOS_DIR" -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.mov" \) -print); do
|
||||||
|
if [[ -z $(sqlite3 "$DANCE_VIDEOS_DB" "SELECT 1 FROM VIDEOS WHERE RAW_FILE='$f';") ]]; then
|
||||||
|
echo "$f not registered" >&2
|
||||||
|
# open $f
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
check_files_are_registered
|
||||||
Reference in New Issue
Block a user