wfm/index-media.sh
2023-03-02 12:56:08 +00:00

45 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
shopt -s nullglob
# I have I feeling I will hate this script by the time I finish writing it
# Some cursed JSON header
echo '{'
echo '"videos":['
isfirst="1"
for filename in *.mp4; do
if [ -f "$filename" ]; then
if [ $isfirst -ne "1" ]; then
echo ','
fi
isfirst="0"
name="${filename%.mp4}"
echo '{'
echo '"filename":"'"$filename"'",'
echo '"subtitles":['
sub_isfirst="1"
IFS=$'\n'
for subtitleName in "$name".*.vtt; do
if [ $sub_isfirst -ne 1 ]; then
echo ','
fi
echo '"'$subtitleName'"'
sub_isfirst="0"
done
echo '],'
ffmpeg -n -ss 00:00:01.00 -i "$filename" -vf 'scale=320:320:force_original_aspect_ratio=decrease' -vframes 1 "$name.jpg"
echo '"thumbnail":"'"$name"'.jpg",'
dimensions=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$filename")
echo '"dimensions":"'"$dimensions"'",'
duration=$(ffprobe -v error -sexagesimal -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$filename")
echo '"duration":"'"$duration"'"'
echo '}'
fi
done
# Close everything off :)
echo ']'
echo '}'