fix the script

This commit is contained in:
Jason Tian 2023-03-08 09:30:37 +08:00
parent 25b5fab6df
commit 258d4cb72a
1 changed files with 9 additions and 11 deletions

View File

@ -2,28 +2,26 @@ file="./scripts/duration-length.txt"
# duration-length.txt example
# https://github.com/shufangOrg/shufang.org/commit/bb08abed58cb35e530988eb44c2683c6327578e1
if [ -f "$file" ]
FIRSTLINE=$(head -n 1 "$file")
then
if [ ${FIRSTLINE:0:3} == "---" ]
then
for i in $(cat $file); do
for i in $(cat $file); do
FIRSTLINE=$(head -n 1 "$i")
if [ ${FIRSTLINE:0:3} == "---" ]
then
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"
done
fi
if [ ${FIRSTLINE:0:3} == "+++" ]
then
for i in $(cat $file); do
fi
if [ ${FIRSTLINE:0:3} == "+++" ]
then
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"
done
fi
fi
done
fi