From 3371cffebb47141e39344e1069e36d383163c98c Mon Sep 17 00:00:00 2001 From: fanta Date: Wed, 8 Mar 2023 22:51:21 +0100 Subject: [PATCH] =?UTF-8?q?primera=20versi=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chunkd | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 chunkd diff --git a/chunkd b/chunkd new file mode 100755 index 0000000..f384efb --- /dev/null +++ b/chunkd @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# dchunks - fanta@56k.es + +import sys +import requests +import time +import progressbar + +chunkSize=1024*1024*1024 +errorMsg="Example: chunkd http://fanta.56k.es/games/1990/1990-King_Quest_5/King_Quest_5.tar.gz" +if len(sys.argv) == 2: url=sys.argv[1] +else: print(errorMsg); exit(1) +session = requests.Session() +try: response = session.get(url,allow_redirects=True,stream=True) +except: print(errorMsg); exit(1) +fileLocalFilename = url.split('/')[-1] +contentLen=None +try: fileSize=int(response.headers['content-length']) +except: contentLen="false" +print("\n[+] "+fileLocalFilename+" - chunk Size: ",chunkSize) + +def downloadChunks(): + totalbits = 0 + response.raise_for_status() + for chunk in response.iter_content(chunk_size=chunkSize): + if chunk: + totalbits += len(chunk) + f.write(chunk) + bar.update(totalbits) + +if response.status_code == 200: + with open(fileLocalFilename, 'wb') as f: + if contentLen == "false": + with progressbar.ProgressBar(max_value=progressbar.UnknownLength) as bar: + downloadChunks() + else: + with progressbar.ProgressBar(max_value=fileSize) as bar: + downloadChunks() + +print("\n")