refactor: rewrite conference creation script for kdenlive

This commit is contained in:
Yorick Barbanneau 2024-09-22 21:10:02 +02:00
parent a9e75d7933
commit 4477c2b2ab

View file

@ -16,6 +16,10 @@ process_args() {
key_label="$2"
shift
;;
-r|--recorder)
recorder_label="$2"
shift
;;
*)
break
esac
@ -23,6 +27,38 @@ process_args() {
done
}
mount_device() {
local label="$1"
local unmount="${2:-0}"
local device
if [[ $unmount -eq 1 ]]; then
printf "Unm"
else
printf "M"
fi
printf "ount device with Label %s\n" "$label"
device="/dev/$(lsblk -o KNAME,LABEL | grep "${label}" | awk '{print $1}')"
# check is we found a device with this name
if [[ $device = "/dev/" ]]; then
error "Can't get device named $label is device plugged?"
return 1
fi
local command
if [[ $unmount -eq 1 ]]; then
command="unmount"
else
command="mount"
fi
if ! udisksctl "${command}" -b "${device}"; then
error " -> Error mounting device $device for $label"
return 1
fi
sleep 1
return 0
}
get_file_hash() {
local file
local file_size
@ -54,6 +90,23 @@ get_file_hash() {
printf "%s" -1
}
move_file(){
local source="$1"
local destination="$2"
printf "Move %s to %s:\n" "$source" "$destination"
if [[ ! -d "${destination%/*}" ]]; then
error "$destination directory does not exists"
return 1
fi
if ! mv "$source" "$destination"; then
error "Error moving $source file, file must not exists"
return 1
fi
return 0
}
get_file_size() {
local file
file=$1
@ -90,7 +143,7 @@ base_dir="${HOME}/medias/videos/sambab"
conf="$*"
key_label=${key_label:-SAMBAB}
recorder_label=${recorder_label:-"LS-100"}
printf "Creation de la conférence de %s\n" "$conf"
cd ~/medias/videos/sambab || exit 1
@ -101,7 +154,7 @@ friday=$(date --date='last Friday' +"%Y.%m.%d")
#Add basedir, then I have my directory
folder="${base_dir}/${friday}-${conf// /_}"
#create it
# create it
mkdir "${folder}/"{rushes,audio,titles} -p || die "folder creation failed"
@ -122,36 +175,28 @@ inkscape --export-type="png" "${folder}/titles/logo_amis.svg" || die "Export fai
printf "Importing PNG File in %s/montage.kdenlive \n" "$folder"
insert_media "$folder/titles/logo_amis.png" "logo"
echo "Mount USBkey with Label $key_label"
usb_key="/dev/$(lsblk -o KNAME,LABEL | grep "${key_label}" | awk '{print $1}')"
[[ ! $usb_key = "/dev/" ]] || die "Can't getting device name, is USB key plugged? $usb_key"
## Get file from USB key
if mount_device "$key_label"; then
if move_file "/run/media/${USER}/${key_label}/RECORD/EXREC/"*.MP3 "${folder}/audio/audio.mp3"; then
insert_media "${folder}/audio/audio.mp3"
fi
if move_file "/run/media/${USER}/${key_label}/$(date --date='last Friday' +'%Y-%m-%d')"\ *.mkv "${folder}/rushes/obs.mkv";
then
insert_media "${folder}/rushes/obs.mkv" video
fi
mount_device "$key_label" 1
fi
disk="$(udisksctl mount -b "${usb_key}" | awk '{print $4}')"
sleep 1
[[ -n $disk ]] || die " -> Error mounting device $usb_key"
## Get audio file from RECORDER
if mount_device "$recorder_label"; then
if move_file "/run/media/${USER}/${recorder_label}/RECORDER/FOLDER_A/"VOC_*.wav "${folder}/audio/recorder.wav"; then
insert_media "${folder}/audio/recorder.wav"
fi
mount_device "${recorder_label}" 1
fi
printf "Change root folder in montage.kdenlive to %s\n" "$folder"
sed -i -e "s#\[\[root_folder\]\]#${folder}#g" "${folder}/montage.kdenlive"
# sed -i -e "s#\[\[root_folder\]\]#${folder}#g" "${folder}/montage.kdenlive"
printf "Copying Audio File: %s\n" "$folder"
if mv "${disk}/RECORD/EXREC/"*.MP3 "${folder}/audio/audio.mp3";
then
# import audio file
printf "Importing Audio File in %s/montage.kdenlive \n" "$folder"
insert_media "${folder}/audio/audio.mp3" audio
else
error "Moving audio file failed!"
fi
printf "Copying Video File\n"
if mv "${disk}/$(date --date='last Friday' +'%Y-%m-%d')"\ *.mkv "${folder}/rushes/obs.mkv";
then
insert_media "${folder}/rushes/obs.mkv" video
else
error "Moving video file failed!"
fi
udisksctl unmount -b "${usb_key}"
exit 0