Made the downloader aware of size issues when copying the wrong URL
This commit is contained in:
parent
faf874f519
commit
806aa452c3
1 changed files with 8 additions and 9 deletions
|
@ -8,15 +8,12 @@ def fileDownloader(url, sender = False):
|
||||||
filename = "%s/%s" % (sender, url.split('/')[-1])
|
filename = "%s/%s" % (sender, url.split('/')[-1])
|
||||||
else:
|
else:
|
||||||
filename = url.split('/')[-1]
|
filename = url.split('/')[-1]
|
||||||
if not os.path.isfile(filename):
|
|
||||||
remote = requests.get(url, stream=True)
|
remote = requests.get(url, stream=True)
|
||||||
with open(filename, 'wb') as outfile:
|
with open(filename, 'wb') as outfile:
|
||||||
for chunk in remote.iter_content(chunk_size=1024):
|
for chunk in remote.iter_content(chunk_size=1024):
|
||||||
if chunk:
|
if chunk:
|
||||||
outfile.write(chunk)
|
outfile.write(chunk)
|
||||||
outfile.flush()
|
outfile.flush()
|
||||||
else:
|
|
||||||
print("File %s already exists. Skipping.", file=sys.stderr)
|
|
||||||
|
|
||||||
def urlparse(url):
|
def urlparse(url):
|
||||||
if "/img/usr/" in url:
|
if "/img/usr/" in url:
|
||||||
|
@ -40,6 +37,8 @@ if __name__ == "__main__":
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("%s is not a valid URL. Skipping." % url, file=sys.stderr)
|
print("%s is not a valid URL. Skipping." % url, file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
|
if purl == urlparse(url):
|
||||||
|
print("Notice: You may have copied the image URL rather than the link URL from the message window. Use the link URL instead!")
|
||||||
if args.get_urls:
|
if args.get_urls:
|
||||||
print(purl)
|
print(purl)
|
||||||
elif args.sender:
|
elif args.sender:
|
||||||
|
|
Loading…
Reference in a new issue