download file list coming along nicely :3
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
webhook.txt
|
webhook.txt
|
||||||
tag.txt
|
tag.txt
|
||||||
|
*.tmp
|
||||||
@@ -1,16 +1,53 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [ -z $1 -o ! -f "$2" ]; then
|
# manually created arrays for file types and extensions
|
||||||
|
types_arr=('MPEG' 'JPEG' 'PNG' 'GIF' 'WebM' 'RIFF')
|
||||||
|
exts_arr=('mp4' 'jpg' 'png' 'gif' 'webm' 'webp')
|
||||||
|
tmp_file="$1/download.tmp"
|
||||||
|
|
||||||
|
# check for existance of $1 or if $2 is a file
|
||||||
|
if [ -z $1 ] || [ ! -f "$2" ]; then
|
||||||
echo "Usage: $0 <output_directory> <file_list>"
|
echo "Usage: $0 <output_directory> <file_list>"
|
||||||
echo "ExaMPLE: download_file_list Downloads to_download.txt"
|
echo "ExaMPLE: download_file_list Downloads to_download.txt"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# create the out dir if not extant
|
||||||
if [ ! -d "$1" ]; then
|
if [ ! -d "$1" ]; then
|
||||||
echo "Output directory does not exist: $1 Creating"
|
echo "Output directory does not exist: $1 Creating"
|
||||||
mkdir "$1"
|
mkdir "$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# read the input file and loop through it
|
||||||
cat "$2" | \
|
cat "$2" | \
|
||||||
while read line; do
|
while read line; do
|
||||||
echo "curl -o \"$1/$(basename $line)\" \"$line\""
|
# download the file to a tmp
|
||||||
|
echo "Downloading $line to $1"
|
||||||
|
curl -s -o "$tmp_file" "$line"
|
||||||
|
|
||||||
|
# get the file type
|
||||||
|
type=$(file "$tmp_file" | awk '{print $2}')
|
||||||
|
|
||||||
|
# md5 hash the file for a deterministic file name
|
||||||
|
namehash=$(md5sum "$tmp_file" | awk '{print $1}')
|
||||||
|
|
||||||
|
# map the file type to the corresponding extension
|
||||||
|
count=0
|
||||||
|
# loop through types for patch with file type
|
||||||
|
for item in "${types_arr[@]}"; do
|
||||||
|
if [[ " ${types_arr[@]} " =~ " ${type} " ]]; then
|
||||||
|
# if type matches
|
||||||
|
if [[ "$item" == "$type" ]]; then
|
||||||
|
# rename the downloaded file
|
||||||
|
new_name="$1/$namehash.$(echo ${exts_arr[$count]})"
|
||||||
|
echo "Renaming $tmp_file to $new_name"
|
||||||
|
mv "$tmp_file" "$new_name"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$(basename $line) not a supported format: $type! Deleting"
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# increment the count regardless
|
||||||
|
count=$((count + 1))
|
||||||
|
done
|
||||||
done
|
done
|
||||||
Reference in New Issue
Block a user