Changeset 4bc2854bb0f9b2e4302bf6483771110b74519332
- Timestamp:
- 04/06/08 04:04:57
(8 months ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1207472697 -0500
- git-parent:
[e19fdd68c9407b567c1608c8b3a5a9396ab27552]
- git-author:
- Jason Michalski <armooo@armooo.net> 1207472697 -0500
- Message:
Resume downloads.
Still needs some work if it is not supported on the server we will get a
messed up file.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| re19fdd6 |
r4bc2854 |
|
| 6 | 6 | |
|---|
| 7 | 7 | import threading |
|---|
| | 8 | import urllib2 |
|---|
| | 9 | import os.path |
|---|
| | 10 | import shutil |
|---|
| | 11 | import os.path |
|---|
| | 12 | import urllib |
|---|
| 8 | 13 | import xml.etree.ElementTree as ElementTree |
|---|
| 9 | 14 | import Queue |
|---|
| … | … | |
| 83 | 88 | |
|---|
| 84 | 89 | def processDlRequest(self): |
|---|
| 85 | | import shutil |
|---|
| 86 | | import os.path |
|---|
| 87 | | import urllib2 |
|---|
| 88 | | import urllib |
|---|
| 89 | 90 | |
|---|
| 90 | 91 | while True: |
|---|
| … | … | |
| 99 | 100 | file_name = os.path.join(path, '%s-%s' % (data['bodyOfferId'] ,data['url'].split('/')[-1])) |
|---|
| 100 | 101 | |
|---|
| 101 | | print 'downloading %s to %s' % (data['url'], file_name) |
|---|
| 102 | | |
|---|
| 103 | | outfile = open(file_name, 'wb') |
|---|
| 104 | | |
|---|
| 105 | | infile = urllib2.urlopen(data['url']) |
|---|
| 106 | | shutil.copyfileobj(infile, outfile) |
|---|
| 107 | | |
|---|
| 108 | | print 'done downloading %s to %s' % (data['url'], file_name) |
|---|
| | 102 | self.downloadFile(data['url'], file_name) |
|---|
| 109 | 103 | |
|---|
| 110 | 104 | tsn = data['bodyId'] |
|---|
| … | … | |
| 133 | 127 | self.in_progress_lock.release() |
|---|
| 134 | 128 | |
|---|
| | 129 | |
|---|
| | 130 | def downloadFile(self, url, file_path): |
|---|
| | 131 | print 'downloading %s to %s' % (url, file_path) |
|---|
| | 132 | |
|---|
| | 133 | outfile = open(file_path, 'awb') |
|---|
| | 134 | size = os.path.getsize(file_path) |
|---|
| | 135 | r = urllib2.Request(url) |
|---|
| | 136 | if size: |
|---|
| | 137 | r.add_header('Range', 'bytes=%s-' % size) |
|---|
| | 138 | infile = urllib2.urlopen(r) |
|---|
| | 139 | shutil.copyfileobj(infile, outfile, 8192) |
|---|
| | 140 | |
|---|
| | 141 | print 'done downloading %s to %s' % (url, file_path) |
|---|