shufang.org/scripts/duration-length.sh

28 lines
1.1 KiB
Bash
Raw Normal View History

2022-04-02 11:12:42 +02:00
file="./scripts/duration-length.txt"
2022-04-17 08:31:47 +02:00
# duration-length.txt example
# https://github.com/shufangOrg/shufang.org/commit/bb08abed58cb35e530988eb44c2683c6327578e1
2022-04-02 16:29:07 +02:00
if [ -f "$file" ]
2022-04-02 11:12:42 +02:00
then
2023-03-08 02:30:37 +01:00
for i in $(cat $file); do
FIRSTLINE=$(head -n 1 "$i")
if [ ${FIRSTLINE:0:3} == "---" ]
then
2023-03-08 02:26:00 +01:00
mp3="https://"$(cat "$i" | grep "^mp3:" | awk -F' ' '{print $2}')
duration=$(ffprobe -i "$mp3" -show_entries format=duration -v quiet -of csv="p=0" -sexagesimal)
length=$(ffprobe -i "$mp3" -show_entries format=size -v quiet -of csv="p=0")
sed -i "s/^duration: .*/duration: \"$duration\"/g" "$i"
sed -i "s/^length: .*/length: $length/g" "$i"
cat "$i"
2023-03-08 02:30:37 +01:00
fi
if [ ${FIRSTLINE:0:3} == "+++" ]
then
2023-03-08 02:26:00 +01:00
mp3="https://"$(cat "$i" | grep "^mp3 =" | awk -F' ' '{print $2}')
duration=$(ffprobe -i "$mp3" -show_entries format=duration -v quiet -of csv="p=0" -sexagesimal)
length=$(ffprobe -i "$mp3" -show_entries format=size -v quiet -of csv="p=0")
sed -i "s/^duration = .*/duration = \"$duration\"/g" "$i"
sed -i "s/^length = .*/length = $length/g" "$i"
cat "$i"
2023-03-08 02:30:37 +01:00
fi
done
2022-04-02 11:12:42 +02:00
fi