Created
June 22, 2017 22:40
-
-
Save AndrewtConroy/651c0f3b327b680d9b19daddcf057cca to your computer and use it in GitHub Desktop.
this is a download from url script. It's been customized to fit inside maya and with a UI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download(self): | |
gMainProgressBar = mel.eval('$tmp = $gMainProgressBar') | |
try: | |
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', | |
'Accept-Encoding': 'none', | |
'Accept-Language': 'en-US,en;q=0.8', | |
'Connection': 'keep-alive'} | |
req = urllib2.Request(self.url, headers=hdr) | |
temp = cmds.internalVar(utd = True) | |
fileName = temp + self.folder | |
chunk_size=5000000 | |
cmds.progressBar( gMainProgressBar, | |
edit=True, | |
beginProgress=True, | |
isInterruptable=True, | |
status='Downloading Characters ...', | |
maxValue=100 ); | |
fileWrite = open(fileName, 'wb') | |
cmds.progressBar(gMainProgressBar, edit=True, status='Connecting to server....'); | |
response = urllib2.urlopen(req); | |
cmds.progressBar(gMainProgressBar, edit=True, status='Writing data....'); | |
self.total_size = response.info().getheader('Content-Length').strip() | |
self.total_size = int(self.total_size) | |
self.bytes_so_far = 0 | |
while 1: | |
chunk = response.read(chunk_size) | |
fileWrite.write(chunk) | |
self.bytes_so_far += len(chunk) | |
if not chunk: | |
break | |
self.chunk_report() | |
cmds.progressBar(gMainProgressBar, edit=True, endProgress=True) | |
fileWrite.close() | |
cmds.progressBar(gMainProgressBar, edit=True, status='Unzipping file....') | |
zip = zipfile.ZipFile(temp + self.folder) | |
zip.extractall(self.dir) | |
sys.stdout.write('\nFiles Installed!'); | |
self.populateProjects() | |
except Exception as e: | |
sys.stdout.write(str(e)); | |
sys.stdout.write('\n Failed to download file: ' + self.folder + ' See HELP in the Long Winter menu if you\'re stuck.'); | |
cmds.progressBar(gMainProgressBar, edit=True, endProgress=True); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment