From 8281be7ba874e116ccc43e41d1275c1d531c54dc Mon Sep 17 00:00:00 2001 From: kaotisk Date: Thu, 10 Oct 2024 07:42:13 +0300 Subject: Implementation --- create_metadata_show.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 create_metadata_show.sh (limited to 'create_metadata_show.sh') 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 < ${temp_file} +show_hash="$(sha512sum ${temp_file} | cut -d ' ' -f 1)" + +cp ${filename} ./hashes/${hashstring} +mv ${temp_file} ./hashes/${show_hash} -- cgit v1.2.3