1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #!/usr/bin/python # -*- coding: utf-8 -*- # # # Suraj # surajsinghbisht054@gmail.com # www.bitforestinfo.com # # Import Modules import urllib import sys import os
# Check Provided Arguments if len(sys.argv)==1: print "\n[*] Please Provide File Url Address:\n Usages: python {} www.examplesite.com\\path\\to\\file.zip\n".format(sys.argv[0]) sys.exit(0)
# Progress Reporter def progress(blocks, block_size, total_block_size): current_received_blocks = blocks * block_size # Calculate Total Block Received
percent = (100 * current_received_blocks/total_block_size) # Change in percentage sys.stdout.write('\rPercent : {}% [{}]'.format(str(percent),str('#'*(percent/10)).ljust(10))) # Print Percentage with prograss bar return
# File Name Creator def filename(url): # Return Url Address Base Name url_base = os.path.basename(url)
if '.' in url_base: # If file extension available base = url_base print "[+] File Saved As : ",base else: base = raw_input("[*] File Saved As : ") return base
# Download Function def download(url, file_name): print "\n" urllib.urlretrieve(url, file_name, progress) # Downloading File print "\n\n" return
# Main Function For File Name Management def main(url, fname=None): if fname: base = fname else: base = filename(url)
if base: download(url, base) return
if __name__ == '__main__': main(sys.argv[1])
|