satnogs-wut/wut-audio-sha1

71 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# wut-audio-sha1
#
# Usage:
# wut-audio-sha1
# Example:
# wut-audio-sha1
#
# This script verifies sha1 checksums of files downloaded from archive.org.
# If the checksum doesn't match, the file is deleted and the download is
# re-tried.
#
# This script only downloads audio files from archive.org, not satnogs.org.
cd download || exit
# Compile a list of ogg files (NOTE: THIS WILL BREAK AS ARCHIVE GROWS XXX)
echo "Total audio files: `ls -1 */satnogs_*.ogg | wc -l`"
for i in */satnogs_*.ogg
do OBSID=`dirname $i`
# Go into directories with audiofiles
echo $OBSID
cd $OBSID
# See if there is an archive.org XML file, if not, download it.
XMLURL="https://archive.org/download/satnogs-observation-$OBSID/satnogs-observation-$OBSID""_files.xml"
XMLFILE=`basename "$XMLURL"`
[ ! -f "$XMLFILE" ] && \
curl \
--location \
--silent \
--http2 --ipv4 \
--remote-time \
--output $XMLFILE \
$XMLURL \
&& sleep `echo $((0 + RANDOM % 1))`
# Get name of audio file.
AUDIOURL=`cat $OBSID.json | jq --compact-output '.[0] | {archive_url}' | grep ogg | cut -f 2- -d : | sed -e 's/}//g' -e 's/http:/https:/g' -e 's/"//g'`
AUDIOFILE=`basename "$AUDIOURL"`
# Get sha1 for audio file. XXX sgrep dependency XXX
AUDIOXMLSHA1=`sgrep -g xml \
'"<file name=\"'$AUDIOFILE'\" source=\"original\"" .. "/file>"' \
"$XMLFILE" | \
grep "<sha1>" | \
sed -e 's/.*<sha1>//' -e 's/<\/sha1>//'`
AUDIOFILESHA1=`sha1sum $AUDIOFILE | cut -f 1 -d " "`
echo -e -n "XML: $AUDIOXMLSHA1\nFile: $AUDIOFILESHA1 "
if [ "$AUDIOXMLSHA1" = "$AUDIOFILESHA1" ] ; then
echo "Good"
else
echo "Bad, re-downloading $AUDIOURL"
rm "$AUDIOFILE"
curl \
--location \
--silent \
--http2 --ipv4 \
--remote-time \
--output $AUDIOFILE \
$AUDIOURL \
&& sleep `echo $((0 + RANDOM % 1))`
AUDIOFILESHA1=`sha1sum $AUDIOFILE | cut -f 1 -d " "`
echo -e -n "XML: $AUDIOXMLSHA1\nFile: $AUDIOFILESHA1 "
if [ "$AUDIOXMLSHA1" = "$AUDIOFILESHA1" ] ; then
echo "Re-download is good"
else
echo "Still bad after re-downloading"
rm "$AUDIOFILE"
fi
fi
cd ..
done