mirror of
https://github.com/saurabhan/Wallhaven-dl.git
synced 2026-01-21 01:08:01 +00:00
Added check if file exist
This commit is contained in:
@@ -66,7 +66,7 @@ def category():
|
|||||||
sketchy - For 'Sketchy'
|
sketchy - For 'Sketchy'
|
||||||
nsfw - For 'Not Safe For Work'
|
nsfw - For 'Not Safe For Work'
|
||||||
ws - For 'SFW' and 'Sketchy'
|
ws - For 'SFW' and 'Sketchy'
|
||||||
wn - for 'SFW' and 'NSFW'
|
wn - For 'SFW' and 'NSFW'
|
||||||
sn - For 'Sketchy' and 'NSFW'
|
sn - For 'Sketchy' and 'NSFW'
|
||||||
all - For 'SFW', 'Sketchy' and 'NSFW'
|
all - For 'SFW', 'Sketchy' and 'NSFW'
|
||||||
****************************************************************
|
****************************************************************
|
||||||
@@ -131,14 +131,16 @@ def main():
|
|||||||
i]
|
i]
|
||||||
for ext in imgext:
|
for ext in imgext:
|
||||||
iurl = url + ext
|
iurl = url + ext
|
||||||
|
osPath = os.path.join('Wallhaven', os.path.basename(iurl))
|
||||||
|
if not os.path.exists(osPath):
|
||||||
imgreq = requests.get(iurl, cookies=cookies)
|
imgreq = requests.get(iurl, cookies=cookies)
|
||||||
if imgreq.status_code == 200:
|
if imgreq.status_code == 200:
|
||||||
print('Downloading: ' + iurl)
|
with open(osPath, 'ab') as imageFile:
|
||||||
with open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') as imageFile:
|
for chunk in imgreq.iter_content(1024):
|
||||||
for chunk in tqdm.tqdm(imgreq.iter_content(1024), total=(int(imgreq.headers['content-length']) / 1024), unit='KB'):
|
|
||||||
time.sleep(0.01)
|
|
||||||
imageFile.write(chunk)
|
imageFile.write(chunk)
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
print("%s already exist" % os.path.basename(iurl))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user