more setuppp 3
This commit is contained in:
@@ -1,38 +1,36 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
tmp_links_file="/tmp/links.tmp"
|
||||||
|
tmp_file_download="/tmp/download.tmp"
|
||||||
|
|
||||||
|
nano "$tmp_links_file"
|
||||||
|
read -p "Enter output directory: " outdir
|
||||||
|
|
||||||
# manually created arrays for file types and extensions
|
# manually created arrays for file types and extensions
|
||||||
## notes: from twitter downloader mp4 files show as ISO?
|
## notes: from twitter downloader mp4 files show as ISO?
|
||||||
types_arr=('MPEG' 'ISO' 'JPEG' 'PNG' 'GIF' 'WebM' 'RIFF')
|
types_arr=('MPEG' 'ISO' 'JPEG' 'PNG' 'GIF' 'WebM' 'RIFF')
|
||||||
exts_arr=('mp4' 'mp4' 'jpg' 'png' 'gif' 'webm' 'webp')
|
exts_arr=('mp4' '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 "ExaMPLE: download_file_list Downloads to_download.txt"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# create the out dir if not extant
|
# create the out dir if not extant
|
||||||
if [ ! -d "$1" ]; then
|
if [ ! -d "$outdir" ]; then
|
||||||
echo "Output directory does not exist: $1 Creating"
|
echo "Output directory does not exist: $outdir Creating"
|
||||||
mkdir "$1"
|
mkdir "$outdir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# read the input file and loop through it
|
# read the input file and loop through it
|
||||||
cat "$2" | \
|
cat "$tmp_links_file" | \
|
||||||
while read line; do
|
while read line; do
|
||||||
# get default basename of downloaded file
|
# get default basename of downloaded file
|
||||||
file_basename=$(basename "$line")
|
file_basename=$(basename "$line")
|
||||||
|
|
||||||
# download the file to a tmp
|
# download the file to a tmp
|
||||||
echo "Downloading $line to $1/$file_basename"
|
echo "Downloading $line to $outdir/$file_basename"
|
||||||
curl -s -o "$tmp_file" "$line"
|
curl -s -o "$tmp_file_download" "$line"
|
||||||
|
|
||||||
# get the file type
|
# get the file type
|
||||||
type=$(file "$tmp_file" | awk '{print $2}')
|
type=$(file "$tmp_file_download" | awk '{print $2}')
|
||||||
|
|
||||||
# md5 hash the file for a deterministic file name
|
# md5 hash the file for a deterministic file name
|
||||||
namehash=$(md5sum "$tmp_file" | awk '{print $1}')
|
namehash=$(md5sum "$tmp_file_download" | awk '{print $1}')
|
||||||
|
|
||||||
# map the file type to the corresponding extension
|
# map the file type to the corresponding extension
|
||||||
count=0
|
count=0
|
||||||
@@ -42,16 +40,23 @@ cat "$2" | \
|
|||||||
# if type matches
|
# if type matches
|
||||||
if [[ "$item" == "$type" ]]; then
|
if [[ "$item" == "$type" ]]; then
|
||||||
# rename the downloaded file
|
# rename the downloaded file
|
||||||
new_name="$1/$namehash.$(echo ${exts_arr[$count]})"
|
new_name="$outdir/$namehash.$(echo ${exts_arr[$count]})"
|
||||||
echo -e "\tRenaming $file_basename to $new_name\n"
|
# echo -e "\tRenaming $file_basename to $new_name\n"
|
||||||
mv "$tmp_file" "$new_name"
|
mv "$tmp_file_download" "$new_name"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "\nFailed to rename $tmp_file_download to $new_name\n\turl\n\t$line\n\ttype $type\n\tbase name: $file_basename\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "\n$file_basename not a supported format: $(file $tmp_file)! Deleting\n"
|
echo -e "\n$file_basename not a supported format: $type $(file $tmp_file_download)!\n\turl: $line\n\ttype: $type\n\tbase name: $file_basename\n\tfile: $(file $tmp_file_download)\n"
|
||||||
rm -f "$tmp_file"
|
rm -f "$tmp_file_download"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# increment the count regardless
|
# increment the count regardless
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm -f "$tmp_links_file" >/dev/null 2>&1 # suppress errors or output
|
||||||
|
rm -f "$tmp_file_download" >/dev/null 2>&1 # suppress errors or output
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# tmp links file
|
||||||
|
tmpfile="/tmp/links.tmp"
|
||||||
|
|
||||||
|
# get links
|
||||||
|
nano "$tmpfile"
|
||||||
|
|
||||||
|
# download to .
|
||||||
|
cat "$tmpfile" | while read line; do
|
||||||
|
wget "$line"
|
||||||
|
done
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm -f "$tmpfile" 1>/dev/null 2>&1 # suppress errors or output
|
||||||
Reference in New Issue
Block a user