1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 | tail -n 1 | cut -d '=' -f 2-)"
title="$(ogginfo ${filename} | grep -i TITLE | tail -n 1 | 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}
|