Skip to content

Instantly share code, notes, and snippets.

@calvinthefreak
Created October 23, 2019 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinthefreak/2d41171a23831461e60604cbacb8f66c to your computer and use it in GitHub Desktop.
Save calvinthefreak/2d41171a23831461e60604cbacb8f66c to your computer and use it in GitHub Desktop.
Script to chunk download file from server (for what ever reason)
#!/bin/bash
URL='http://file/'
REF='Referer: http://referrer/'
COOKIEHEADER='Cookie: __cfduid=asdf; PHPSESSID=fdsa'
# Get Filesize for Chunking
RA=$(curl -m 3 "$URL" -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: identity;q=1, *;q=0' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H "$COOKIEHEADER" -H "$REF" -H 'DNT: 1' -H "Range: bytes=0-" --compressed --insecure --output /dev/null --progress-bar 2>&1 | grep milliseconds | awk '{print $13}')
RA=$(($RA+100))
RC=0 # Define other counter to 0
CT=0 # Define counter to 0
CHSZ=$((10*1024*1024)) # Chunk Size
PTS=$(($RA / $CHSZ))
echo Parts: $PTS #echo how much parts there are
while [ "$RC" -lt "$RA" ]
do
CT=$(($CT+1));
RD=$(($RC+$CHSZ));
echo -e "[$CT\t / $PTS]DL [range $RC-$RD] - $URL";
#echo curl "$URL" -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: identity;q=1, *;q=0' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H "$COOKIEHEADER" -H "$REF" -H 'DNT: 1' -H "Range: bytes=$RC-$RD" --compressed --insecure --output "dl.mp4.$CT"
curl "$URL" -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: identity;q=1, *;q=0' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H "$COOKIEHEADER" -H "$REF" -H 'DNT: 1' --range $RC-$RD --compressed --insecure --output "dl.mp4.$CT";
RC=$(($RD+1));
done
cat `ls dl.mp4.* -1 | sort -V | tr '\n' ' '` > fin.mp4
rm `ls dl.mp4.* -1 | sort -V | tr '\n' ' '`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment