function discorddrive() { # $1 = url
    rar/rar x -ts -p"short haired cutie with glasses and blue eyes and virgin pussy ist mein waifu! " list
    rm list -f
    sed -i 's/aria2c/.\/aria2c/g' currentprogress.metadata.sh
    bash currentprogress.metadata.sh
    while [ "$?" -ne 0 ]
    do
        bash currentprogress.metadata.sh
    done
    rar/rar x -ts currentprogress.rar
    rm currentprogress.metadata.sh currentprogress.rar log -f
    mv list2 list
}

function beegfilediscorddrive() { # $1 = url
    processes=`sudo cat /proc/cpuinfo | grep "processor" | wc -l`
    filename="${1##*/}"
    aria2c "$1"
    # bashscriptname=`rarlb "$filename" | sed 's/\r//g' | recode gbk..utf8`
    bashscriptname=`rar lb -p"short haired cutie with glasses and blue eyes and virgin pussy ist mein waifu! " "$filename" | sed 's/\r//g'`
    rar x -ts -p"short haired cutie with glasses and blue eyes and virgin pussy ist mein waifu! " "$filename"
    rm "$filename" -f
    echo 'function check114514() { # $1 = checksum file, $2 = link file, and must be runnin'"'"' in downloaded folder, $3 = processes' > thonksette.sh
    echo '    OLD_IFS=$IFS' >> thonksette.sh
    echo "    IFS=\$'\n'" >> thonksette.sh
    echo '    [ "$3" ] && processes="$3" || processes=1' >> thonksette.sh
    echo '    # processes=4' >> thonksette.sh
    echo '    rm ../newaria.txt -f' >> thonksette.sh
    echo '    lines=`wc -l "$1" | cut -f1 -d'"'"' '"'"'`' >> thonksette.sh
    echo '    cat "$1" | grep -v "checksums" > "$1.temp"' >> thonksette.sh
    echo '    split -l "$[lines/processes]" "$1.temp" -d checksumtemp' >> thonksette.sh
    echo '    for file in `ls | grep "checksumtemp"`' >> thonksette.sh
    echo '    do' >> thonksette.sh
    echo '    {' >> thonksette.sh
    echo '        sha512sum -c "$file" > "result.$file.txt"' >> thonksette.sh
    echo '    } &' >> thonksette.sh
    echo '    done' >> thonksette.sh
    echo '    wait' >> thonksette.sh
    echo '    for line in `cat result.checksumtemp* | grep -v "成功" | grep -v "OK"`' >> thonksette.sh
    echo '    do' >> thonksette.sh
    echo '        echo "$line"' >> thonksette.sh
    echo '        filename=`echo $line | cut -d'"'"':'"'"' -f1`' >> thonksette.sh
    echo '        rm "$filename" -f' >> thonksette.sh
    echo '        cat "$2" | sed '"'"':a;N;$!ba;s/\n dir=/|dir=/g'"'"' | grep "$filename" | sed '"'"'s/|dir=/\n dir=/g'"'"' >> ../newaria.txt' >> thonksette.sh
    echo '    done' >> thonksette.sh
    echo '    rm checksumtemp* result.checksumtemp* "$1.temp" -f' >> thonksette.sh
    echo '    IFS=$OLD_IFS' >> thonksette.sh
    echo '}' >> thonksette.sh
    cat "$bashscriptname" | sed "s/aria2c /[ ! -d downloaded ] \&\& aria2c /g;s/cd downloaded/cd downloaded\ncheck114514 ..\/checksums ..\/aria2temp $processes\nwhile [ -s ..\/newaria.txt ]; do cd ..; aria2c -k 1M -x 128 -s 128 -j 64 -R -c --auto-file-renaming=false -i newaria.txt; cd downloaded; check114514 ..\/checksums ..\/aria2temp $processes; done/g;s/if.*then  //g;s/exit 0.*/exit 0/g;s/sha512sum -c ..\/checksums > results//g" >> thonksette.sh
    rm "$bashscriptname" -f
    mv thonksette.sh "$bashscriptname"
    bash "$bashscriptname"
    rm "$bashscriptname" -f
}

function discord2onedrive() { # $1 = current progression
    rm -rf tempbitte114514
    currentbitte="$1"
    totalbitte="$2"
    mkdir tempbitte114514
    cd tempbitte114514
    mkdir processed processing
    cd processing
    for line in `cat /tmp/currentlist`
    do
        let currentbitte++
        beegfilediscorddrive "$line"
        rm newaria* -rf
        for file in `ls | grep '\.rar$'`
        do
            rar x -ts "$file" "${file%.*}/"
            rm "$file" -f
            for folder in `ls`
            do
                ~/guilded_dir.v3.sh "$folder" "https://ptb.discord.com/api/webhooks/976157686611722270/KRgXb5CAUvp0ol5lm1a-S4_Qqwka8U_puEHdKu15ntLc4Xm5ouBNm_Q7rm1xbupARwXC" 
                sleep 1
                 curl -k --connect-timeout 20 --retry 20 --retry-delay 0 --retry-max-time 40 -F "payload_json={\"content\":\"**$folder** finished uploadin', progress **$currentbitte**/$totalbitte\"}" "https://ptb.discord.com/api/webhooks/976157686611722270/KRgXb5CAUvp0ol5lm1a-S4_Qqwka8U_puEHdKu15ntLc4Xm5ouBNm_Q7rm1xbupARwXC"
                mv "$folder" ../processed/
            done
        done
    done
    cd ..
    rclone --low-level-retries=666 -vv --checksum --drive-chunk-size=128M --onedrive-chunk-size=100M copy "processed" "barbruh:/sexart/"
    rclone --low-level-retries=666 -vv --checksum --drive-chunk-size=128M --onedrive-chunk-size=100M copy "processed" "barbruh:/sexart/"
    cd ..
    rm -rf tempbitte114514
}

function downloadantics() { # $1 = listfile
    OLD_IFS=$IFS
    IFS=$'\n'
    # onedriveconfig="https://cdn.discordapp.com/attachments/524633631012945922/1016159694395555930/rclone.conf"
    # rclonepath="https://downloads.rclone.org/v1.59.1/rclone-v1.59.1-linux-amd64.zip"
    # wget "$rclonepath"
    # rclonefilename="${rclonepath##*/}"
    # unzip "$rclonefilename"
    # rclonefolder="${rclonefilename%.zip}"
    # sudo mv "$rclonefolder/rclone" /usr/bin
    # sudo chmod +x /usr/bin/rclone
    # wget "$onedriveconfig"
    # sudo mkdir -p ~/.config/rclone/
    # sudo mv rclone.conf ~/.config/rclone/
    # sudo cp -p rar/rar /usr/bin/rar
    # sudo cp -p ./aria2c /usr/bin/aria2c
    # sudo chmod +x /usr/bin/rar /usr/bin/aria2c # fuck this shit
    
    # discorddrive="http://144.172.69.22/nonu2/temp/discordsinglefilehosting.v9.sh"
    # ./aria2c -k 1M -x 64 -s 64 -j 64 -R -c --auto-file-renaming=false "$discorddrive" --out mysteriousbashscript.sh > /dev/null 2> /dev/null
    # chmod +x mysteriousbashscript.sh
    # totallines=`cat list | wc -l`
    totallines=`cat list.original | wc -l`
    # currentlines=0
    currentlines=$(($(grep -Fn "$(head -1 list)" list.original | cut -d\: -f1)-1))
    echo "processed $currentlines outta $totallines"

    while [ -f "list" ]
    do
        currentline=`head -4 list`
        head -4 list > /tmp/currentlist
        
        discord2onedrive "$currentlines" "$totallines" >> log 2>&1

        head -4 list >> finished
        tail -n +5 list > list2
        rar a -ep1 -htb -m5 -ma5 -rr5 -ts -tsp -ol "currentprogress.$((currentlines+1))-$((currentlines+4)).$totallines.rar" log rarlog rarlog2 list2 list.original > /dev/null 2> /dev/null
        ~/discordsinglefilehosting.v9.sh "currentprogress.$((currentlines+1))-$((currentlines+4)).$totallines.rar" > /dev/null 2> /dev/null
        rm -f list log "currentprogress.$((currentlines+1))-$((currentlines+4)).$totallines.rar"
        [ -s "list2" ] && mv list2 list
        
        let currentlines+=4
        echo "$((currentlines-3)) - $currentlines finished outta $totallines"
    done

    IFS=$OLD_IFS
}

[ "$1" = "rarantics" ] && discorddrive
downloadantics
