Last active
February 27, 2020 04:50
-
-
Save amircloner/7a00d39b3b07fc73074a578fdb6c49e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#EDIT TOKEN: | |
TOKEN="hZdWdqPfhxVvRa42zS-1xAltk3qa5BXA_5WAjAUcW29e81vEBAbo9RxaqTjSA6lAvjzl5Jx-tD1g8EyNzNzWnLVqy_BhT3wavfPiBKmU3dmLj-VGm512cYLcZ7uMTfsLvHi8I52C3JVfY1m4" | |
if [[ "$#" -lt 1 ]]; then #Check number of arguemnt | |
echo "Please pass file names as argument." | |
exit 1 | |
fi | |
#ALSO MAKE SURE THAT CURL, RAR and JQ ARE INSTALLED ON YOUR SYSTEM | |
upload() { | |
#$1 is filename | |
res=$(curl -X POST "https://bot.sapp.ir/$TOKEN/uploadFile" -H 'content-type: multipart/form-data' -F file=@"$1") | |
local ok | |
ok=$(jq -r .resultMessage <<<"$res") | |
if [[ "$ok" != "OK" ]]; then | |
echo "Error on file $1:" | |
jq .description <<<"$res" | |
return | |
fi | |
local id | |
id=$(jq -r .fileUrl <<<"$res") | |
echo "https://bot.sapp.ir/$TOKEN/downloadFile/$id" >>"uploaded_files.txt" | |
local fname | |
fname=$(basename "$1") | |
echo "bot.sapp.ir/$TOKEN/downloadFile/$id:$fname" >>"file_names.txt" | |
echo "IDMan.exe /d https://bot.sapp.ir/$TOKEN/downloadFile/$id /f $fname /a" >> idm.bat | |
rm "$1" | |
} | |
#Lets start | |
rm -rf /tmp/SoroushUploader | |
#At first rar the file and split it into a temp directory | |
mkdir /tmp/SoroushUploader | |
rarCommand="rar a -M0 -v100M /tmp/SoroushUploader/u.rar" # You can also change the chunk size. Max upload size is 100MB | |
for arg in "$@" | |
do | |
rarCommand+=" \"$arg\"" | |
done | |
eval "$rarCommand" #Rar the files | |
#Then get the file names and upload eachone to server | |
for filename in /tmp/SoroushUploader/*.rar; do | |
while [ "$(jobs | wc -l)" -ge 10 ]; do # Change 10 if needed | |
sleep 5 | |
done | |
upload "$filename" & | |
done | |
while [[ "$(jobs)" =~ "Running" ]]; do | |
sleep 5 | |
done | |
echo "Done uploading files" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment