diff options
Diffstat (limited to 'create_metadata_show.sh')
-rwxr-xr-x | create_metadata_show.sh | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/create_metadata_show.sh b/create_metadata_show.sh new file mode 100755 index 0000000..e447661 --- /dev/null +++ b/create_metadata_show.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# Creates metadata for a show +# Kaotisk Hund 2024 +# +# Output should be: +# { +# "artist":..., +# "title":..., +# "duration":..., +# "published_on":..., +# "created_on":..., +# "hash":..., +# "mimetype":..., +# "filename":..., +# "file-extension":... +# } +# +# Accept one argument, the targeted file +if [ ! -z $1 ] && [ -n "$1" ] +then + filename="$1" +else + echo "No filename given" + exit 1 +fi +# Check if file exists +if [ ! -f "${filename}" ] +then + echo "File doesn't exist" + exit 1 +fi +# ❯ file QmNcDk7jn8pGtt3UWZnKDPSGmGwFNkBUyXHCD5H9bdZ2Le.ogx +# QmNcDk7jn8pGtt3UWZnKDPSGmGwFNkBUyXHCD5H9bdZ2Le.ogx: Ogg data, Vorbis audio, stereo, 44100 Hz, ~192000 bps, created by: Xiph.Org libVorbis I +# +file ${filename} | grep 'Ogg data, Vorbis audio,' 1>/dev/null 2>&1 +if [ $? -eq 0 ] +then + mimetype='audio/ogg' +else + echo "Unknown file type" + exit 1 +fi +hashstring="$(sha512sum ${filename}|cut -d ' ' -f 1)" +if [ -f "./hashes/${hashstring}" ] +then + echo "File already exists" + exit 1 +fi + +artist="$(ogginfo ${filename} | grep -i ARTIST | cut -d '=' -f 2-)" +title="$(ogginfo ${filename} | grep -i TITLE | cut -d '=' -f 2-)" +duration="$(ogginfo ${filename} | grep 'Playback length' | cut -d ':' -f 2-)" +published_on="$(date -u +%s)000" +dmins="$(echo ${duration}|cut -d 'm' -f 1)" +dsecs="$(echo ${duration}|cut -d ':' -f 2|cut -d '.' -f 1)" +dmil="$(echo ${duration}|cut -d ':' -f 2|cut -d '.' -f 2|cut -d 's' -f 1)" +duration="$(echo -n $(($(( ${dmins} * 60)) + ${dsecs}))${dmil})" +created_on="$(echo -n $((${published_on} - ${duration})))" +file_extension="$(echo -n $filename|rev|cut -d '.' -f 1|rev)" + +temp_file="$(mktemp)" + +( +cat >&1 <<EOF +{ + "type":"show", + "artist":"${artist}", + "title":"${title}", + "published_on":"${published_on}", + "created_on":"${created_on}", + "duration":"${duration}", + "hash":"${hashstring}", + "mimetype":"${mimetype}", + "file_extension":"${file_extension}", + "filename":"${filename}" +} +EOF +)| jq -c -M > ${temp_file} +show_hash="$(sha512sum ${temp_file} | cut -d ' ' -f 1)" + +cp ${filename} ./hashes/${hashstring} +mv ${temp_file} ./hashes/${show_hash} |