My first module
This commit is contained in:
parent
cb37b7882d
commit
1d907edb1c
5 changed files with 26 additions and 9 deletions
19
home-manager/kdenlive/default.nix
Normal file
19
home-manager/kdenlive/default.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
{ pkgs, lib, config, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.modules.video.kdenlive;
|
||||
in
|
||||
{
|
||||
options.modules.video.kdenlive = {
|
||||
enable = mkEnableOption "enable Kdenlive video editor";
|
||||
};
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = with pkgs; [
|
||||
kdenlive
|
||||
ffmpeg-full
|
||||
frei0r
|
||||
inkscape
|
||||
];
|
||||
home.file.".local/bin/create_conf".source = ./files/create_conf;
|
||||
};
|
||||
}
|
159
home-manager/kdenlive/files/create_conf
Executable file
159
home-manager/kdenlive/files/create_conf
Executable file
|
@ -0,0 +1,159 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
error() {
|
||||
>&2 printf "\e[31mE\e[0m %s\n" "$1"
|
||||
}
|
||||
|
||||
die() {
|
||||
error "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
process_args() {
|
||||
while :; do
|
||||
case $1 in
|
||||
-l|--label)
|
||||
key_label="$2"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
get_file_hash() {
|
||||
local file
|
||||
local file_size
|
||||
|
||||
file=$1
|
||||
file_size=${2:-1}
|
||||
if (( file_size != -1 ))
|
||||
then
|
||||
if [ -f "$file" ]
|
||||
then
|
||||
if (( file_size > 0 ))
|
||||
then
|
||||
if (( $file_size > 2000000 ))
|
||||
then
|
||||
#calculate
|
||||
local tmp_file
|
||||
tmp_file=mktemp
|
||||
head -c 1MB "$file" > "$tmp_file"
|
||||
tail -c 1MB "$file" >> "$tmp_file"
|
||||
printf "%s" "$(md5sum "$tmp_file" | cut -d" " -f 1)"
|
||||
rm "$tmp_file"
|
||||
else
|
||||
printf "%s" "$(md5sum "$file" | cut -d" " -f 1)"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
printf "%s" -1
|
||||
}
|
||||
|
||||
get_file_size() {
|
||||
local file
|
||||
local a
|
||||
file=$1
|
||||
if [ -f "$file" ]
|
||||
then
|
||||
wc -c < "$file"
|
||||
return
|
||||
fi
|
||||
printf "%s" -1
|
||||
}
|
||||
|
||||
insert_media() {
|
||||
local filename filesize filehash tag
|
||||
filename="$1"
|
||||
tag="$2"
|
||||
[ ! -f "$filename" ] && {
|
||||
error "File $filename not found, can't insert media";
|
||||
return;
|
||||
}
|
||||
[ -z "$tag" ] && {
|
||||
error "Tag not defined, can't insert media"
|
||||
}
|
||||
filesize=$(get_file_size "$filename")
|
||||
filehash=$(get_file_hash "$filename" "$filesize")
|
||||
sed -i -e "s#\[\[${tag}\]\]#${filename}#g" \
|
||||
-e "s#\[\[${tag}_filesize\]\]#${filesize}#g" \
|
||||
-e "s#\[\[${tag}_filehash\]\]#${filehash}#g" \
|
||||
${folder}"/montage.kdenlive" || {
|
||||
error "sed command error on insert media!"
|
||||
}
|
||||
}
|
||||
|
||||
test=""
|
||||
base_dir="${HOME}/medias/videos/sambab"
|
||||
|
||||
conf="$*"
|
||||
key_label=${key_label:-SAMBAB}
|
||||
|
||||
|
||||
printf "Creation de la conférence de %s\n" "$conf"
|
||||
cd ~/medias/videos/sambab || exit 1
|
||||
|
||||
#Get las friday date for creating folder
|
||||
friday=$(date --date='last Friday' +"%Y.%m.%d")
|
||||
|
||||
#Add basedir, then I have my directory
|
||||
folder="${base_dir}/${friday}-${conf// /_}"
|
||||
|
||||
#create it
|
||||
mkdir "${folder}"/{rushes,audio,titles} -p || die "folder creation failed"
|
||||
|
||||
|
||||
cp "${base_dir}/logo_amis.svg" "${folder}/titles" || die "SVG copy failed!"
|
||||
cp "${base_dir}/template.kdenlive" "${folder}/montage.kdenlive" || dir "Template copy failed!" }
|
||||
|
||||
inkscape_date=$(LC_ALL=fr_FR.UTF-8 date --date='last Friday' +"%A %d %B %Y")
|
||||
|
||||
printf "Put Name on title\n"
|
||||
sed -i "s/\[\[conf\]\]/${conf//_/ }/g" ${folder}/titles/logo_amis.svg || die "Change text on credits screen failed!"
|
||||
|
||||
printf "Put date on title\n"
|
||||
sed -i "s/\[\[date\]\]/${inkscape_date}/g" ${folder}/titles/logo_amis.svg || die "Change date failed!"
|
||||
|
||||
printf "Export SVG title \n"
|
||||
inkscape --export-type="png" "${folder}/titles/logo_amis.svg" || die "Export failed"
|
||||
|
||||
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"
|
||||
|
||||
|
||||
disk="$(udisksctl mount -b ${usb_key} | awk '{print $4}')"
|
||||
sleep 1
|
||||
[[ -n $disk ]] || die " -> Error mounting device $usb_key"
|
||||
|
||||
|
||||
printf "Change root folder in montage.kdenlive to %s\n" "$folder"
|
||||
sed -i -e "s#\[\[root_folder\]\]#${folder}#g" "${folder}/montage.kdenlive"
|
||||
|
||||
printf "Copying Audio File\n" "$folder"
|
||||
if cp ${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 cp ${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
|
Loading…
Add table
Add a link
Reference in a new issue