Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import os
- import sys
- import urllib
- import urllib2
- import locale
- reload(sys)
- def help():
- print "\nfsget fsua_[number].txt\n"
- print "Only for fs.ua file lists\n"
- return None
- # URL-encoded to UTF-8
- def fs_decode(localline):
- return urllib.unquote(localline).decode('utf8')
- # Logics itself
- if (len(sys.argv) != 2):
- help()
- else:
- filename = sys.argv[1]
- if(os.path.exists(filename) and os.path.isfile(filename)):
- # print "valid file"
- myfile = open(filename, 'r')
- line = myfile.readline()
- block_sz = 8192
- while (line != None) and (line != ""):
- decoded_line = fs_decode(line)
- file_name = decoded_line.split('/')[-1]
- file_name = file_name.replace(file_name[-1], "")
- file_name = file_name.replace(file_name[-1], "")
- if(os.path.isfile(file_name)):
- file_size_dl = int(os.path.getsize(file_name))
- else:
- file_size_dl = 0
- u = urllib2.urlopen(line)
- meta = u.info()
- file_size = int(meta.getheaders("Content-Length")[0])
- print "Downloading: %s\nBytes: %s" % (file_name, file_size)
- # print "Remote file size = "+str(file_size)+";"
- # print "Local file size = "+str(file_size_dl)+";"
- if(file_size != file_size_dl):
- f = open(file_name, 'wb')
- while True:
- buffer = u.read(block_sz)
- if not buffer:
- break
- file_size_dl += len(buffer)
- f.write(buffer)
- status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
- status = status + chr(8)*(len(status)+1)
- print status,
- f.close()
- else:
- print "File '"+file_name+"' seems to downloaded already!"
- line = myfile.readline()
- else:
- print "invalid file"
Add Comment
Please, Sign In to add comment